Commit ca64946b by Mike Dikan

Remove deprecated references to ProgramsApiConfig model

ECOM-7195

The (now deprecated) programs service had several fields to set up configuration of the API.  We are removing the property/field references in codeas the first part of deprecating the model fields.  Also being removed are the model properties.
parent b2385424
......@@ -830,7 +830,7 @@ def dashboard(request):
'courses_requirements_not_met': courses_requirements_not_met,
'nav_hidden': True,
'inverted_programs': inverted_programs,
'show_program_listing': ProgramsApiConfig.current().show_program_listing,
'show_program_listing': ProgramsApiConfig.is_enabled(),
'disable_courseware_js': True,
'display_course_modes_on_dashboard': enable_verified_certificates and display_course_modes_on_dashboard,
}
......
......@@ -8,6 +8,7 @@ class ProgramsConfigMixin(object):
"""Mixin providing a method used to configure the programs feature."""
def set_programs_api_configuration(self, is_enabled=False, api_version=1):
"""Dynamically adjusts the Programs config model during tests."""
# Update these paramters once fields are removed from model
ConfigModelFixture('/config/programs', {
'enabled': is_enabled,
'api_version_number': api_version,
......
......@@ -121,7 +121,7 @@ class TestProgramListing(ProgramsApiConfigMixin, CredentialsApiConfigMixin, Shar
"""
Verify that the page 404s if disabled.
"""
self.create_programs_config(program_listing_enabled=False)
self.create_programs_config(enabled=False)
response = self.client.get(self.url)
self.assertEqual(response.status_code, 404)
......@@ -294,7 +294,7 @@ class TestProgramDetails(ProgramsApiConfigMixin, CatalogIntegrationMixin, Shared
"""
Verify that the page 404s if disabled.
"""
self.create_programs_config(program_details_enabled=False)
self.create_programs_config(enabled=False)
response = self.client.get(self.url)
self.assertEqual(response.status_code, 404)
......
......@@ -22,7 +22,7 @@ from openedx.core.djangoapps.user_api.preferences.api import get_user_preference
def program_listing(request):
"""View a list of programs in which the user is engaged."""
programs_config = ProgramsApiConfig.current()
if not programs_config.show_program_listing:
if not programs_config.enabled:
raise Http404
meter = ProgramProgressMeter(request.user)
......@@ -34,7 +34,7 @@ def program_listing(request):
'nav_hidden': True,
'programs': meter.engaged_programs,
'progress': meter.progress,
'show_program_listing': programs_config.show_program_listing,
'show_program_listing': programs_config.enabled,
'uses_pattern_library': True,
}
......@@ -46,7 +46,7 @@ def program_listing(request):
def program_details(request, program_uuid):
"""View details about a specific program."""
programs_config = ProgramsApiConfig.current()
if not programs_config.show_program_details:
if not programs_config.enabled:
raise Http404
program_data = get_programs(uuid=program_uuid)
......@@ -66,7 +66,7 @@ def program_details(request, program_uuid):
context = {
'program_data': program_data,
'urls': urls,
'show_program_listing': programs_config.show_program_listing,
'show_program_listing': programs_config.enabled,
'nav_hidden': True,
'disable_courseware_js': True,
'uses_pattern_library': True,
......
......@@ -596,7 +596,7 @@ class AccountSettingsViewTest(ThirdPartyAuthTestMixin, TestCase, ProgramsApiConf
"""
Verify that tabs header will be shown while program listing is enabled.
"""
self.create_programs_config(program_listing_enabled=True)
self.create_programs_config()
view_path = reverse('account_settings')
response = self.client.get(path=view_path)
......@@ -606,7 +606,7 @@ class AccountSettingsViewTest(ThirdPartyAuthTestMixin, TestCase, ProgramsApiConf
"""
Verify that nav header will be shown while program listing is disabled.
"""
self.create_programs_config(program_listing_enabled=False)
self.create_programs_config(enabled=False)
view_path = reverse('account_settings')
response = self.client.get(path=view_path)
......
......@@ -471,7 +471,7 @@ def account_settings_context(request):
'user_accounts_api_url': reverse("accounts_api", kwargs={'username': user.username}),
'user_preferences_api_url': reverse('preferences_api', kwargs={'username': user.username}),
'disable_courseware_js': True,
'show_program_listing': ProgramsApiConfig.current().show_program_listing,
'show_program_listing': ProgramsApiConfig.is_enabled(),
'order_history': user_orders
}
......
......@@ -94,52 +94,3 @@ class ProgramsApiConfig(ConfigurationModel):
verbose_name=_("Do we want to show program details pages"),
default=False
)
@property
def internal_api_url(self):
"""
Generate a URL based on internal service URL and API version number.
"""
return urljoin(self.internal_service_url, '/api/v{}/'.format(self.api_version_number))
@property
def public_api_url(self):
"""
Generate a URL based on public service URL and API version number.
"""
return urljoin(self.public_service_url, '/api/v{}/'.format(self.api_version_number))
@property
def is_cache_enabled(self):
"""Whether responses from the Programs API will be cached."""
return self.cache_ttl > 0
@property
def is_studio_tab_enabled(self):
"""
Indicates whether Studio functionality related to Programs should
be enabled or not.
"""
return self.enabled and self.enable_studio_tab
@property
def is_certification_enabled(self):
"""
Indicates whether background tasks should be initiated to grant
certificates for Program completion.
"""
return self.enabled and self.enable_certification
@property
def show_program_listing(self):
"""
Indicates whether we want to show program listing page
"""
return self.enabled and self.program_listing_enabled
@property
def show_program_details(self):
"""
Indicates whether we want to show program details pages
"""
return self.enabled and self.program_details_enabled
......@@ -5,6 +5,7 @@ from openedx.core.djangoapps.programs.models import ProgramsApiConfig
class ProgramsApiConfigMixin(object):
"""Utilities for working with Programs configuration during testing."""
# Update these paramters once fields are removed from model
DEFAULTS = {
'enabled': True,
'api_version_number': 1,
......
"""Tests for models supporting Program-related functionality."""
import ddt
from django.test import TestCase
import mock
from nose.plugins.attrib import attr
from openedx.core.djangoapps.programs.tests.mixins import ProgramsApiConfigMixin
from openedx.core.djangolib.testing.utils import skip_unless_lms
@skip_unless_lms
@attr(shard=2)
@ddt.ddt
# ConfigurationModels use the cache. Make every cache get a miss.
@mock.patch('config_models.models.cache.get', return_value=None)
class TestProgramsApiConfig(ProgramsApiConfigMixin, TestCase):
"""Tests covering the ProgramsApiConfig model."""
def test_url_construction(self, _mock_cache):
"""Verify that URLs returned by the model are constructed correctly."""
programs_config = self.create_programs_config()
self.assertEqual(
programs_config.internal_api_url,
programs_config.internal_service_url.strip('/') + '/api/v{}/'.format(programs_config.api_version_number)
)
self.assertEqual(
programs_config.public_api_url,
programs_config.public_service_url.strip('/') + '/api/v{}/'.format(programs_config.api_version_number)
)
@ddt.data(
(0, False),
(1, True),
)
@ddt.unpack
def test_cache_control(self, cache_ttl, is_cache_enabled, _mock_cache):
"""Verify the behavior of the property controlling whether API responses are cached."""
programs_config = self.create_programs_config(cache_ttl=cache_ttl)
self.assertEqual(programs_config.is_cache_enabled, is_cache_enabled)
def test_is_studio_tab_enabled(self, _mock_cache):
"""
Verify that the property controlling display of the Studio tab is only True
when configuration is enabled and all required configuration is provided.
"""
programs_config = self.create_programs_config(enabled=False)
self.assertFalse(programs_config.is_studio_tab_enabled)
programs_config = self.create_programs_config(enable_studio_tab=False)
self.assertFalse(programs_config.is_studio_tab_enabled)
programs_config = self.create_programs_config()
self.assertTrue(programs_config.is_studio_tab_enabled)
def test_is_certification_enabled(self, _mock_cache):
"""
Verify that the property controlling certification-related functionality
for Programs behaves as expected.
"""
programs_config = self.create_programs_config(enabled=False)
self.assertFalse(programs_config.is_certification_enabled)
programs_config = self.create_programs_config(enable_certification=False)
self.assertFalse(programs_config.is_certification_enabled)
programs_config = self.create_programs_config()
self.assertTrue(programs_config.is_certification_enabled)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment