mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
test_auth_backends: Add missing type annotations.
This commit is contained in:
@@ -14,7 +14,7 @@ from zerver.lib.test_helpers import (
|
|||||||
AuthedTestCase
|
AuthedTestCase
|
||||||
)
|
)
|
||||||
from zerver.models import \
|
from zerver.models import \
|
||||||
get_realm, get_user_profile_by_email, email_to_username
|
get_realm, get_user_profile_by_email, email_to_username, UserProfile
|
||||||
|
|
||||||
from zproject.backends import ZulipDummyBackend, EmailAuthBackend, \
|
from zproject.backends import ZulipDummyBackend, EmailAuthBackend, \
|
||||||
GoogleMobileOauth2Backend, ZulipRemoteUserBackend, ZulipLDAPAuthBackend, \
|
GoogleMobileOauth2Backend, ZulipRemoteUserBackend, ZulipLDAPAuthBackend, \
|
||||||
@@ -159,6 +159,7 @@ class AuthBackendTest(TestCase):
|
|||||||
email_to_username=email_to_username)
|
email_to_username=email_to_username)
|
||||||
|
|
||||||
def test_github_backend(self):
|
def test_github_backend(self):
|
||||||
|
# type: () -> None
|
||||||
email = 'hamlet@zulip.com'
|
email = 'hamlet@zulip.com'
|
||||||
good_kwargs = dict(response=dict(email=email), return_data=dict())
|
good_kwargs = dict(response=dict(email=email), return_data=dict())
|
||||||
bad_kwargs = dict() # type: Dict[str, str]
|
bad_kwargs = dict() # type: Dict[str, str]
|
||||||
@@ -168,6 +169,7 @@ class AuthBackendTest(TestCase):
|
|||||||
|
|
||||||
class GitHubAuthBackendTest(AuthedTestCase):
|
class GitHubAuthBackendTest(AuthedTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
# type: () -> None
|
||||||
self.email = 'hamlet@zulip.com'
|
self.email = 'hamlet@zulip.com'
|
||||||
self.name = 'Hamlet'
|
self.name = 'Hamlet'
|
||||||
self.backend = GitHubAuthBackend()
|
self.backend = GitHubAuthBackend()
|
||||||
@@ -176,7 +178,9 @@ class GitHubAuthBackendTest(AuthedTestCase):
|
|||||||
self.user_profile.backend = self.backend
|
self.user_profile.backend = self.backend
|
||||||
|
|
||||||
def test_github_backend_do_auth(self):
|
def test_github_backend_do_auth(self):
|
||||||
|
# type: () -> None
|
||||||
def do_auth(*args, **kwargs):
|
def do_auth(*args, **kwargs):
|
||||||
|
# type: (*Any, **Any) -> UserProfile
|
||||||
return self.user_profile
|
return self.user_profile
|
||||||
|
|
||||||
with mock.patch('zerver.views.login_or_register_remote_user') as result, \
|
with mock.patch('zerver.views.login_or_register_remote_user') as result, \
|
||||||
@@ -226,7 +230,9 @@ class GitHubAuthBackendTest(AuthedTestCase):
|
|||||||
self.backend.do_auth('fake-access-token', response=response)
|
self.backend.do_auth('fake-access-token', response=response)
|
||||||
|
|
||||||
def test_github_backend_inactive_user(self):
|
def test_github_backend_inactive_user(self):
|
||||||
|
# type: () -> None
|
||||||
def do_auth_inactive(*args, **kwargs):
|
def do_auth_inactive(*args, **kwargs):
|
||||||
|
# type: (*Any, **Any) -> UserProfile
|
||||||
return_data = kwargs['return_data']
|
return_data = kwargs['return_data']
|
||||||
return_data['inactive_user'] = True
|
return_data['inactive_user'] = True
|
||||||
return self.user_profile
|
return self.user_profile
|
||||||
@@ -240,6 +246,7 @@ class GitHubAuthBackendTest(AuthedTestCase):
|
|||||||
self.assertIs(user, None)
|
self.assertIs(user, None)
|
||||||
|
|
||||||
def test_github_backend_new_user(self):
|
def test_github_backend_new_user(self):
|
||||||
|
# type: () -> None
|
||||||
rf = RequestFactory()
|
rf = RequestFactory()
|
||||||
request = rf.get('/complete')
|
request = rf.get('/complete')
|
||||||
request.session = {}
|
request.session = {}
|
||||||
@@ -247,6 +254,7 @@ class GitHubAuthBackendTest(AuthedTestCase):
|
|||||||
self.backend.strategy.request = request
|
self.backend.strategy.request = request
|
||||||
|
|
||||||
def do_auth(*args, **kwargs):
|
def do_auth(*args, **kwargs):
|
||||||
|
# type: (*Any, **Any) -> UserProfile
|
||||||
return_data = kwargs['return_data']
|
return_data = kwargs['return_data']
|
||||||
return_data['valid_attestation'] = True
|
return_data['valid_attestation'] = True
|
||||||
return None
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user