Skip to content

Commit

Permalink
Merge pull request #208 from openedx/asheehan-edx/parsing-catalog-api…
Browse files Browse the repository at this point in the history
…-response-results

fix: pulling results out of the response payload from the catalog service for content metadata
  • Loading branch information
alex-sheehan-edx authored Feb 15, 2024
2 parents 5ada832 + d6fc1af commit a8df681
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion enterprise_subsidy/apps/api_client/enterprise_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def get_content_metadata(self, content_identifier, **kwargs):
try:
response = self.client.get(content_metadata_url, params=query_params)
response.raise_for_status()
return response.json()
response_json = response.json()
return response_json['results'][0] if response_json['results'] else None
except requests.exceptions.HTTPError as exc:
if hasattr(response, 'text'):
logger.exception(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,15 @@ def test_successful_fetch_course_content_metadata(self, mock_oauth_client):
Test the enterprise catalog client's ability to handle api requests to fetch content metadata from the catalog
service.
"""
mock_oauth_client.return_value.get.return_value = MockResponse(self.course_metadata, 200)
mock_oauth_client.return_value.get.return_value = MockResponse(
{
'results': [self.course_metadata],
'count': 1,
'next': None,
'previous': None,
},
200,
)
enterprise_catalog_client = EnterpriseCatalogApiClient()
response = enterprise_catalog_client.get_content_metadata(self.course_key)
assert response == self.course_metadata
Expand Down

0 comments on commit a8df681

Please sign in to comment.