Skip to content

Commit

Permalink
fix: allow periods in pk lookup_value_regex for ContentMetadataView (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
adamstankiewicz authored Mar 4, 2025
1 parent c938a53 commit 1d990b0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions enterprise_catalog/apps/api/v1/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2321,6 +2321,25 @@ def test_retrieve_success(
)
assert response_json.get('key') == expected_object_to_receive.content_key

def test_retrieve_success_with_content_key_containing_period(self):
"""
Test a successful, expected api response for the metadata fetch endpoint given a content key containing
a period.
"""
content_key_with_period = 'foo.bar'
ContentMetadataFactory(
content_type=COURSE,
content_key=content_key_with_period,
json_metadata={'key': content_key_with_period},
)
url = reverse(
'api:v1:content-metadata-detail',
kwargs={'pk': content_key_with_period}
)
response = self.client.get(url)
response_json = response.json()
assert response_json.get('key') == content_key_with_period


@ddt.ddt
class CatalogQueryViewTests(APITestMixin):
Expand Down
1 change: 1 addition & 0 deletions enterprise_catalog/apps/api/v1/views/content_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ContentMetadataView(viewsets.ReadOnlyModelViewSet):
"""
View for retrieving and listing base content metadata.
"""
lookup_value_regex = r'[^/]+' # Allow any non-slash character in the pk (including periods).
serializer_class = ContentMetadataSerializer
authentication_classes = [JwtAuthentication, SessionAuthentication]
permission_classes = [permissions.IsAuthenticated]
Expand Down

0 comments on commit 1d990b0

Please sign in to comment.