-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ability to retire users on edX (#1785)
* feat: add ability to retire users on edX * fix tests * fix tests * update app-json * added checks for client id and secret * tests: add tests * requirements: updated edx-api-client version * update dependency * update dependency
- Loading branch information
1 parent
d5961fe
commit 3ca0128
Showing
9 changed files
with
196 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,10 +15,15 @@ | |
|
||
|
||
@pytest.mark.django_db | ||
def test_single_success(): | ||
def test_single_success(mocker): | ||
"""test retire_users command success with one user""" | ||
test_username = "test_user" | ||
|
||
mock_bulk_retire_edx_users = mocker.patch( | ||
"users.management.commands.retire_users.bulk_retire_edx_users", | ||
return_value={"successful_user_retirements": [test_username]}, | ||
) | ||
|
||
user = UserFactory.create(username=test_username, is_active=True) | ||
UserSocialAuthFactory.create(user=user, provider="edX") | ||
|
||
|
@@ -32,13 +37,19 @@ def test_single_success(): | |
assert user.is_active is False | ||
assert "retired_email" in user.email | ||
assert UserSocialAuth.objects.filter(user=user).count() == 0 | ||
mock_bulk_retire_edx_users.assert_called() | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_multiple_success(): | ||
def test_multiple_success(mocker): | ||
"""test retire_users command success with more than one user""" | ||
test_usernames = ["foo", "bar", "baz"] | ||
|
||
mock_bulk_retire_edx_users = mocker.patch( | ||
"users.management.commands.retire_users.bulk_retire_edx_users", | ||
return_value={"successful_user_retirements": test_usernames}, | ||
) | ||
|
||
for username in test_usernames: | ||
user = UserFactory.create(username=username, is_active=True) | ||
UserSocialAuthFactory.create(user=user, provider="not_edx") | ||
|
@@ -54,16 +65,22 @@ def test_multiple_success(): | |
assert user.is_active is False | ||
assert "retired_email" in user.email | ||
assert UserSocialAuth.objects.filter(user=user).count() == 0 | ||
mock_bulk_retire_edx_users.assert_called() | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_retire_user_with_email(): | ||
def test_retire_user_with_email(mocker): | ||
"""test retire_users command success with user email""" | ||
test_email = "[email protected]" | ||
|
||
user = UserFactory.create(email=test_email, is_active=True) | ||
UserSocialAuthFactory.create(user=user, provider="edX") | ||
|
||
mock_bulk_retire_edx_users = mocker.patch( | ||
"users.management.commands.retire_users.bulk_retire_edx_users", | ||
return_value={"successful_user_retirements": [user.username]}, | ||
) | ||
|
||
assert user.is_active is True | ||
assert "retired_email" not in user.email | ||
assert UserSocialAuth.objects.filter(user=user).count() == 1 | ||
|
@@ -74,10 +91,11 @@ def test_retire_user_with_email(): | |
assert user.is_active is False | ||
assert "retired_email" in user.email | ||
assert UserSocialAuth.objects.filter(user=user).count() == 0 | ||
mock_bulk_retire_edx_users.assert_called_with(user.username) | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_retire_user_blocking_with_email(): | ||
def test_retire_user_blocking_with_email(mocker): | ||
"""test retire_users command success with user email""" | ||
test_email = "[email protected]" | ||
|
||
|
@@ -90,6 +108,10 @@ def test_retire_user_blocking_with_email(): | |
assert UserSocialAuth.objects.filter(user=user).count() == 1 | ||
assert BlockList.objects.all().count() == 0 | ||
|
||
mock_bulk_retire_edx_users = mocker.patch( | ||
"users.management.commands.retire_users.bulk_retire_edx_users", | ||
return_value={"successful_user_retirements": [user.username]}, | ||
) | ||
COMMAND.handle("retire_users", users=[test_email], block_users=True) | ||
|
||
user.refresh_from_db() | ||
|
@@ -98,12 +120,17 @@ def test_retire_user_blocking_with_email(): | |
assert UserSocialAuth.objects.filter(user=user).count() == 0 | ||
assert BlockList.objects.all().count() == 1 | ||
assert BlockList.objects.filter(hashed_email=hashed_email).count() == 1 | ||
mock_bulk_retire_edx_users.assert_called_with(user.username) | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_multiple_success_blocking_user(): | ||
def test_multiple_success_blocking_user(mocker): | ||
"""test retire_users command blocking emails success with more than one user""" | ||
test_usernames = ["foo", "bar", "baz"] | ||
mock_bulk_retire_edx_users = mocker.patch( | ||
"users.management.commands.retire_users.bulk_retire_edx_users", | ||
return_value={"successful_user_retirements": test_usernames}, | ||
) | ||
|
||
for username in test_usernames: | ||
user = UserFactory.create(username=username, is_active=True) | ||
|
@@ -123,10 +150,11 @@ def test_multiple_success_blocking_user(): | |
assert UserSocialAuth.objects.filter(user=user).count() == 0 | ||
|
||
assert BlockList.objects.all().count() == 3 | ||
mock_bulk_retire_edx_users.assert_called() | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_user_blocking_if_not_requested(): | ||
def test_user_blocking_if_not_requested(mocker): | ||
"""test retire_users command success but it should not block user(s) if not requested""" | ||
test_email = "[email protected]" | ||
|
||
|
@@ -139,10 +167,15 @@ def test_user_blocking_if_not_requested(): | |
assert UserSocialAuth.objects.filter(user=user).count() == 1 | ||
assert BlockList.objects.all().count() == 0 | ||
|
||
mock_bulk_retire_edx_users = mocker.patch( | ||
"users.management.commands.retire_users.bulk_retire_edx_users", | ||
return_value={"successful_user_retirements": [user.username]}, | ||
) | ||
COMMAND.handle("retire_users", users=[test_email]) | ||
|
||
user.refresh_from_db() | ||
assert user.is_active is False | ||
assert "retired_email" in user.email | ||
assert UserSocialAuth.objects.filter(user=user).count() == 0 | ||
assert BlockList.objects.all().count() == 0 | ||
mock_bulk_retire_edx_users.assert_called_with(user.username) |
Oops, something went wrong.