Add program UUID in cache key instead passing as resource id.

LEARNER-5373
This commit is contained in:
Waheed Ahmed
2018-05-31 01:22:17 +05:00
parent 172b1c8c09
commit bc358b89de
2 changed files with 9 additions and 10 deletions

View File

@@ -28,7 +28,7 @@ class TestGetCredentials(CredentialsApiConfigMixin, CacheIsolationTestCase):
ClientFactory(name=CredentialsApiConfig.OAUTH2_CLIENT_NAME, client_type=CONFIDENTIAL)
self.create_credentials_config()
self.credentials_config = self.create_credentials_config(cache_ttl=1)
self.user = UserFactory()
def test_get_many(self, mock_get_edx_api_data):
@@ -45,8 +45,9 @@ class TestGetCredentials(CredentialsApiConfigMixin, CacheIsolationTestCase):
'username': self.user.username,
'status': 'awarded',
}
cache_key = '{}.{}'.format(self.credentials_config.CACHE_KEY, self.user.username)
self.assertEqual(kwargs['querystring'], querystring)
self.assertIsNone(kwargs['resource_id'])
self.assertEqual(kwargs['cache_key'], cache_key)
self.assertEqual(actual, expected)
@@ -66,7 +67,8 @@ class TestGetCredentials(CredentialsApiConfigMixin, CacheIsolationTestCase):
'status': 'awarded',
'program_uuid': program_uuid,
}
cache_key = '{}.{}.{}'.format(self.credentials_config.CACHE_KEY, self.user.username, program_uuid)
self.assertEqual(kwargs['querystring'], querystring)
self.assertEqual(kwargs['resource_id'], program_uuid)
self.assertEqual(kwargs['cache_key'], cache_key)
self.assertEqual(actual, expected)

View File

@@ -55,14 +55,11 @@ def get_credentials(user, program_uuid=None):
# Bypass caching for staff users, who may be generating credentials and
# want to see them displayed immediately.
use_cache = credential_configuration.is_cache_enabled and not user.is_staff
cache_key = credential_configuration.CACHE_KEY + '.' + user.username if use_cache else None
cache_key = '{}.{}'.format(credential_configuration.CACHE_KEY, user.username) if use_cache else None
if cache_key and program_uuid:
cache_key = '{}.{}'.format(cache_key, program_uuid)
api = get_credentials_api_client(user)
return get_edx_api_data(
credential_configuration,
'credentials',
api=api,
resource_id=program_uuid,
querystring=querystring,
cache_key=cache_key
credential_configuration, 'credentials', api=api, querystring=querystring, cache_key=cache_key
)