auth: Add email_data option to github_oauth2_test.

Removes email_not_verified option. That option was used to assign
email_data a different set of emails for a test. Instead of that,
this refactor allows to specify the email_data itself in the function
which calls github_oauth2_test. Flags like email_not_verified are
generally used in one test. This is a preparatory refactor for
choose email screen which may have introduced multiple flags otherwise.
This commit is contained in:
Shubham Padia 2018-07-19 03:42:07 +05:30 committed by Tim Abbott
parent 79e590f50f
commit c1d1378125
1 changed files with 9 additions and 9 deletions

View File

@ -431,7 +431,7 @@ class GitHubAuthBackendTest(ZulipTestCase):
*, subdomain: Optional[str]=None, *, subdomain: Optional[str]=None,
mobile_flow_otp: Optional[str]=None, mobile_flow_otp: Optional[str]=None,
is_signup: Optional[str]=None, is_signup: Optional[str]=None,
email_not_verified: bool=False, email_data: Optional[List[Dict[str, Any]]]=None,
next: str='') -> HttpResponse: next: str='') -> HttpResponse:
url = "/accounts/login/social/github" url = "/accounts/login/social/github"
params = {} params = {}
@ -470,13 +470,8 @@ class GitHubAuthBackendTest(ZulipTestCase):
'access_token': 'foobar', 'access_token': 'foobar',
'token_type': 'bearer' 'token_type': 'bearer'
} }
if email_not_verified:
email_data = [ if not email_data:
dict(email=account_data_dict["email"],
verified=False,
primary=True),
]
else:
# Keeping a verified email before the primary email makes sure # Keeping a verified email before the primary email makes sure
# get_verified_emails puts the primary email at the start of the # get_verified_emails puts the primary email at the start of the
# email list returned as social_associate_user_helper assumes the # email list returned as social_associate_user_helper assumes the
@ -560,10 +555,15 @@ class GitHubAuthBackendTest(ZulipTestCase):
def test_github_oauth2_email_not_verified(self) -> None: def test_github_oauth2_email_not_verified(self) -> None:
account_data_dict = dict(email=self.email, name=self.name) account_data_dict = dict(email=self.email, name=self.name)
email_data = [
dict(email=account_data_dict["email"],
verified=False,
primary=True),
]
with mock.patch('logging.warning') as mock_warning: with mock.patch('logging.warning') as mock_warning:
result = self.github_oauth2_test(account_data_dict, result = self.github_oauth2_test(account_data_dict,
subdomain='zulip', subdomain='zulip',
email_not_verified=True) email_data=email_data)
self.assertEqual(result.status_code, 302) self.assertEqual(result.status_code, 302)
self.assertEqual(result.url, "/login/") self.assertEqual(result.url, "/login/")
mock_warning.assert_called_once_with("Social auth (GitHub) failed " mock_warning.assert_called_once_with("Social auth (GitHub) failed "