zerver/tests: Use python 3 syntax for typing (part 4).

This commit is contained in:
rht
2017-11-20 02:22:57 +00:00
committed by Tim Abbott
parent 3bf9cd0656
commit 0260ba82ca
7 changed files with 38 additions and 38 deletions

View File

@@ -190,8 +190,7 @@ class AuthBackendTest(ZulipTestCase):
realm=None, realm=None,
return_data=dict())) return_data=dict()))
def test_email_auth_backend_disabled_password_auth(self): def test_email_auth_backend_disabled_password_auth(self) -> None:
# type: () -> None
user_profile = self.example_user('hamlet') user_profile = self.example_user('hamlet')
password = "testpassword" password = "testpassword"
user_profile.set_password(password) user_profile.set_password(password)
@@ -711,9 +710,10 @@ class ResponseMock:
return "Response text" return "Response text"
class GoogleOAuthTest(ZulipTestCase): class GoogleOAuthTest(ZulipTestCase):
def google_oauth2_test(self, token_response, account_response, *, subdomain=None, def google_oauth2_test(self, token_response: ResponseMock, account_response: ResponseMock,
mobile_flow_otp=None, is_signup=None): *, subdomain: Optional[str]=None,
# type: (ResponseMock, ResponseMock, Optional[str], Optional[str], Optional[str]) -> HttpResponse mobile_flow_otp: Optional[str]=None,
is_signup: Optional[str]=None) -> HttpResponse:
url = "/accounts/login/google/" url = "/accounts/login/google/"
params = {} params = {}
headers = {} headers = {}

View File

@@ -141,9 +141,9 @@ class DecoratorTestCase(TestCase):
def test_REQ_converter_and_validator_invalid(self) -> None: def test_REQ_converter_and_validator_invalid(self) -> None:
with self.assertRaisesRegex(AssertionError, "converter and validator are mutually exclusive"): with self.assertRaisesRegex(AssertionError, "converter and validator are mutually exclusive"):
@has_request_variables @has_request_variables
def get_total(request, numbers=REQ(validator=check_list(check_int), def get_total(request: HttpRequest,
converter=lambda x: [])): numbers: Iterable[int]=REQ(validator=check_list(check_int),
# type: (HttpRequest, Iterable[int]) -> int converter=lambda x: [])) -> int:
return sum(numbers) # nocoverage -- isn't intended to be run return sum(numbers) # nocoverage -- isn't intended to be run
def test_REQ_validator(self) -> None: def test_REQ_validator(self) -> None:

View File

@@ -153,11 +153,10 @@ class TestSendWebhookFixtureMessage(TestCase):
@patch('zerver.management.commands.send_webhook_fixture_message.ujson') @patch('zerver.management.commands.send_webhook_fixture_message.ujson')
@patch("zerver.management.commands.send_webhook_fixture_message.open", create=True) @patch("zerver.management.commands.send_webhook_fixture_message.open", create=True)
def test_check_if_command_post_request_to_url_with_fixture(self, def test_check_if_command_post_request_to_url_with_fixture(self,
open_mock, open_mock: MagicMock,
ujson_mock, ujson_mock: MagicMock,
client_mock, client_mock: MagicMock,
os_path_exists_mock): os_path_exists_mock: MagicMock) -> None:
# type: (MagicMock, MagicMock, MagicMock, MagicMock) -> None
ujson_mock.loads.return_value = '{}' ujson_mock.loads.return_value = '{}'
ujson_mock.dumps.return_value = {} ujson_mock.dumps.return_value = {}
os_path_exists_mock.return_value = True os_path_exists_mock.return_value = True

View File

@@ -404,9 +404,8 @@ class PersonalMessagesTest(ZulipTestCase):
class StreamMessagesTest(ZulipTestCase): class StreamMessagesTest(ZulipTestCase):
def assert_stream_message(self, stream_name, topic_name="test topic", def assert_stream_message(self, stream_name: Text, topic_name: Text="test topic",
content="test content"): content: Text="test content") -> None:
# type: (Text, Text, Text) -> None
""" """
Check that messages sent to a stream reach all subscribers to that stream. 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') self.assertEqual(message_history[5]['topic'], 'topic 1')
def test_edit_message_content_limit(self) -> None: def test_edit_message_content_limit(self) -> None:
def set_message_editing_params(allow_message_editing, def set_message_editing_params(allow_message_editing: bool,
message_content_edit_limit_seconds): message_content_edit_limit_seconds: int) -> None:
# type: (bool, int) -> None
result = self.client_patch("/json/realm", { result = self.client_patch("/json/realm", {
'allow_message_editing': ujson.dumps(allow_message_editing), 'allow_message_editing': ujson.dumps(allow_message_editing),
'message_content_edit_limit_seconds': message_content_edit_limit_seconds 'message_content_edit_limit_seconds': message_content_edit_limit_seconds

View File

@@ -15,9 +15,10 @@ class SubdomainsTest(TestCase):
request.attach_mock(mock.Mock(return_value=host), 'get_host') request.attach_mock(mock.Mock(return_value=host), 'get_host')
return request return request
def test(expected, host, *, plusport=True, def test(expected: str, host: str, *, plusport: bool=True,
external_host='example.org', realm_hosts={}, root_aliases=[]): external_host: str='example.org',
# type: (str, str, bool, str, Dict[str, str], List[str]) -> None realm_hosts: Dict[str, str]={},
root_aliases: List[str]=[]) -> None:
with self.settings(EXTERNAL_HOST=external_host, with self.settings(EXTERNAL_HOST=external_host,
REALM_HOSTS=realm_hosts, REALM_HOSTS=realm_hosts,
ROOT_SUBDOMAIN_ALIASES=root_aliases): ROOT_SUBDOMAIN_ALIASES=root_aliases):

View File

@@ -449,9 +449,8 @@ class StreamAdminTest(ZulipTestCase):
{'description': ujson.dumps('Test description')}) {'description': ujson.dumps('Test description')})
self.assert_json_error(result, 'Must be a realm administrator') self.assert_json_error(result, 'Must be a realm administrator')
def set_up_stream_for_deletion(self, stream_name, invite_only=False, def set_up_stream_for_deletion(self, stream_name: str, invite_only: bool=False,
subscribed=True): subscribed: bool=True) -> Stream:
# type: (str, bool, bool) -> Stream
""" """
Create a stream for deletion by an administrator. Create a stream for deletion by an administrator.
""" """
@@ -565,9 +564,9 @@ class StreamAdminTest(ZulipTestCase):
"privstream", subscribed=False, invite_only=True) "privstream", subscribed=False, invite_only=True)
self.delete_stream(priv_stream) self.delete_stream(priv_stream)
def attempt_unsubscribe_of_principal(self, query_count, is_admin=False, is_subbed=True, def attempt_unsubscribe_of_principal(self, query_count: int, is_admin: bool=False,
invite_only=False, other_user_subbed=True): is_subbed: bool=True, invite_only: bool=False,
# type: (int, bool, bool, bool, bool) -> HttpResponse other_user_subbed: bool=True) -> HttpResponse:
# Set up the main user, who is in most cases an admin. # Set up the main user, who is in most cases an admin.
user_profile = self.example_user('hamlet') user_profile = self.example_user('hamlet')
@@ -1501,10 +1500,13 @@ class SubscriptionAPITest(ZulipTestCase):
# also check that this matches the list of your subscriptions # also check that this matches the list of your subscriptions
self.assertEqual(sorted(list_streams), sorted(self.streams)) self.assertEqual(sorted(list_streams), sorted(self.streams))
def helper_check_subs_before_and_after_add(self, subscriptions, other_params, def helper_check_subs_before_and_after_add(self, subscriptions: List[Text],
subscribed, already_subscribed, other_params: Dict[str, Any],
email, new_subs, realm, invite_only=False): subscribed: List[Text],
# type: (List[Text], Dict[str, Any], List[Text], List[Text], Text, List[Text], Realm, bool) -> None already_subscribed: List[Text],
email: Text, new_subs: List[Text],
realm: Realm,
invite_only: bool=False) -> None:
""" """
Check result of adding subscriptions. 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'" self.assert_json_error(result, "User not authorized to execute queries on behalf of '%s'"
% (principal,), status_code=403) % (principal,), status_code=403)
def helper_check_subs_before_and_after_remove(self, subscriptions, json_dict, def helper_check_subs_before_and_after_remove(self, subscriptions: List[Text],
email, new_subs, realm): json_dict: Dict[str, Any],
# type: (List[Text], Dict[str, Any], Text, List[Text], Realm) -> None email: Text, new_subs: List[Text],
realm: Realm) -> None:
""" """
Check result of removing subscriptions. Check result of removing subscriptions.

View File

@@ -19,9 +19,8 @@ from zerver.models import UserProfile, UserGroup, get_realm, Realm, \
UserGroupMembership UserGroupMembership
class UserGroupTestCase(ZulipTestCase): class UserGroupTestCase(ZulipTestCase):
def create_user_group_for_test(self, group_name, def create_user_group_for_test(self, group_name: Text,
realm=get_realm('zulip')): realm: Realm=get_realm('zulip')) -> UserGroup:
# type: (Text, Realm) -> UserGroup
members = [self.example_user('othello')] members = [self.example_user('othello')]
return create_user_group(group_name, members, realm) return create_user_group(group_name, members, realm)