Merge pull request #23047 from edx/ormsbee/update_config_models

Python upgrades (django-config-models v2)+
This commit is contained in:
David Ormsbee
2020-02-10 09:13:10 -05:00
committed by GitHub
9 changed files with 21 additions and 19 deletions

View File

@@ -2,19 +2,18 @@
import ddt
import mock
from django.test import TestCase, override_settings
from openedx.core.djangoapps.catalog.tests import mixins
from openedx.core.djangoapps.site_configuration.tests.test_util import with_site_configuration
from openedx.core.djangolib.testing.utils import CacheIsolationTestCase
COURSE_CATALOG_API_URL = 'https://api.example.com/v1/'
@ddt.ddt
# ConfigurationModels use the cache. Make every cache get a miss.
@mock.patch('config_models.models.cache.get', return_value=None)
class TestCatalogIntegration(mixins.CatalogIntegrationMixin, TestCase):
class TestCatalogIntegration(mixins.CatalogIntegrationMixin, CacheIsolationTestCase):
"""Tests covering the CatalogIntegration model."""
def assert_get_internal_api_url_value(self, expected):
@@ -27,13 +26,13 @@ class TestCatalogIntegration(mixins.CatalogIntegrationMixin, TestCase):
(1, True),
)
@ddt.unpack
def test_cache_control(self, cache_ttl, is_cache_enabled, _mock_cache):
def test_cache_control(self, cache_ttl, is_cache_enabled):
"""Test the behavior of the property controlling whether API responses are cached."""
catalog_integration = self.create_catalog_integration(cache_ttl=cache_ttl)
self.assertEqual(catalog_integration.is_cache_enabled, is_cache_enabled)
@override_settings(COURSE_CATALOG_API_URL=COURSE_CATALOG_API_URL)
def test_get_internal_api_url(self, _mock_cache):
def test_get_internal_api_url(self):
""" Requests made without a microsite should return the value from settings. """
self.assert_get_internal_api_url_value(COURSE_CATALOG_API_URL)
catalog_integration = self.create_catalog_integration()
@@ -41,14 +40,14 @@ class TestCatalogIntegration(mixins.CatalogIntegrationMixin, TestCase):
@override_settings(COURSE_CATALOG_API_URL=COURSE_CATALOG_API_URL)
@with_site_configuration(configuration={})
def test_get_internal_api_url_without_microsite_override(self, _mock_cache):
def test_get_internal_api_url_without_microsite_override(self):
""" Requests made to microsites that do not have COURSE_CATALOG_API_URL overridden should
return the default value from settings. """
self.assert_get_internal_api_url_value(COURSE_CATALOG_API_URL)
@override_settings(COURSE_CATALOG_API_URL=COURSE_CATALOG_API_URL)
@with_site_configuration(configuration={'COURSE_CATALOG_API_URL': 'foo'})
def test_get_internal_api_url_with_microsite_override(self, _mock_cache):
def test_get_internal_api_url_with_microsite_override(self):
""" If a microsite has overridden the value of COURSE_CATALOG_API_URL, the overridden
value should be returned. """
self.assert_get_internal_api_url_value('foo')

View File

@@ -439,7 +439,7 @@ class TestGetLocalizedPriceText(TestCase):
@skip_unless_lms
@mock.patch(UTILS_MODULE + '.get_edx_api_data')
class TestGetCourseRuns(CatalogIntegrationMixin, TestCase):
class TestGetCourseRuns(CatalogIntegrationMixin, CacheIsolationTestCase):
"""
Tests covering retrieval of course runs from the catalog service.
"""
@@ -474,6 +474,7 @@ class TestGetCourseRuns(CatalogIntegrationMixin, TestCase):
Verify that no errors occur when catalog config is missing.
"""
CatalogIntegration.objects.all().delete()
self.clear_caches()
data = get_course_runs()
self.assertFalse(mock_get_edx_api_data.called)