Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: content metadata list filter accepts uuids #768

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion enterprise_catalog/apps/api/v1/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2395,7 +2395,8 @@ def test_list_with_content_keys(self):
Test a successful, expected api response for the metadata list endpoint with a supplied content keys query
param
"""
url = reverse('api:v1:content-metadata-list') + f"?content_keys={self.content_metadata_object.content_key}"
query_param_string = f"?content_identifiers={self.content_metadata_object.content_key}"
url = reverse('api:v1:content-metadata-list') + query_param_string
response = self.client.get(url)
response_json = response.json()
assert len(response_json.get('results')) == 1
Expand All @@ -2413,3 +2414,15 @@ def test_get_success(self):
response = self.client.get(url)
response_json = response.json()
assert response_json.get('title') == self.content_metadata_object.json_metadata.get('title')

def test_filter_list_by_uuid(self):
"""
Test that the list content_identifiers query param accepts uuids
"""
query_param_string = f"?content_identifiers={self.content_metadata_object.content_uuid}"
url = reverse('api:v1:content-metadata-list') + query_param_string
response = self.client.get(url)
response_json = response.json()
assert len(response_json.get('results')) == 1
assert response_json.get('results')[0].get("key") == self.content_metadata_object.content_key
assert response_json.get('results')[0].get("course_runs")[0].get('start') == '2024-02-12T11:00:00Z'
7 changes: 4 additions & 3 deletions enterprise_catalog/apps/api/v1/views/content_metadata.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.db.models import Q
from edx_rest_framework_extensions.auth.jwt.authentication import (
JwtAuthentication,
)
Expand Down Expand Up @@ -26,10 +27,10 @@

def get_queryset(self, **kwargs):
"""
Returns all content metadata objects filtered by an optional request query param ``content_keys`` (LIST).
Returns all content metadata objects filtered by an optional request query param (LIST) ``content_identifiers``
"""
content_filter = kwargs.get('content_keys')
content_filter = kwargs.get('content_identifiers')
queryset = self.queryset
if content_filter:
return queryset.filter(content_key__in=content_filter)
return queryset.filter(Q(content_key__in=content_filter) | Q(uuid__in=content_filter))

Check warning on line 35 in enterprise_catalog/apps/api/v1/views/content_metadata.py

View check run for this annotation

Codecov / codecov/patch

enterprise_catalog/apps/api/v1/views/content_metadata.py#L35

Added line #L35 was not covered by tests
return queryset
Loading