-
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.
Update username and email on drupal login
- Loading branch information
Showing
2 changed files
with
57 additions
and
11 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 |
---|---|---|
|
@@ -34,36 +34,61 @@ def test_drupal_social_login_adapter(self): | |
User = get_user_model() | ||
user = User() | ||
old_name = "Old Name" | ||
setattr(user, account_settings.USER_MODEL_USERNAME_FIELD, "test") | ||
setattr(user, "name", "Old Name") | ||
setattr(user, account_settings.USER_MODEL_EMAIL_FIELD, "[email protected]") | ||
old_username = "test" | ||
old_email = "[email protected]" | ||
setattr(user, account_settings.USER_MODEL_USERNAME_FIELD, old_username) | ||
setattr(user, "name", old_name) | ||
setattr(user, account_settings.USER_MODEL_EMAIL_FIELD, old_email) | ||
|
||
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"}) | ||
user = User.objects.get( | ||
**{account_settings.USER_MODEL_USERNAME_FIELD: old_username} | ||
) | ||
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_name(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_study_sites_add(self): | ||
adapter = SocialAccountAdapter() | ||
|