Skip to content

Commit

Permalink
style: quality fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zawan-ila committed Oct 10, 2024
1 parent 8138d20 commit 7f6de70
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions course_discovery/apps/api/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions course_discovery/apps/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
1 change: 1 addition & 0 deletions course_discovery/apps/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions course_discovery/apps/api/v1/tests/test_views/test_courses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down

0 comments on commit 7f6de70

Please sign in to comment.