Skip to content

Commit

Permalink
feat: expand get_content_metadata REST API to support course run ke…
Browse files Browse the repository at this point in the history
…ys (#940)
  • Loading branch information
adamstankiewicz authored Sep 9, 2024
1 parent c56430e commit db89535
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
27 changes: 27 additions & 0 deletions enterprise_catalog/apps/api/v1/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,33 @@ def test_get_content_metadata_no_catalog_query(self):
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.json()['results'], [])

@mock.patch('enterprise_catalog.apps.api_client.enterprise_cache.EnterpriseApiClient')
def test_get_content_metadata_content_filters_course_run_key(self, mock_api_client):
"""
Test that the get_content_metadata view GET view will support a filter including
course run key(s), even when the catalog itself doesn't explictly contain course runs.
"""
mock_api_client.return_value.get_enterprise_customer.return_value = {
'slug': self.enterprise_slug,
'enable_learner_portal': True,
'modified': str(datetime.now().replace(tzinfo=pytz.UTC)),
}
course_metadata = ContentMetadataFactory(content_type=COURSE)
course_key = course_metadata.content_key
course_run_key = course_metadata.json_metadata['course_runs'][0]['key']
ContentMetadataFactory(
content_type=COURSE_RUN,
content_key=course_run_key,
parent_content_key=course_key
)
self.add_metadata_to_catalog(self.enterprise_catalog, [course_metadata])

url = f'{self._get_content_metadata_url(self.enterprise_catalog)}?content_keys={quote_plus(course_run_key)}'
response = self.client.get(url)
assert response.data.get('count') == 1
result = response.data.get('results')[0]
assert get_content_key(result) == course_metadata.content_key

@mock.patch('enterprise_catalog.apps.api_client.enterprise_cache.EnterpriseApiClient')
@ddt.data(
False,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def get_queryset(self, **kwargs):
queryset = self.enterprise_catalog.content_metadata
content_filter = kwargs.get('content_keys_filter')
if content_filter:
queryset = queryset.filter(content_key__in=content_filter)
queryset = self.enterprise_catalog.get_matching_content(content_keys=content_filter)

return queryset.order_by('catalog_queries')

Expand Down
1 change: 1 addition & 0 deletions enterprise_catalog/apps/catalog/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def json_metadata(self):
'owners': owners,
'advertised_course_run_uuid': str(FAKE_ADVERTISED_COURSE_RUN_UUID),
'course_runs': course_runs,
'course': self.content_key,
})
elif self.content_type == COURSE_RUN:
json_metadata.update({
Expand Down

0 comments on commit db89535

Please sign in to comment.