Skip to content

Commit

Permalink
Address code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
collinpreston committed Mar 20, 2023
1 parent 5d80f24 commit fe1146f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
7 changes: 4 additions & 3 deletions openedx/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,14 @@ def create_edx_user(user):
if not created and open_edx_user.has_been_synced:
# Here we should check with edx that the user exists on that end.
try:
get_edx_api_client(user)
client = get_edx_api_client(user)
client.user_info.get_user_info()
except:
pass
else:
open_edx_user.has_been_synced = True
open_edx_user.save()
return created
return False

# a non-200 status here will ensure we rollback creation of the OpenEdxUser and try again
req_session = requests.Session()
Expand Down Expand Up @@ -135,7 +136,7 @@ def create_edx_user(user):
)
open_edx_user.has_been_synced = True
open_edx_user.save()
return created
return True


@transaction.atomic
Expand Down
13 changes: 7 additions & 6 deletions openedx/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,18 @@ def test_create_edx_user_for_user_not_synced_with_edx(
OpenEdxUserFactory.create(
user=user, has_been_synced=open_edx_user_record_has_been_synced
)
mocker.patch(
"openedx.api.get_edx_api_client",
side_effect=ValueError("Unexpected error")
if not open_edx_user_record_exists
else None,
mock_client = mocker.MagicMock()
mock_client.user_info.get_user_info = mocker.Mock(
side_effect=Exception if not open_edx_user_record_exists else None,
)
mocker.patch("openedx.api.get_edx_api_client", return_value=mock_client)

user_created_in_edx = create_edx_user(user)

assert OpenEdxUser.objects.get(user=user).has_been_synced is True
assert user_created_in_edx is False if open_edx_user_record_exists else True
assert user_created_in_edx is not (
open_edx_user_record_exists and open_edx_user_record_has_been_synced
)


@responses.activate
Expand Down

0 comments on commit fe1146f

Please sign in to comment.