Skip to content

Commit

Permalink
Get display name from profile
Browse files Browse the repository at this point in the history
Related to #872
  • Loading branch information
say-yawn committed Jun 17, 2021
1 parent 9c50585 commit da393bf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions emails/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ def at_max_free_aliases(self):
def fxa(self):
return self.user.socialaccount_set.filter(provider='fxa').first()

@property
def display_name(self):
# if display name is not set on FxA the
# displayName key will not exist on the extra_data
return self.fxa.extra_data.get('displayName')

@property
def has_unlimited(self):
# FIXME: as we don't have all the tiers defined we are over-defining
Expand Down
20 changes: 20 additions & 0 deletions emails/tests/models_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,26 @@ def test_add_subdomain_to_unlimited_profile_with_badword_subdomain_raises_except
return
self.fail("Should have raised CannotMakeSubdomainException")

def test_display_name_exists(self):
display_name = 'Display Name'
social_account = baker.make(
SocialAccount,
provider='fxa',
extra_data={'displayName': display_name}
)
profile = Profile.objects.get(user=social_account.user)
assert profile.display_name == display_name

def test_display_name_does_not_exist(self):
social_account = baker.make(
SocialAccount,
provider='fxa',
extra_data={}
)
profile = Profile.objects.get(user=social_account.user)
assert profile.display_name == None



class DomainAddressTest(TestCase):
def setUp(self):
Expand Down

0 comments on commit da393bf

Please sign in to comment.