Commit 457b9a11 by Douglas Hall Committed by GitHub

Merge pull request #16223 from edx/douglashall/ENT-704

Fix get_enterprise_customer api cache key.
parents c5e0ce50 2062dd86
...@@ -268,6 +268,7 @@ class EnterpriseApiServiceClient(EnterpriseServiceClientMixin, EnterpriseApiClie ...@@ -268,6 +268,7 @@ class EnterpriseApiServiceClient(EnterpriseServiceClientMixin, EnterpriseApiClie
""" """
cache_key = get_cache_key( cache_key = get_cache_key(
resource='enterprise-customer', resource='enterprise-customer',
resource_id=uuid,
username=settings.ENTERPRISE_SERVICE_WORKER_USERNAME, username=settings.ENTERPRISE_SERVICE_WORKER_USERNAME,
) )
enterprise_customer = cache.get(cache_key) enterprise_customer = cache.get(cache_key)
......
...@@ -88,17 +88,17 @@ class TestEnterpriseApi(EnterpriseServiceMockMixin, CacheIsolationTestCase): ...@@ -88,17 +88,17 @@ class TestEnterpriseApi(EnterpriseServiceMockMixin, CacheIsolationTestCase):
# pylint: disable=protected-access # pylint: disable=protected-access
self.assertEqual(enterprise_api_service_client.client._store['session'].auth.token, 'test-token') self.assertEqual(enterprise_api_service_client.client._store['session'].auth.token, 'test-token')
def _assert_get_enterprise_customer(self, api_client): def _assert_get_enterprise_customer(self, api_client, enterprise_api_data_for_mock):
""" """
DRY method to verify caching for get enterprise customer method. DRY method to verify caching for get enterprise customer method.
""" """
dummy_enterprise_api_data = {'name': 'dummy-enterprise-customer', 'uuid': 'enterprise-uuid'}
cache_key = get_cache_key( cache_key = get_cache_key(
resource='enterprise-customer', resource='enterprise-customer',
resource_id=enterprise_api_data_for_mock['uuid'],
username=settings.ENTERPRISE_SERVICE_WORKER_USERNAME, username=settings.ENTERPRISE_SERVICE_WORKER_USERNAME,
) )
self.mock_get_enterprise_customer('enterprise-uuid', dummy_enterprise_api_data, 200) self.mock_get_enterprise_customer(enterprise_api_data_for_mock['uuid'], enterprise_api_data_for_mock, 200)
self._assert_get_enterprise_customer_with_cache(api_client, dummy_enterprise_api_data, cache_key) self._assert_get_enterprise_customer_with_cache(api_client, enterprise_api_data_for_mock, cache_key)
def _assert_get_enterprise_customer_with_cache(self, api_client, enterprise_customer_data, cache_key): def _assert_get_enterprise_customer_with_cache(self, api_client, enterprise_customer_data, cache_key):
""" """
...@@ -121,10 +121,17 @@ class TestEnterpriseApi(EnterpriseServiceMockMixin, CacheIsolationTestCase): ...@@ -121,10 +121,17 @@ class TestEnterpriseApi(EnterpriseServiceMockMixin, CacheIsolationTestCase):
""" """
self._assert_api_service_client(EnterpriseApiServiceClient, mock_jwt_builder) self._assert_api_service_client(EnterpriseApiServiceClient, mock_jwt_builder)
# Now verify that enterprise customer data is cached properly for # Verify that enterprise customer data is cached properly for the
# the enterprise api client. # enterprise api client.
enterprise_api_client = EnterpriseApiServiceClient() enterprise_api_client = EnterpriseApiServiceClient()
self._assert_get_enterprise_customer(enterprise_api_client) enterprise_api_data_for_mock_1 = {'name': 'dummy-enterprise-customer-1', 'uuid': 'enterprise-uuid-1'}
self._assert_get_enterprise_customer(enterprise_api_client, enterprise_api_data_for_mock_1)
# Now try to get enterprise customer for another enterprise and verify
# that enterprise api client returns data according to the provided
# enterprise UUID.
enterprise_api_data_for_mock_2 = {'name': 'dummy-enterprise-customer-2', 'uuid': 'enterprise-uuid-2'}
self._assert_get_enterprise_customer(enterprise_api_client, enterprise_api_data_for_mock_2)
@httpretty.activate @httpretty.activate
@mock.patch('openedx.features.enterprise_support.api.JwtBuilder') @mock.patch('openedx.features.enterprise_support.api.JwtBuilder')
......
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