Increase test quality for GitHubAuthBackendTest.

This commit is contained in:
Umair Khan 2016-10-11 18:14:50 +05:00 committed by Tim Abbott
parent 4fcd36b124
commit b886e38a58
1 changed files with 33 additions and 24 deletions

View File

@ -319,33 +319,39 @@ class GitHubAuthBackendTest(ZulipTestCase):
def test_github_backend_do_auth_for_default(self):
# type: () -> None
def authenticate(*args, **kwargs):
# type: (*Any, **Any) -> None
assert isinstance(kwargs['backend'], GithubOAuth2) == True
def do_auth(*args, **kwargs):
# type: (*Any, **Any) -> UserProfile
return self.backend.authenticate(*args, **kwargs)
with mock.patch('social.backends.github.GithubOAuth2.user_data',
return_value=dict()), \
mock.patch('zproject.backends.SocialAuthMixin.process_do_auth'), \
mock.patch('social.strategies.django_strategy.'
'DjangoStrategy.authenticate', side_effect=authenticate):
with mock.patch('social.backends.github.GithubOAuth2.do_auth',
side_effect=do_auth), \
mock.patch('zproject.backends.SocialAuthMixin.process_do_auth') as result:
response=dict(email=self.email, name=self.name)
self.backend.do_auth('fake-access-token', response=response)
kwargs = {'realm_subdomain': 'acme',
'response': response,
'return_data': {}}
result.assert_called_with(self.user_profile, 'fake-access-token', **kwargs)
def test_github_backend_do_auth_for_team(self):
# type: () -> None
def authenticate(*args, **kwargs):
# type: (*Any, **Any) -> None
assert isinstance(kwargs['backend'], GithubTeamOAuth2) == True
def do_auth(*args, **kwargs):
# type: (*Any, **Any) -> UserProfile
return self.backend.authenticate(*args, **kwargs)
with mock.patch('social.backends.github.GithubTeamOAuth2.user_data',
return_value=dict()), \
mock.patch('zproject.backends.SocialAuthMixin.process_do_auth'), \
mock.patch('social.strategies.django_strategy.'
'DjangoStrategy.authenticate', side_effect=authenticate):
with mock.patch('social.backends.github.GithubTeamOAuth2.do_auth',
side_effect=do_auth), \
mock.patch('zproject.backends.SocialAuthMixin.process_do_auth') as result:
response=dict(email=self.email, name=self.name)
with self.settings(SOCIAL_AUTH_GITHUB_TEAM_ID='zulip-webapp'):
self.backend.do_auth('fake-access-token', response=response)
kwargs = {'realm_subdomain': 'acme',
'response': response,
'return_data': {}}
result.assert_called_with(self.user_profile, 'fake-access-token', **kwargs)
def test_github_backend_do_auth_for_team_auth_failed(self):
# type: () -> None
with mock.patch('social.backends.github.GithubTeamOAuth2.do_auth',
@ -362,19 +368,22 @@ class GitHubAuthBackendTest(ZulipTestCase):
def test_github_backend_do_auth_for_org(self):
# type: () -> None
def authenticate(*args, **kwargs):
# type: (*Any, **Any) -> None
assert isinstance(kwargs['backend'], GithubOrganizationOAuth2) == True
def do_auth(*args, **kwargs):
# type: (*Any, **Any) -> UserProfile
return self.backend.authenticate(*args, **kwargs)
with mock.patch('social.backends.github.GithubOrganizationOAuth2.user_data',
return_value=dict()), \
mock.patch('zproject.backends.SocialAuthMixin.process_do_auth'), \
mock.patch('social.strategies.django_strategy.'
'DjangoStrategy.authenticate', side_effect=authenticate):
with mock.patch('social.backends.github.GithubOrganizationOAuth2.do_auth',
side_effect=do_auth), \
mock.patch('zproject.backends.SocialAuthMixin.process_do_auth') as result:
response=dict(email=self.email, name=self.name)
with self.settings(SOCIAL_AUTH_GITHUB_ORG_NAME='Zulip'):
self.backend.do_auth('fake-access-token', response=response)
kwargs = {'realm_subdomain': 'acme',
'response': response,
'return_data': {}}
result.assert_called_with(self.user_profile, 'fake-access-token', **kwargs)
def test_github_backend_do_auth_for_org_auth_failed(self):
# type: () -> None
with mock.patch('social.backends.github.GithubOrganizationOAuth2.do_auth',