Skip to content

Commit

Permalink
tests(socialaccount): Query email
Browse files Browse the repository at this point in the history
  • Loading branch information
pennersr committed Nov 3, 2023
1 parent d04aeb8 commit 6444a8c
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 12 deletions.
3 changes: 3 additions & 0 deletions allauth/socialaccount/providers/authentiq/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ def get_mocked_response(self):
),
)

@override_settings(
SOCIALACCOUNT_QUERY_EMAIL=False,
)
def test_default_scopes_no_email(self):
scopes = self.provider.get_default_scope()
self.assertIn("aq:name", scopes)
Expand Down
48 changes: 41 additions & 7 deletions allauth/socialaccount/providers/github/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ class GitHubTests(OAuth2TestsMixin, TestCase):
provider_id = GitHubProvider.id

def get_mocked_response(self):
return MockedResponse(
200,
"""
return [
MockedResponse(
200,
"""
{
"type":"User",
"organizations_url":"https://api.github.com/users/pennersr/orgs",
Expand Down Expand Up @@ -42,19 +43,52 @@ def get_mocked_response(self):
"events_url":"https://api.github.com/users/pennersr/events{/privacy}",
"following_url":"https://api.github.com/users/pennersr/following"
}""",
)
),
MockedResponse(
200,
"""
{
"email": "[email protected]",
"verified": true,
"primary": true,
"visibility": "public"
}
""",
),
]

def test_account_name_null(self):
"""String conversion when GitHub responds with empty name"""
data = """{
mocks = [
MockedResponse(
200,
"""
{
"type": "User",
"id": 201022,
"login": "pennersr",
"name": null
}"""
self.login(MockedResponse(200, data))
}
""",
),
MockedResponse(
200,
"""
[
{
"email": "[email protected]",
"verified": true,
"primary": true,
"visibility": "public"
}
]
""",
),
]
self.login(mocks)
socialaccount = SocialAccount.objects.get(uid="201022")
self.assertIsNone(socialaccount.extra_data.get("name"))
account = socialaccount.get_provider_account()
self.assertIsNotNone(account.to_str())
self.assertEqual(account.to_str(), "pennersr")
self.assertEqual(socialaccount.user.email, "[email protected]")
16 changes: 12 additions & 4 deletions allauth/socialaccount/providers/linkedin_oauth2/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ class LinkedInOAuth2Tests(OAuth2TestsMixin, TestCase):
provider_id = LinkedInOAuth2Provider.id

def get_mocked_response(self):
return MockedResponse(
200,
"""
return [
MockedResponse(
200,
"""
{}
""",
),
MockedResponse(
200,
"""
{
"profilePicture": {
"displayImage": "urn:li:digitalmediaAsset:12345abcdefgh-12abcd"
Expand All @@ -43,7 +50,8 @@ def get_mocked_response(self):
}
}
""",
)
),
]

def test_data_to_str(self):
data = {
Expand Down
4 changes: 4 additions & 0 deletions allauth/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def json(self):
def raise_for_status(self):
pass

@property
def ok(self):
return self.status_code // 100 == 2

@property
def text(self):
return self.content.decode("utf8")
Expand Down
2 changes: 1 addition & 1 deletion test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class MyPBKDF2PasswordHasher(PBKDF2PasswordHasher):
ACCOUNT_EMAIL_CONFIRMATION_COOLDOWN = 0
ACCOUNT_RATE_LIMITS = {}


SOCIALACCOUNT_QUERY_EMAIL = True
SOCIALACCOUNT_PROVIDERS = {
"openid_connect": {
"APPS": [
Expand Down

0 comments on commit 6444a8c

Please sign in to comment.