mirror of https://github.com/zulip/zulip.git
mypy: Use Python 3 type syntax in zerver/lib/test_classes.py.
This commit is contained in:
parent
96fa399ce0
commit
21e629f351
|
@ -359,9 +359,8 @@ class ZulipTestCase(TestCase):
|
||||||
)
|
)
|
||||||
return [cast(Text, get_display_recipient(sub.recipient)) for sub in subs]
|
return [cast(Text, get_display_recipient(sub.recipient)) for sub in subs]
|
||||||
|
|
||||||
def send_personal_message(self, from_email, to_email, content="test content",
|
def send_personal_message(self, from_email: Text, to_email: Text, content: Text="test content",
|
||||||
sender_realm="zulip"):
|
sender_realm: Text="zulip") -> int:
|
||||||
# type: (Text, Text, Text, Text) -> int
|
|
||||||
sender = get_user(from_email, get_realm(sender_realm))
|
sender = get_user(from_email, get_realm(sender_realm))
|
||||||
|
|
||||||
recipient_list = [to_email]
|
recipient_list = [to_email]
|
||||||
|
@ -372,9 +371,8 @@ class ZulipTestCase(TestCase):
|
||||||
content
|
content
|
||||||
)
|
)
|
||||||
|
|
||||||
def send_huddle_message(self, from_email, to_emails, content="test content",
|
def send_huddle_message(self, from_email: Text, to_emails: List[Text], content: Text="test content",
|
||||||
sender_realm="zulip"):
|
sender_realm: Text="zulip") -> int:
|
||||||
# type: (Text, List[Text], Text, Text) -> int
|
|
||||||
sender = get_user(from_email, get_realm(sender_realm))
|
sender = get_user(from_email, get_realm(sender_realm))
|
||||||
|
|
||||||
assert(len(to_emails) >= 2)
|
assert(len(to_emails) >= 2)
|
||||||
|
@ -386,9 +384,8 @@ class ZulipTestCase(TestCase):
|
||||||
content
|
content
|
||||||
)
|
)
|
||||||
|
|
||||||
def send_stream_message(self, sender_email, stream_name, content="test content",
|
def send_stream_message(self, sender_email: Text, stream_name: Text, content: Text="test content",
|
||||||
topic_name="test", sender_realm="zulip"):
|
topic_name: Text="test", sender_realm: Text="zulip") -> int:
|
||||||
# type: (Text, Text, Text, Text, Text) -> int
|
|
||||||
sender = get_user(sender_email, get_realm(sender_realm))
|
sender = get_user(sender_email, get_realm(sender_realm))
|
||||||
|
|
||||||
(sending_client, _) = Client.objects.get_or_create(name="test suite")
|
(sending_client, _) = Client.objects.get_or_create(name="test suite")
|
||||||
|
@ -401,9 +398,8 @@ class ZulipTestCase(TestCase):
|
||||||
body=content,
|
body=content,
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_messages(self, anchor=1, num_before=100, num_after=100,
|
def get_messages(self, anchor: int=1, num_before: int=100, num_after: int=100,
|
||||||
use_first_unread_anchor=False):
|
use_first_unread_anchor: bool=False) -> List[Dict[str, Any]]:
|
||||||
# type: (int, int, int, bool) -> List[Dict[str, Any]]
|
|
||||||
post_params = {"anchor": anchor, "num_before": num_before,
|
post_params = {"anchor": anchor, "num_before": num_before,
|
||||||
"num_after": num_after,
|
"num_after": num_after,
|
||||||
"use_first_unread_anchor": ujson.dumps(use_first_unread_anchor)}
|
"use_first_unread_anchor": ujson.dumps(use_first_unread_anchor)}
|
||||||
|
@ -529,9 +525,9 @@ class ZulipTestCase(TestCase):
|
||||||
bulk_remove_subscriptions([user_profile], [stream])
|
bulk_remove_subscriptions([user_profile], [stream])
|
||||||
|
|
||||||
# Subscribe to a stream by making an API request
|
# Subscribe to a stream by making an API request
|
||||||
def common_subscribe_to_streams(self, email, streams, extra_post_data={}, invite_only=False,
|
def common_subscribe_to_streams(self, email: Text, streams: Iterable[Text],
|
||||||
**kwargs):
|
extra_post_data: Dict[str, Any]={}, invite_only: bool=False,
|
||||||
# type: (Text, Iterable[Text], Dict[str, Any], bool, **Any) -> HttpResponse
|
**kwargs: Any) -> HttpResponse:
|
||||||
post_data = {'subscriptions': ujson.dumps([{"name": stream} for stream in streams]),
|
post_data = {'subscriptions': ujson.dumps([{"name": stream} for stream in streams]),
|
||||||
'invite_only': ujson.dumps(invite_only)}
|
'invite_only': ujson.dumps(invite_only)}
|
||||||
post_data.update(extra_post_data)
|
post_data.update(extra_post_data)
|
||||||
|
@ -607,9 +603,9 @@ class WebhookTestCase(ZulipTestCase):
|
||||||
def setUp(self) -> None:
|
def setUp(self) -> None:
|
||||||
self.url = self.build_webhook_url()
|
self.url = self.build_webhook_url()
|
||||||
|
|
||||||
def send_and_test_stream_message(self, fixture_name, expected_subject=None,
|
def send_and_test_stream_message(self, fixture_name: Text, expected_subject: Optional[Text]=None,
|
||||||
expected_message=None, content_type="application/json", **kwargs):
|
expected_message: Optional[Text]=None,
|
||||||
# type: (Text, Optional[Text], Optional[Text], Optional[Text], **Any) -> Message
|
content_type: Optional[Text]="application/json", **kwargs: Any) -> Message:
|
||||||
payload = self.get_body(fixture_name)
|
payload = self.get_body(fixture_name)
|
||||||
if content_type is not None:
|
if content_type is not None:
|
||||||
kwargs['content_type'] = content_type
|
kwargs['content_type'] = content_type
|
||||||
|
@ -620,9 +616,9 @@ class WebhookTestCase(ZulipTestCase):
|
||||||
|
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
def send_and_test_private_message(self, fixture_name, expected_subject=None,
|
def send_and_test_private_message(self, fixture_name: Text, expected_subject: Text=None,
|
||||||
expected_message=None, content_type="application/json", **kwargs):
|
expected_message: Text=None, content_type: str="application/json",
|
||||||
# type: (Text, Text, Text, str, **Any) -> Message
|
**kwargs: Any)-> Message:
|
||||||
payload = self.get_body(fixture_name)
|
payload = self.get_body(fixture_name)
|
||||||
if content_type is not None:
|
if content_type is not None:
|
||||||
kwargs['content_type'] = content_type
|
kwargs['content_type'] = content_type
|
||||||
|
|
Loading…
Reference in New Issue