Skip to content

Commit

Permalink
feat: handle 409 case (mark as active instead of recreating course)
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzawaleed01 committed Apr 2, 2024
1 parent 751ac18 commit 742b782
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Change Log
Unreleased
----------
[4.13.14]
---------
* feat: handle Degreed 409 case (mark as active instead of recreating course)

[4.13.13]
---------
* fix: adding additional info to the enterprise group serializer
Expand Down
2 changes: 1 addition & 1 deletion enterprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Your project description goes here.
"""

__version__ = "4.13.13"
__version__ = "4.13.14"
17 changes: 13 additions & 4 deletions integrated_channels/degreed2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,24 @@ def create_content_metadata(self, serialized_data):
external_id = a_course.get('external-id')
status_code, response_body = self._sync_content_metadata(a_course, 'post', self.get_courses_url())
if status_code == 409:
# course already exists, don't raise failure, but log and move on
# course already exists, don't raise failure, but try to mark it as active on Degreed side
# if succeeds, we'll treat this as a success
LOGGER.warning(
self.make_log_msg(
external_id,
f'Course with integration_id = {external_id} already exists, '
f'Course with integration_id = {external_id} already exists, marking it as active'
)
)
# content already exists, we'll treat this as a success
status_code = 200
try:
channel_metadata_item['courses'][0]['obsolete'] = False
return self.update_content_metadata(json.dumps(channel_metadata_item).encode('utf-8'))
except requests.exceptions.RequestException as exc:
raise ClientError(
'Degreed2APIClient request failed while handling 409: {error} {message}'.format(
error=exc.__class__.__name__,
message=str(exc)
)
) from exc
elif status_code >= 400:
raise ClientError(
f'Degreed2APIClient create_content_metadata failed with status {status_code}: {response_body}',
Expand Down
6 changes: 6 additions & 0 deletions tests/test_integrated_channels/test_degreed2/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,12 @@ def test_create_content_metadata_course_exists(self):
json='{}',
status=200
)
responses.add(
responses.PATCH,
f'{enterprise_config.degreed_base_url}api/v2/content/courses/{degreed_course_id}',
json='{}',
status=200
)
status_code, _ = degreed_api_client.create_content_metadata(create_course_payload())
# we treat as "course exists" as a success
assert status_code == 200
Expand Down

0 comments on commit 742b782

Please sign in to comment.