Commit 8173182c by Afzal Wali

Taking the url change behind the waffle switch. Required for the Learner-1146

Learner-1111
parent f318661d
...@@ -9,6 +9,7 @@ from datetime import datetime ...@@ -9,6 +9,7 @@ from datetime import datetime
import ddt import ddt
import freezegun import freezegun
import httpretty import httpretty
import waffle
from django.conf import settings from django.conf import settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from mock import patch from mock import patch
...@@ -157,6 +158,7 @@ class CourseModeViewTest(CatalogIntegrationMixin, UrlResetMixin, ModuleStoreTest ...@@ -157,6 +158,7 @@ class CourseModeViewTest(CatalogIntegrationMixin, UrlResetMixin, ModuleStoreTest
self.assertEquals(response.status_code, 200) self.assertEquals(response.status_code, 200)
@httpretty.activate @httpretty.activate
@waffle.testutils.override_switch("populate-multitenant-programs", True)
def test_enterprise_learner_context(self): def test_enterprise_learner_context(self):
""" """
Test: Track selection page should show the enterprise context message if user belongs to the Enterprise. Test: Track selection page should show the enterprise context message if user belongs to the Enterprise.
...@@ -177,6 +179,7 @@ class CourseModeViewTest(CatalogIntegrationMixin, UrlResetMixin, ModuleStoreTest ...@@ -177,6 +179,7 @@ class CourseModeViewTest(CatalogIntegrationMixin, UrlResetMixin, ModuleStoreTest
) )
@httpretty.activate @httpretty.activate
@waffle.testutils.override_switch("populate-multitenant-programs", True)
def test_enterprise_learner_context_with_multiple_organizations(self): def test_enterprise_learner_context_with_multiple_organizations(self):
""" """
Test: Track selection page should show the enterprise context message with multiple organization names Test: Track selection page should show the enterprise context message with multiple organization names
...@@ -209,6 +212,7 @@ class CourseModeViewTest(CatalogIntegrationMixin, UrlResetMixin, ModuleStoreTest ...@@ -209,6 +212,7 @@ class CourseModeViewTest(CatalogIntegrationMixin, UrlResetMixin, ModuleStoreTest
) )
@httpretty.activate @httpretty.activate
@waffle.testutils.override_switch("populate-multitenant-programs", True)
def test_enterprise_learner_context_audit_disabled(self): def test_enterprise_learner_context_audit_disabled(self):
""" """
Track selection page should hide the audit choice by default in an Enterprise Customer/Learner context Track selection page should hide the audit choice by default in an Enterprise Customer/Learner context
......
...@@ -4,15 +4,18 @@ import json ...@@ -4,15 +4,18 @@ import json
import ddt import ddt
import httpretty import httpretty
import waffle
from django.conf import settings from django.conf import settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.test import TestCase from django.test import TestCase
from django.test.utils import override_settings from django.test.utils import override_settings
from oauth2_provider.models import get_application_model from oauth2_provider.models import get_application_model
from openedx.core.djangoapps.api_admin.models import ApiAccessRequest, ApiAccessConfig from openedx.core.djangoapps.api_admin.models import ApiAccessConfig, ApiAccessRequest
from openedx.core.djangoapps.api_admin.tests.factories import ( from openedx.core.djangoapps.api_admin.tests.factories import (
ApiAccessRequestFactory, ApplicationFactory, CatalogFactory ApiAccessRequestFactory,
ApplicationFactory,
CatalogFactory
) )
from openedx.core.djangoapps.api_admin.tests.utils import VALID_DATA from openedx.core.djangoapps.api_admin.tests.utils import VALID_DATA
from openedx.core.djangolib.testing.utils import skip_unless_lms from openedx.core.djangolib.testing.utils import skip_unless_lms
...@@ -263,6 +266,7 @@ class CatalogSearchViewTest(CatalogTest): ...@@ -263,6 +266,7 @@ class CatalogSearchViewTest(CatalogTest):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
@httpretty.activate @httpretty.activate
@waffle.testutils.override_switch("populate-multitenant-programs", True)
def test_post(self): def test_post(self):
catalog_user = UserFactory() catalog_user = UserFactory()
self.mock_catalog_endpoint({'results': []}) self.mock_catalog_endpoint({'results': []})
...@@ -285,6 +289,7 @@ class CatalogListViewTest(CatalogTest): ...@@ -285,6 +289,7 @@ class CatalogListViewTest(CatalogTest):
self.url = reverse('api_admin:catalog-list', kwargs={'username': self.catalog_user.username}) self.url = reverse('api_admin:catalog-list', kwargs={'username': self.catalog_user.username})
@httpretty.activate @httpretty.activate
@waffle.testutils.override_switch("populate-multitenant-programs", True)
def test_get(self): def test_get(self):
catalog = CatalogFactory(viewers=[self.catalog_user.username]) catalog = CatalogFactory(viewers=[self.catalog_user.username])
self.mock_catalog_endpoint({'results': [catalog.attributes]}) self.mock_catalog_endpoint({'results': [catalog.attributes]})
...@@ -293,6 +298,7 @@ class CatalogListViewTest(CatalogTest): ...@@ -293,6 +298,7 @@ class CatalogListViewTest(CatalogTest):
self.assertIn(catalog.name, response.content.decode('utf-8')) self.assertIn(catalog.name, response.content.decode('utf-8'))
@httpretty.activate @httpretty.activate
@waffle.testutils.override_switch("populate-multitenant-programs", True)
def test_get_no_catalogs(self): def test_get_no_catalogs(self):
"""Verify that the view works when no catalogs are set up.""" """Verify that the view works when no catalogs are set up."""
self.mock_catalog_endpoint({}, status_code=404) self.mock_catalog_endpoint({}, status_code=404)
...@@ -300,6 +306,7 @@ class CatalogListViewTest(CatalogTest): ...@@ -300,6 +306,7 @@ class CatalogListViewTest(CatalogTest):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
@httpretty.activate @httpretty.activate
@waffle.testutils.override_switch("populate-multitenant-programs", True)
def test_post(self): def test_post(self):
catalog_data = { catalog_data = {
'name': 'test-catalog', 'name': 'test-catalog',
...@@ -314,6 +321,7 @@ class CatalogListViewTest(CatalogTest): ...@@ -314,6 +321,7 @@ class CatalogListViewTest(CatalogTest):
self.assertRedirects(response, reverse('api_admin:catalog-edit', kwargs={'catalog_id': catalog_id})) self.assertRedirects(response, reverse('api_admin:catalog-edit', kwargs={'catalog_id': catalog_id}))
@httpretty.activate @httpretty.activate
@waffle.testutils.override_switch("populate-multitenant-programs", True)
def test_post_invalid(self): def test_post_invalid(self):
catalog = CatalogFactory(viewers=[self.catalog_user.username]) catalog = CatalogFactory(viewers=[self.catalog_user.username])
self.mock_catalog_endpoint({'results': [catalog.attributes]}) self.mock_catalog_endpoint({'results': [catalog.attributes]})
...@@ -339,6 +347,7 @@ class CatalogEditViewTest(CatalogTest): ...@@ -339,6 +347,7 @@ class CatalogEditViewTest(CatalogTest):
self.url = reverse('api_admin:catalog-edit', kwargs={'catalog_id': self.catalog.id}) self.url = reverse('api_admin:catalog-edit', kwargs={'catalog_id': self.catalog.id})
@httpretty.activate @httpretty.activate
@waffle.testutils.override_switch("populate-multitenant-programs", True)
def test_get(self): def test_get(self):
self.mock_catalog_endpoint(self.catalog.attributes, catalog_id=self.catalog.id) self.mock_catalog_endpoint(self.catalog.attributes, catalog_id=self.catalog.id)
response = self.client.get(self.url) response = self.client.get(self.url)
...@@ -346,6 +355,7 @@ class CatalogEditViewTest(CatalogTest): ...@@ -346,6 +355,7 @@ class CatalogEditViewTest(CatalogTest):
self.assertIn(self.catalog.name, response.content.decode('utf-8')) self.assertIn(self.catalog.name, response.content.decode('utf-8'))
@httpretty.activate @httpretty.activate
@waffle.testutils.override_switch("populate-multitenant-programs", True)
def test_delete(self): def test_delete(self):
self.mock_catalog_endpoint( self.mock_catalog_endpoint(
self.catalog.attributes, self.catalog.attributes,
...@@ -362,6 +372,7 @@ class CatalogEditViewTest(CatalogTest): ...@@ -362,6 +372,7 @@ class CatalogEditViewTest(CatalogTest):
self.assertEqual(len(httpretty.httpretty.latest_requests), 1) self.assertEqual(len(httpretty.httpretty.latest_requests), 1)
@httpretty.activate @httpretty.activate
@waffle.testutils.override_switch("populate-multitenant-programs", True)
def test_edit(self): def test_edit(self):
self.mock_catalog_endpoint(self.catalog.attributes, method=httpretty.PATCH, catalog_id=self.catalog.id) self.mock_catalog_endpoint(self.catalog.attributes, method=httpretty.PATCH, catalog_id=self.catalog.id)
new_attributes = dict(self.catalog.attributes, **{'delete-catalog': 'off', 'name': 'changed'}) new_attributes = dict(self.catalog.attributes, **{'delete-catalog': 'off', 'name': 'changed'})
...@@ -370,6 +381,7 @@ class CatalogEditViewTest(CatalogTest): ...@@ -370,6 +381,7 @@ class CatalogEditViewTest(CatalogTest):
self.assertRedirects(response, reverse('api_admin:catalog-edit', kwargs={'catalog_id': self.catalog.id})) self.assertRedirects(response, reverse('api_admin:catalog-edit', kwargs={'catalog_id': self.catalog.id}))
@httpretty.activate @httpretty.activate
@waffle.testutils.override_switch("populate-multitenant-programs", True)
def test_edit_invalid(self): def test_edit_invalid(self):
self.mock_catalog_endpoint(self.catalog.attributes, catalog_id=self.catalog.id) self.mock_catalog_endpoint(self.catalog.attributes, catalog_id=self.catalog.id)
new_attributes = dict(self.catalog.attributes, **{'delete-catalog': 'off', 'name': ''}) new_attributes = dict(self.catalog.attributes, **{'delete-catalog': 'off', 'name': ''})
...@@ -389,6 +401,7 @@ class CatalogPreviewViewTest(CatalogTest): ...@@ -389,6 +401,7 @@ class CatalogPreviewViewTest(CatalogTest):
self.url = reverse('api_admin:catalog-preview') self.url = reverse('api_admin:catalog-preview')
@httpretty.activate @httpretty.activate
@waffle.testutils.override_switch("populate-multitenant-programs", True)
def test_get(self): def test_get(self):
data = {'count': 1, 'results': ['test data'], 'next': None, 'prev': None} data = {'count': 1, 'results': ['test data'], 'next': None, 'prev': None}
httpretty.register_uri( httpretty.register_uri(
...@@ -401,6 +414,7 @@ class CatalogPreviewViewTest(CatalogTest): ...@@ -401,6 +414,7 @@ class CatalogPreviewViewTest(CatalogTest):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEqual(json.loads(response.content), data) self.assertEqual(json.loads(response.content), data)
@waffle.testutils.override_switch("populate-multitenant-programs", True)
def test_get_without_query(self): def test_get_without_query(self):
response = self.client.get(self.url) response = self.client.get(self.url)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
......
...@@ -9,7 +9,6 @@ from openedx.core.djangoapps.catalog.cache import PROGRAM_CACHE_KEY_TPL, PROGRAM ...@@ -9,7 +9,6 @@ from openedx.core.djangoapps.catalog.cache import PROGRAM_CACHE_KEY_TPL, PROGRAM
from openedx.core.djangoapps.catalog.models import CatalogIntegration from openedx.core.djangoapps.catalog.models import CatalogIntegration
from openedx.core.djangoapps.catalog.utils import create_catalog_api_client from openedx.core.djangoapps.catalog.utils import create_catalog_api_client
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
User = get_user_model() # pylint: disable=invalid-name User = get_user_model() # pylint: disable=invalid-name
......
"""Models governing integration with the catalog service.""" """Models governing integration with the catalog service."""
import waffle
from config_models.models import ConfigurationModel from config_models.models import ConfigurationModel
from django.conf import settings from django.conf import settings
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
...@@ -54,7 +55,10 @@ class CatalogIntegration(ConfigurationModel): ...@@ -54,7 +55,10 @@ class CatalogIntegration(ConfigurationModel):
def get_internal_api_url(self): def get_internal_api_url(self):
""" Returns the internal Catalog API URL associated with the request's site. """ """ Returns the internal Catalog API URL associated with the request's site. """
return helpers.get_value('COURSE_CATALOG_API_URL', settings.COURSE_CATALOG_API_URL) if waffle.switch_is_active("populate-multitenant-programs"):
return helpers.get_value('COURSE_CATALOG_API_URL', settings.COURSE_CATALOG_API_URL)
else:
return self.internal_api_url
def get_service_user(self): def get_service_user(self):
# NOTE: We load the user model here to avoid issues at startup time that result from the hacks # NOTE: We load the user model here to avoid issues at startup time that result from the hacks
......
"""Catalog model tests.""" """Catalog model tests."""
import ddt import ddt
import mock import mock
import waffle
from django.test import TestCase, override_settings from django.test import TestCase, override_settings
from openedx.core.djangoapps.catalog.tests import mixins from openedx.core.djangoapps.catalog.tests import mixins
...@@ -31,6 +32,7 @@ class TestCatalogIntegration(mixins.CatalogIntegrationMixin, TestCase): ...@@ -31,6 +32,7 @@ class TestCatalogIntegration(mixins.CatalogIntegrationMixin, TestCase):
self.assertEqual(catalog_integration.is_cache_enabled, is_cache_enabled) self.assertEqual(catalog_integration.is_cache_enabled, is_cache_enabled)
@override_settings(COURSE_CATALOG_API_URL=COURSE_CATALOG_API_URL) @override_settings(COURSE_CATALOG_API_URL=COURSE_CATALOG_API_URL)
@waffle.testutils.override_switch("populate-multitenant-programs", True)
def test_get_internal_api_url(self, _mock_cache): def test_get_internal_api_url(self, _mock_cache):
""" Requests made without a microsite should return the value from settings. """ """ Requests made without a microsite should return the value from settings. """
self.assert_get_internal_api_url_value(COURSE_CATALOG_API_URL) self.assert_get_internal_api_url_value(COURSE_CATALOG_API_URL)
...@@ -39,6 +41,7 @@ class TestCatalogIntegration(mixins.CatalogIntegrationMixin, TestCase): ...@@ -39,6 +41,7 @@ class TestCatalogIntegration(mixins.CatalogIntegrationMixin, TestCase):
@override_settings(COURSE_CATALOG_API_URL=COURSE_CATALOG_API_URL) @override_settings(COURSE_CATALOG_API_URL=COURSE_CATALOG_API_URL)
@with_site_configuration(configuration={}) @with_site_configuration(configuration={})
@waffle.testutils.override_switch("populate-multitenant-programs", True)
def test_get_internal_api_url_without_microsite_override(self, _mock_cache): def test_get_internal_api_url_without_microsite_override(self, _mock_cache):
""" Requests made to microsites that do not have COURSE_CATALOG_API_URL overridden should """ Requests made to microsites that do not have COURSE_CATALOG_API_URL overridden should
return the default value from settings. """ return the default value from settings. """
...@@ -46,6 +49,7 @@ class TestCatalogIntegration(mixins.CatalogIntegrationMixin, TestCase): ...@@ -46,6 +49,7 @@ class TestCatalogIntegration(mixins.CatalogIntegrationMixin, TestCase):
@override_settings(COURSE_CATALOG_API_URL=COURSE_CATALOG_API_URL) @override_settings(COURSE_CATALOG_API_URL=COURSE_CATALOG_API_URL)
@with_site_configuration(configuration={'COURSE_CATALOG_API_URL': 'foo'}) @with_site_configuration(configuration={'COURSE_CATALOG_API_URL': 'foo'})
@waffle.testutils.override_switch("populate-multitenant-programs", True)
def test_get_internal_api_url_with_microsite_override(self, _mock_cache): def test_get_internal_api_url_with_microsite_override(self, _mock_cache):
""" If a microsite has overridden the value of COURSE_CATALOG_API_URL, the overridden """ If a microsite has overridden the value of COURSE_CATALOG_API_URL, the overridden
value should be returned. """ value should be returned. """
......
...@@ -4,6 +4,7 @@ import json ...@@ -4,6 +4,7 @@ import json
import httpretty import httpretty
import mock import mock
import waffle
from django.core.cache import cache from django.core.cache import cache
from django.test.utils import override_settings from django.test.utils import override_settings
from edx_oauth2_provider.tests.factories import ClientFactory from edx_oauth2_provider.tests.factories import ClientFactory
...@@ -73,6 +74,7 @@ class TestGetEdxApiData(CatalogIntegrationMixin, CredentialsApiConfigMixin, Cach ...@@ -73,6 +74,7 @@ class TestGetEdxApiData(CatalogIntegrationMixin, CredentialsApiConfigMixin, Cach
# Verify the API was actually hit (not the cache) # Verify the API was actually hit (not the cache)
self._assert_num_requests(1) self._assert_num_requests(1)
@waffle.testutils.override_switch("populate-multitenant-programs", True)
def test_get_paginated_data(self): def test_get_paginated_data(self):
"""Verify that paginated data can be retrieved.""" """Verify that paginated data can be retrieved."""
catalog_integration = self.create_catalog_integration() catalog_integration = self.create_catalog_integration()
...@@ -100,6 +102,7 @@ class TestGetEdxApiData(CatalogIntegrationMixin, CredentialsApiConfigMixin, Cach ...@@ -100,6 +102,7 @@ class TestGetEdxApiData(CatalogIntegrationMixin, CredentialsApiConfigMixin, Cach
self._assert_num_requests(len(expected_collection)) self._assert_num_requests(len(expected_collection))
@waffle.testutils.override_switch("populate-multitenant-programs", True)
def test_get_paginated_data_do_not_traverse_pagination(self): def test_get_paginated_data_do_not_traverse_pagination(self):
""" """
Verify that pagination is not traversed if traverse_pagination=False is passed as argument. Verify that pagination is not traversed if traverse_pagination=False is passed as argument.
...@@ -128,6 +131,7 @@ class TestGetEdxApiData(CatalogIntegrationMixin, CredentialsApiConfigMixin, Cach ...@@ -128,6 +131,7 @@ class TestGetEdxApiData(CatalogIntegrationMixin, CredentialsApiConfigMixin, Cach
self.assertEqual(actual_collection, expected_response) self.assertEqual(actual_collection, expected_response)
self._assert_num_requests(1) self._assert_num_requests(1)
@waffle.testutils.override_switch("populate-multitenant-programs", True)
def test_get_specific_resource(self): def test_get_specific_resource(self):
"""Verify that a specific resource can be retrieved.""" """Verify that a specific resource can be retrieved."""
catalog_integration = self.create_catalog_integration() catalog_integration = self.create_catalog_integration()
...@@ -151,6 +155,7 @@ class TestGetEdxApiData(CatalogIntegrationMixin, CredentialsApiConfigMixin, Cach ...@@ -151,6 +155,7 @@ class TestGetEdxApiData(CatalogIntegrationMixin, CredentialsApiConfigMixin, Cach
self._assert_num_requests(1) self._assert_num_requests(1)
@waffle.testutils.override_switch("populate-multitenant-programs", True)
def test_get_specific_resource_with_falsey_id(self): def test_get_specific_resource_with_falsey_id(self):
""" """
Verify that a specific resource can be retrieved, and pagination parsing is Verify that a specific resource can be retrieved, and pagination parsing is
...@@ -180,6 +185,7 @@ class TestGetEdxApiData(CatalogIntegrationMixin, CredentialsApiConfigMixin, Cach ...@@ -180,6 +185,7 @@ class TestGetEdxApiData(CatalogIntegrationMixin, CredentialsApiConfigMixin, Cach
self._assert_num_requests(1) self._assert_num_requests(1)
@waffle.testutils.override_switch("populate-multitenant-programs", True)
def test_cache_utilization(self): def test_cache_utilization(self):
"""Verify that when enabled, the cache is used.""" """Verify that when enabled, the cache is used."""
catalog_integration = self.create_catalog_integration(cache_ttl=5) catalog_integration = self.create_catalog_integration(cache_ttl=5)
......
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