-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #294 from UW-GAC/feature/update-username-email-on-…
…login Update django username and email to match drupal username and email on login
- Loading branch information
Showing
2 changed files
with
51 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,36 +36,59 @@ def test_drupal_social_login_adapter(self): | |
User = get_user_model() | ||
user = User() | ||
old_name = "Old Name" | ||
old_username = "test" | ||
old_email = "[email protected]" | ||
setattr(user, account_settings.USER_MODEL_USERNAME_FIELD, "test") | ||
setattr(user, "name", "Old Name") | ||
setattr(user, account_settings.USER_MODEL_EMAIL_FIELD, "[email protected]") | ||
|
||
account = SocialAccount( | ||
provider="drupal_oauth_provider", | ||
uid="123", | ||
extra_data=dict(first_name="Old", last_name="Name"), | ||
extra_data=dict( | ||
first_name="Old", | ||
last_name="Name", | ||
email=old_email, | ||
preferred_username=old_username, | ||
), | ||
) | ||
sociallogin = SocialLogin(user=user, account=account) | ||
complete_social_login(request, sociallogin) | ||
|
||
user = User.objects.get(**{account_settings.USER_MODEL_USERNAME_FIELD: "test"}) | ||
assert SocialAccount.objects.filter(user=user, uid=account.uid).exists() is True | ||
assert user.name == old_name | ||
assert user.username == old_username | ||
assert user.email == old_email | ||
|
||
def test_update_user_research_centers(self): | ||
def test_update_user_info(self): | ||
adapter = SocialAccountAdapter() | ||
|
||
User = get_user_model() | ||
user = User() | ||
new_name = "New Name" | ||
new_first_name = "New" | ||
new_last_name = "Name" | ||
new_name = f"{new_first_name} {new_last_name}" | ||
new_email = "[email protected]" | ||
new_username = "newusername" | ||
setattr(user, account_settings.USER_MODEL_USERNAME_FIELD, "test") | ||
setattr(user, "name", "Old Name") | ||
setattr(user, account_settings.USER_MODEL_EMAIL_FIELD, "[email protected]") | ||
|
||
user.save() | ||
|
||
adapter.update_user_name(user, dict(first_name="New", last_name="Name")) | ||
adapter.update_user_info( | ||
user, | ||
dict( | ||
first_name=new_first_name, | ||
last_name=new_last_name, | ||
email=new_email, | ||
preferred_username=new_username, | ||
), | ||
) | ||
assert user.name == new_name | ||
assert user.email == new_email | ||
assert user.username == new_username | ||
|
||
def test_update_user_research_centers_add(self): | ||
adapter = SocialAccountAdapter() | ||
|