mirror of
https://github.com/zulip/zulip.git
synced 2025-11-15 11:22:04 +00:00
zerver/tests: Use python 3 syntax for typing (part 4).
This commit is contained in:
@@ -190,8 +190,7 @@ class AuthBackendTest(ZulipTestCase):
|
||||
realm=None,
|
||||
return_data=dict()))
|
||||
|
||||
def test_email_auth_backend_disabled_password_auth(self):
|
||||
# type: () -> None
|
||||
def test_email_auth_backend_disabled_password_auth(self) -> None:
|
||||
user_profile = self.example_user('hamlet')
|
||||
password = "testpassword"
|
||||
user_profile.set_password(password)
|
||||
@@ -711,9 +710,10 @@ class ResponseMock:
|
||||
return "Response text"
|
||||
|
||||
class GoogleOAuthTest(ZulipTestCase):
|
||||
def google_oauth2_test(self, token_response, account_response, *, subdomain=None,
|
||||
mobile_flow_otp=None, is_signup=None):
|
||||
# type: (ResponseMock, ResponseMock, Optional[str], Optional[str], Optional[str]) -> HttpResponse
|
||||
def google_oauth2_test(self, token_response: ResponseMock, account_response: ResponseMock,
|
||||
*, subdomain: Optional[str]=None,
|
||||
mobile_flow_otp: Optional[str]=None,
|
||||
is_signup: Optional[str]=None) -> HttpResponse:
|
||||
url = "/accounts/login/google/"
|
||||
params = {}
|
||||
headers = {}
|
||||
|
||||
@@ -141,9 +141,9 @@ class DecoratorTestCase(TestCase):
|
||||
def test_REQ_converter_and_validator_invalid(self) -> None:
|
||||
with self.assertRaisesRegex(AssertionError, "converter and validator are mutually exclusive"):
|
||||
@has_request_variables
|
||||
def get_total(request, numbers=REQ(validator=check_list(check_int),
|
||||
converter=lambda x: [])):
|
||||
# type: (HttpRequest, Iterable[int]) -> int
|
||||
def get_total(request: HttpRequest,
|
||||
numbers: Iterable[int]=REQ(validator=check_list(check_int),
|
||||
converter=lambda x: [])) -> int:
|
||||
return sum(numbers) # nocoverage -- isn't intended to be run
|
||||
|
||||
def test_REQ_validator(self) -> None:
|
||||
|
||||
@@ -153,11 +153,10 @@ class TestSendWebhookFixtureMessage(TestCase):
|
||||
@patch('zerver.management.commands.send_webhook_fixture_message.ujson')
|
||||
@patch("zerver.management.commands.send_webhook_fixture_message.open", create=True)
|
||||
def test_check_if_command_post_request_to_url_with_fixture(self,
|
||||
open_mock,
|
||||
ujson_mock,
|
||||
client_mock,
|
||||
os_path_exists_mock):
|
||||
# type: (MagicMock, MagicMock, MagicMock, MagicMock) -> None
|
||||
open_mock: MagicMock,
|
||||
ujson_mock: MagicMock,
|
||||
client_mock: MagicMock,
|
||||
os_path_exists_mock: MagicMock) -> None:
|
||||
ujson_mock.loads.return_value = '{}'
|
||||
ujson_mock.dumps.return_value = {}
|
||||
os_path_exists_mock.return_value = True
|
||||
|
||||
@@ -404,9 +404,8 @@ class PersonalMessagesTest(ZulipTestCase):
|
||||
|
||||
class StreamMessagesTest(ZulipTestCase):
|
||||
|
||||
def assert_stream_message(self, stream_name, topic_name="test topic",
|
||||
content="test content"):
|
||||
# type: (Text, Text, Text) -> None
|
||||
def assert_stream_message(self, stream_name: Text, topic_name: Text="test topic",
|
||||
content: Text="test content") -> None:
|
||||
"""
|
||||
Check that messages sent to a stream reach all subscribers to that stream.
|
||||
"""
|
||||
@@ -1679,9 +1678,8 @@ class EditMessageTest(ZulipTestCase):
|
||||
self.assertEqual(message_history[5]['topic'], 'topic 1')
|
||||
|
||||
def test_edit_message_content_limit(self) -> None:
|
||||
def set_message_editing_params(allow_message_editing,
|
||||
message_content_edit_limit_seconds):
|
||||
# type: (bool, int) -> None
|
||||
def set_message_editing_params(allow_message_editing: bool,
|
||||
message_content_edit_limit_seconds: int) -> None:
|
||||
result = self.client_patch("/json/realm", {
|
||||
'allow_message_editing': ujson.dumps(allow_message_editing),
|
||||
'message_content_edit_limit_seconds': message_content_edit_limit_seconds
|
||||
|
||||
@@ -15,9 +15,10 @@ class SubdomainsTest(TestCase):
|
||||
request.attach_mock(mock.Mock(return_value=host), 'get_host')
|
||||
return request
|
||||
|
||||
def test(expected, host, *, plusport=True,
|
||||
external_host='example.org', realm_hosts={}, root_aliases=[]):
|
||||
# type: (str, str, bool, str, Dict[str, str], List[str]) -> None
|
||||
def test(expected: str, host: str, *, plusport: bool=True,
|
||||
external_host: str='example.org',
|
||||
realm_hosts: Dict[str, str]={},
|
||||
root_aliases: List[str]=[]) -> None:
|
||||
with self.settings(EXTERNAL_HOST=external_host,
|
||||
REALM_HOSTS=realm_hosts,
|
||||
ROOT_SUBDOMAIN_ALIASES=root_aliases):
|
||||
|
||||
@@ -449,9 +449,8 @@ class StreamAdminTest(ZulipTestCase):
|
||||
{'description': ujson.dumps('Test description')})
|
||||
self.assert_json_error(result, 'Must be a realm administrator')
|
||||
|
||||
def set_up_stream_for_deletion(self, stream_name, invite_only=False,
|
||||
subscribed=True):
|
||||
# type: (str, bool, bool) -> Stream
|
||||
def set_up_stream_for_deletion(self, stream_name: str, invite_only: bool=False,
|
||||
subscribed: bool=True) -> Stream:
|
||||
"""
|
||||
Create a stream for deletion by an administrator.
|
||||
"""
|
||||
@@ -565,9 +564,9 @@ class StreamAdminTest(ZulipTestCase):
|
||||
"privstream", subscribed=False, invite_only=True)
|
||||
self.delete_stream(priv_stream)
|
||||
|
||||
def attempt_unsubscribe_of_principal(self, query_count, is_admin=False, is_subbed=True,
|
||||
invite_only=False, other_user_subbed=True):
|
||||
# type: (int, bool, bool, bool, bool) -> HttpResponse
|
||||
def attempt_unsubscribe_of_principal(self, query_count: int, is_admin: bool=False,
|
||||
is_subbed: bool=True, invite_only: bool=False,
|
||||
other_user_subbed: bool=True) -> HttpResponse:
|
||||
|
||||
# Set up the main user, who is in most cases an admin.
|
||||
user_profile = self.example_user('hamlet')
|
||||
@@ -1501,10 +1500,13 @@ class SubscriptionAPITest(ZulipTestCase):
|
||||
# also check that this matches the list of your subscriptions
|
||||
self.assertEqual(sorted(list_streams), sorted(self.streams))
|
||||
|
||||
def helper_check_subs_before_and_after_add(self, subscriptions, other_params,
|
||||
subscribed, already_subscribed,
|
||||
email, new_subs, realm, invite_only=False):
|
||||
# type: (List[Text], Dict[str, Any], List[Text], List[Text], Text, List[Text], Realm, bool) -> None
|
||||
def helper_check_subs_before_and_after_add(self, subscriptions: List[Text],
|
||||
other_params: Dict[str, Any],
|
||||
subscribed: List[Text],
|
||||
already_subscribed: List[Text],
|
||||
email: Text, new_subs: List[Text],
|
||||
realm: Realm,
|
||||
invite_only: bool=False) -> None:
|
||||
"""
|
||||
Check result of adding subscriptions.
|
||||
|
||||
@@ -2102,9 +2104,10 @@ class SubscriptionAPITest(ZulipTestCase):
|
||||
self.assert_json_error(result, "User not authorized to execute queries on behalf of '%s'"
|
||||
% (principal,), status_code=403)
|
||||
|
||||
def helper_check_subs_before_and_after_remove(self, subscriptions, json_dict,
|
||||
email, new_subs, realm):
|
||||
# type: (List[Text], Dict[str, Any], Text, List[Text], Realm) -> None
|
||||
def helper_check_subs_before_and_after_remove(self, subscriptions: List[Text],
|
||||
json_dict: Dict[str, Any],
|
||||
email: Text, new_subs: List[Text],
|
||||
realm: Realm) -> None:
|
||||
"""
|
||||
Check result of removing subscriptions.
|
||||
|
||||
|
||||
@@ -19,9 +19,8 @@ from zerver.models import UserProfile, UserGroup, get_realm, Realm, \
|
||||
UserGroupMembership
|
||||
|
||||
class UserGroupTestCase(ZulipTestCase):
|
||||
def create_user_group_for_test(self, group_name,
|
||||
realm=get_realm('zulip')):
|
||||
# type: (Text, Realm) -> UserGroup
|
||||
def create_user_group_for_test(self, group_name: Text,
|
||||
realm: Realm=get_realm('zulip')) -> UserGroup:
|
||||
members = [self.example_user('othello')]
|
||||
return create_user_group(group_name, members, realm)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user