From 7f6de70a841cf48169e8a781faea1f1c6c6edec4 Mon Sep 17 00:00:00 2001 From: Ali Nawaz Date: Thu, 10 Oct 2024 20:38:53 +0500 Subject: [PATCH] style: quality fixes --- course_discovery/apps/api/cache.py | 1 + course_discovery/apps/api/serializers.py | 1 + course_discovery/apps/api/utils.py | 1 + course_discovery/apps/api/v1/tests/test_views/test_courses.py | 4 ++-- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/course_discovery/apps/api/cache.py b/course_discovery/apps/api/cache.py index 026703442c9..a4d0e1b746f 100644 --- a/course_discovery/apps/api/cache.py +++ b/course_discovery/apps/api/cache.py @@ -167,5 +167,6 @@ def list(self, request, *args, **kwargs): def retrieve(self, request, *args, **kwargs): return super().retrieve(request, *args, **kwargs) + def get_utm_source_request_cache_key(partner, user): return get_cache_key(partner=partner.id, user=user.id) diff --git a/course_discovery/apps/api/serializers.py b/course_discovery/apps/api/serializers.py index ba77cbc8cb3..cfb7a439883 100644 --- a/course_discovery/apps/api/serializers.py +++ b/course_discovery/apps/api/serializers.py @@ -147,6 +147,7 @@ def get_lms_course_url_for_archived(partner, course_key): return f'{lms_url}/courses/{course_key}/course/' + @use_request_cache("utm_source_cache", get_utm_source_request_cache_key) def get_utm_source_for_user(partner, user): """ diff --git a/course_discovery/apps/api/utils.py b/course_discovery/apps/api/utils.py index 5ca6e6e831a..4febf91fe3a 100644 --- a/course_discovery/apps/api/utils.py +++ b/course_discovery/apps/api/utils.py @@ -354,6 +354,7 @@ def push_to_studio(self, course_run, create=False, old_course_run_key=None, user else: self.update_course_run_details_in_studio(course_run) + def use_request_cache(cache_name, key_func): def inner(fn): @functools.wraps(fn) diff --git a/course_discovery/apps/api/v1/tests/test_views/test_courses.py b/course_discovery/apps/api/v1/tests/test_views/test_courses.py index a34bc4f7204..6ce74eb0abf 100644 --- a/course_discovery/apps/api/v1/tests/test_views/test_courses.py +++ b/course_discovery/apps/api/v1/tests/test_views/test_courses.py @@ -352,7 +352,7 @@ def test_list(self): response.data['results'], self.serialize_course(Course.objects.all(), many=True) ) - + def test_no_repeated_cache_calls_for_utm_calculation(self): """ Test that utm source calculation is done only once per request, and not per @@ -370,7 +370,7 @@ def test_no_repeated_cache_calls_for_utm_calculation(self): }) as mocked_api_access_request: with override_switch('use_company_name_as_utm_source_value', True): url = reverse('api:v1:course-list') - response = self.client.get(url) + self.client.get(url) mocked_api_access_request.assert_called_once() @pytest.mark.skip(reason="https://github.com/openedx/course-discovery/issues/4431")