2020-06-11 00:54:34 +02:00
|
|
|
from typing import Any, List, Mapping
|
|
|
|
|
2020-08-07 01:09:47 +02:00
|
|
|
import orjson
|
2016-10-12 20:57:59 +02:00
|
|
|
|
2020-06-11 00:54:34 +02:00
|
|
|
from zerver.lib.test_classes import ZulipTestCase
|
|
|
|
from zerver.lib.test_helpers import queries_captured, tornado_redirected_to_list
|
|
|
|
from zerver.models import Huddle, get_huddle_hash
|
|
|
|
|
2016-10-12 20:57:59 +02:00
|
|
|
|
2020-02-22 13:38:09 +01:00
|
|
|
class TypingValidateOperatorTest(ZulipTestCase):
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_missing_parameter(self) -> None:
|
2016-10-12 20:57:59 +02:00
|
|
|
"""
|
|
|
|
Sending typing notification without op parameter fails
|
|
|
|
"""
|
2020-02-22 13:38:09 +01:00
|
|
|
sender = self.example_user("hamlet")
|
|
|
|
params = dict(
|
2020-08-07 01:09:47 +02:00
|
|
|
to=orjson.dumps([sender.id]).decode(),
|
2020-02-22 13:38:09 +01:00
|
|
|
)
|
2021-02-12 08:20:45 +01:00
|
|
|
result = self.api_post(sender, "/api/v1/typing", params)
|
|
|
|
self.assert_json_error(result, "Missing 'op' argument")
|
2016-10-12 20:57:59 +02:00
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_invalid_parameter(self) -> None:
|
2016-10-12 20:57:59 +02:00
|
|
|
"""
|
|
|
|
Sending typing notification with invalid value for op parameter fails
|
|
|
|
"""
|
2020-02-22 13:38:09 +01:00
|
|
|
sender = self.example_user("hamlet")
|
|
|
|
params = dict(
|
2020-08-07 01:09:47 +02:00
|
|
|
to=orjson.dumps([sender.id]).decode(),
|
2021-02-12 08:20:45 +01:00
|
|
|
op="foo",
|
2020-02-22 13:38:09 +01:00
|
|
|
)
|
2021-02-12 08:20:45 +01:00
|
|
|
result = self.api_post(sender, "/api/v1/typing", params)
|
2021-02-05 19:32:46 +01:00
|
|
|
self.assert_json_error(result, "Invalid op")
|
2016-10-12 20:57:59 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-02-22 13:38:09 +01:00
|
|
|
class TypingValidateUsersTest(ZulipTestCase):
|
|
|
|
def test_empty_array(self) -> None:
|
|
|
|
"""
|
|
|
|
Sending typing notification without recipient fails
|
|
|
|
"""
|
2020-03-10 11:48:26 +01:00
|
|
|
sender = self.example_user("hamlet")
|
2021-02-12 08:20:45 +01:00
|
|
|
result = self.api_post(sender, "/api/v1/typing", {"op": "start", "to": "[]"})
|
|
|
|
self.assert_json_error(result, "Missing parameter: 'to' (recipient)")
|
2020-02-22 13:38:09 +01:00
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_missing_recipient(self) -> None:
|
2016-10-12 20:57:59 +02:00
|
|
|
"""
|
|
|
|
Sending typing notification without recipient fails
|
|
|
|
"""
|
2020-03-10 11:48:26 +01:00
|
|
|
sender = self.example_user("hamlet")
|
2021-02-12 08:20:45 +01:00
|
|
|
result = self.api_post(sender, "/api/v1/typing", {"op": "start"})
|
2020-02-28 18:23:57 +01:00
|
|
|
self.assert_json_error(result, "Missing 'to' argument")
|
2016-10-12 20:57:59 +02:00
|
|
|
|
2020-02-22 13:38:09 +01:00
|
|
|
def test_argument_to_is_not_valid_json(self) -> None:
|
2016-10-12 20:57:59 +02:00
|
|
|
"""
|
|
|
|
Sending typing notification to invalid recipient fails
|
|
|
|
"""
|
2020-03-10 11:48:26 +01:00
|
|
|
sender = self.example_user("hamlet")
|
2021-02-12 08:20:45 +01:00
|
|
|
invalid = "bad email"
|
|
|
|
result = self.api_post(sender, "/api/v1/typing", {"op": "start", "to": invalid})
|
2020-02-28 18:23:57 +01:00
|
|
|
self.assert_json_error(result, 'Argument "to" is not valid JSON.')
|
2016-10-12 20:57:59 +02:00
|
|
|
|
2020-02-22 13:38:09 +01:00
|
|
|
def test_bogus_user_id(self) -> None:
|
2016-10-12 20:57:59 +02:00
|
|
|
"""
|
2020-02-22 13:38:09 +01:00
|
|
|
Sending typing notification to invalid recipient fails
|
2016-10-12 20:57:59 +02:00
|
|
|
"""
|
2020-03-10 11:48:26 +01:00
|
|
|
sender = self.example_user("hamlet")
|
2021-02-12 08:20:45 +01:00
|
|
|
invalid = "[9999999]"
|
|
|
|
result = self.api_post(sender, "/api/v1/typing", {"op": "start", "to": invalid})
|
|
|
|
self.assert_json_error(result, "Invalid user ID 9999999")
|
2016-10-12 20:57:59 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-02-22 13:38:09 +01:00
|
|
|
class TypingHappyPathTest(ZulipTestCase):
|
|
|
|
def test_start_to_single_recipient(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
sender = self.example_user("hamlet")
|
|
|
|
recipient_user = self.example_user("othello")
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_recipients = {sender, recipient_user}
|
|
|
|
expected_recipient_emails = {user.email for user in expected_recipients}
|
|
|
|
expected_recipient_ids = {user.id for user in expected_recipients}
|
2018-08-28 21:48:47 +02:00
|
|
|
|
2020-02-23 17:24:41 +01:00
|
|
|
params = dict(
|
2020-08-07 01:09:47 +02:00
|
|
|
to=orjson.dumps([recipient_user.id]).decode(),
|
2021-02-12 08:20:45 +01:00
|
|
|
op="start",
|
2020-02-23 17:24:41 +01:00
|
|
|
)
|
|
|
|
|
python: Convert assignment type annotations to Python 3.6 style.
This commit was split by tabbott; this piece covers the vast majority
of files in Zulip, but excludes scripts/, tools/, and puppet/ to help
ensure we at least show the right error messages for Xenial systems.
We can likely further refine the remaining pieces with some testing.
Generated by com2ann, with whitespace fixes and various manual fixes
for runtime issues:
- invoiced_through: Optional[LicenseLedger] = models.ForeignKey(
+ invoiced_through: Optional["LicenseLedger"] = models.ForeignKey(
-_apns_client: Optional[APNsClient] = None
+_apns_client: Optional["APNsClient"] = None
- notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- signup_notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ signup_notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- author: Optional[UserProfile] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
+ author: Optional["UserProfile"] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
- bot_owner: Optional[UserProfile] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
+ bot_owner: Optional["UserProfile"] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
- default_sending_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
- default_events_register_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_sending_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_events_register_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
-descriptors_by_handler_id: Dict[int, ClientDescriptor] = {}
+descriptors_by_handler_id: Dict[int, "ClientDescriptor"] = {}
-worker_classes: Dict[str, Type[QueueProcessingWorker]] = {}
-queues: Dict[str, Dict[str, Type[QueueProcessingWorker]]] = {}
+worker_classes: Dict[str, Type["QueueProcessingWorker"]] = {}
+queues: Dict[str, Dict[str, Type["QueueProcessingWorker"]]] = {}
-AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional[LDAPSearch] = None
+AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional["LDAPSearch"] = None
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-22 01:09:50 +02:00
|
|
|
events: List[Mapping[str, Any]] = []
|
2020-02-23 17:24:41 +01:00
|
|
|
with queries_captured() as queries:
|
|
|
|
with tornado_redirected_to_list(events):
|
2021-02-12 08:20:45 +01:00
|
|
|
result = self.api_post(sender, "/api/v1/typing", params)
|
2018-08-28 21:48:47 +02:00
|
|
|
|
|
|
|
self.assert_json_success(result)
|
|
|
|
self.assertEqual(len(events), 1)
|
2020-03-10 11:48:26 +01:00
|
|
|
self.assertEqual(len(queries), 4)
|
2018-08-28 21:48:47 +02:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
event = events[0]["event"]
|
|
|
|
event_recipient_emails = {user["email"] for user in event["recipients"]}
|
|
|
|
event_user_ids = set(events[0]["users"])
|
|
|
|
event_recipient_user_ids = {user["user_id"] for user in event["recipients"]}
|
2018-08-28 21:48:47 +02:00
|
|
|
|
|
|
|
self.assertEqual(expected_recipient_ids, event_recipient_user_ids)
|
|
|
|
self.assertEqual(expected_recipient_ids, event_user_ids)
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assertEqual(event["sender"]["email"], sender.email)
|
2018-08-28 21:48:47 +02:00
|
|
|
self.assertEqual(event_recipient_emails, expected_recipient_emails)
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assertEqual(event["type"], "typing")
|
|
|
|
self.assertEqual(event["op"], "start")
|
2018-08-28 21:48:47 +02:00
|
|
|
|
2020-02-22 13:38:09 +01:00
|
|
|
def test_start_to_multiple_recipients(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
sender = self.example_user("hamlet")
|
|
|
|
recipient_users = [self.example_user("othello"), self.example_user("cordelia")]
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_recipients = set(recipient_users) | {sender}
|
|
|
|
expected_recipient_emails = {user.email for user in expected_recipients}
|
|
|
|
expected_recipient_ids = {user.id for user in expected_recipients}
|
2020-02-23 18:05:29 +01:00
|
|
|
|
|
|
|
huddle_hash = get_huddle_hash(list(expected_recipient_ids))
|
|
|
|
self.assertFalse(Huddle.objects.filter(huddle_hash=huddle_hash).exists())
|
|
|
|
|
python: Convert assignment type annotations to Python 3.6 style.
This commit was split by tabbott; this piece covers the vast majority
of files in Zulip, but excludes scripts/, tools/, and puppet/ to help
ensure we at least show the right error messages for Xenial systems.
We can likely further refine the remaining pieces with some testing.
Generated by com2ann, with whitespace fixes and various manual fixes
for runtime issues:
- invoiced_through: Optional[LicenseLedger] = models.ForeignKey(
+ invoiced_through: Optional["LicenseLedger"] = models.ForeignKey(
-_apns_client: Optional[APNsClient] = None
+_apns_client: Optional["APNsClient"] = None
- notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- signup_notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ signup_notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- author: Optional[UserProfile] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
+ author: Optional["UserProfile"] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
- bot_owner: Optional[UserProfile] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
+ bot_owner: Optional["UserProfile"] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
- default_sending_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
- default_events_register_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_sending_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_events_register_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
-descriptors_by_handler_id: Dict[int, ClientDescriptor] = {}
+descriptors_by_handler_id: Dict[int, "ClientDescriptor"] = {}
-worker_classes: Dict[str, Type[QueueProcessingWorker]] = {}
-queues: Dict[str, Dict[str, Type[QueueProcessingWorker]]] = {}
+worker_classes: Dict[str, Type["QueueProcessingWorker"]] = {}
+queues: Dict[str, Dict[str, Type["QueueProcessingWorker"]]] = {}
-AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional[LDAPSearch] = None
+AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional["LDAPSearch"] = None
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-22 01:09:50 +02:00
|
|
|
events: List[Mapping[str, Any]] = []
|
2020-02-23 17:24:41 +01:00
|
|
|
|
|
|
|
params = dict(
|
2020-08-07 01:09:47 +02:00
|
|
|
to=orjson.dumps([user.id for user in recipient_users]).decode(),
|
2021-02-12 08:20:45 +01:00
|
|
|
op="start",
|
2020-02-23 17:24:41 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
with queries_captured() as queries:
|
|
|
|
with tornado_redirected_to_list(events):
|
2021-02-12 08:20:45 +01:00
|
|
|
result = self.api_post(sender, "/api/v1/typing", params)
|
2018-08-28 21:48:47 +02:00
|
|
|
self.assert_json_success(result)
|
|
|
|
self.assertEqual(len(events), 1)
|
2020-03-10 11:48:26 +01:00
|
|
|
self.assertEqual(len(queries), 5)
|
2018-08-28 21:48:47 +02:00
|
|
|
|
2020-02-23 14:10:26 +01:00
|
|
|
# We should not be adding new Huddles just because
|
|
|
|
# a user started typing in the compose box. Let's
|
|
|
|
# wait till they send an actual message.
|
|
|
|
self.assertFalse(Huddle.objects.filter(huddle_hash=huddle_hash).exists())
|
2020-02-23 18:05:29 +01:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
event = events[0]["event"]
|
|
|
|
event_recipient_emails = {user["email"] for user in event["recipients"]}
|
|
|
|
event_user_ids = set(events[0]["users"])
|
|
|
|
event_recipient_user_ids = {user["user_id"] for user in event["recipients"]}
|
2018-08-28 21:48:47 +02:00
|
|
|
|
|
|
|
self.assertEqual(expected_recipient_ids, event_recipient_user_ids)
|
|
|
|
self.assertEqual(expected_recipient_ids, event_user_ids)
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assertEqual(event["sender"]["email"], sender.email)
|
2018-08-28 21:48:47 +02:00
|
|
|
self.assertEqual(event_recipient_emails, expected_recipient_emails)
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assertEqual(event["type"], "typing")
|
|
|
|
self.assertEqual(event["op"], "start")
|
2018-08-28 21:48:47 +02:00
|
|
|
|
2020-02-22 13:38:09 +01:00
|
|
|
def test_start_to_self(self) -> None:
|
2018-08-28 21:48:47 +02:00
|
|
|
"""
|
|
|
|
Sending typing notification to yourself (using user IDs)
|
|
|
|
is successful.
|
|
|
|
"""
|
2021-02-12 08:20:45 +01:00
|
|
|
user = self.example_user("hamlet")
|
2018-08-28 21:48:47 +02:00
|
|
|
email = user.email
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_recipient_emails = {email}
|
|
|
|
expected_recipient_ids = {user.id}
|
python: Convert assignment type annotations to Python 3.6 style.
This commit was split by tabbott; this piece covers the vast majority
of files in Zulip, but excludes scripts/, tools/, and puppet/ to help
ensure we at least show the right error messages for Xenial systems.
We can likely further refine the remaining pieces with some testing.
Generated by com2ann, with whitespace fixes and various manual fixes
for runtime issues:
- invoiced_through: Optional[LicenseLedger] = models.ForeignKey(
+ invoiced_through: Optional["LicenseLedger"] = models.ForeignKey(
-_apns_client: Optional[APNsClient] = None
+_apns_client: Optional["APNsClient"] = None
- notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- signup_notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ signup_notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- author: Optional[UserProfile] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
+ author: Optional["UserProfile"] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
- bot_owner: Optional[UserProfile] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
+ bot_owner: Optional["UserProfile"] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
- default_sending_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
- default_events_register_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_sending_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_events_register_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
-descriptors_by_handler_id: Dict[int, ClientDescriptor] = {}
+descriptors_by_handler_id: Dict[int, "ClientDescriptor"] = {}
-worker_classes: Dict[str, Type[QueueProcessingWorker]] = {}
-queues: Dict[str, Dict[str, Type[QueueProcessingWorker]]] = {}
+worker_classes: Dict[str, Type["QueueProcessingWorker"]] = {}
+queues: Dict[str, Dict[str, Type["QueueProcessingWorker"]]] = {}
-AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional[LDAPSearch] = None
+AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional["LDAPSearch"] = None
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-22 01:09:50 +02:00
|
|
|
events: List[Mapping[str, Any]] = []
|
2018-08-28 21:48:47 +02:00
|
|
|
with tornado_redirected_to_list(events):
|
|
|
|
result = self.api_post(
|
2020-03-10 11:48:26 +01:00
|
|
|
user,
|
2021-02-12 08:20:45 +01:00
|
|
|
"/api/v1/typing",
|
2018-08-28 21:48:47 +02:00
|
|
|
{
|
2021-02-12 08:20:45 +01:00
|
|
|
"to": orjson.dumps([user.id]).decode(),
|
|
|
|
"op": "start",
|
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
|
|
|
},
|
2018-08-28 21:48:47 +02:00
|
|
|
)
|
|
|
|
self.assert_json_success(result)
|
2016-10-28 18:50:21 +02:00
|
|
|
self.assertEqual(len(events), 1)
|
2016-10-12 20:57:59 +02:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
event = events[0]["event"]
|
|
|
|
event_recipient_emails = {user["email"] for user in event["recipients"]}
|
|
|
|
event_user_ids = set(events[0]["users"])
|
|
|
|
event_recipient_user_ids = {user["user_id"] for user in event["recipients"]}
|
2016-10-12 20:57:59 +02:00
|
|
|
|
2016-10-28 18:50:21 +02:00
|
|
|
self.assertEqual(expected_recipient_ids, event_recipient_user_ids)
|
|
|
|
self.assertEqual(expected_recipient_ids, event_user_ids)
|
|
|
|
self.assertEqual(event_recipient_emails, expected_recipient_emails)
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assertEqual(event["sender"]["email"], email)
|
|
|
|
self.assertEqual(event["type"], "typing")
|
|
|
|
self.assertEqual(event["op"], "start")
|
2016-10-12 20:57:59 +02:00
|
|
|
|
2020-02-22 13:38:09 +01:00
|
|
|
def test_start_to_another_user(self) -> None:
|
2016-10-12 20:57:59 +02:00
|
|
|
"""
|
|
|
|
Sending typing notification to another user
|
|
|
|
is successful.
|
|
|
|
"""
|
2021-02-12 08:20:45 +01:00
|
|
|
sender = self.example_user("hamlet")
|
|
|
|
recipient = self.example_user("othello")
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_recipients = {sender, recipient}
|
|
|
|
expected_recipient_emails = {user.email for user in expected_recipients}
|
|
|
|
expected_recipient_ids = {user.id for user in expected_recipients}
|
2016-10-28 18:50:21 +02:00
|
|
|
|
2020-02-22 13:38:09 +01:00
|
|
|
params = dict(
|
2020-08-07 01:09:47 +02:00
|
|
|
to=orjson.dumps([recipient.id]).decode(),
|
2021-02-12 08:20:45 +01:00
|
|
|
op="start",
|
2020-02-22 13:38:09 +01:00
|
|
|
)
|
|
|
|
|
python: Convert assignment type annotations to Python 3.6 style.
This commit was split by tabbott; this piece covers the vast majority
of files in Zulip, but excludes scripts/, tools/, and puppet/ to help
ensure we at least show the right error messages for Xenial systems.
We can likely further refine the remaining pieces with some testing.
Generated by com2ann, with whitespace fixes and various manual fixes
for runtime issues:
- invoiced_through: Optional[LicenseLedger] = models.ForeignKey(
+ invoiced_through: Optional["LicenseLedger"] = models.ForeignKey(
-_apns_client: Optional[APNsClient] = None
+_apns_client: Optional["APNsClient"] = None
- notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- signup_notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ signup_notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- author: Optional[UserProfile] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
+ author: Optional["UserProfile"] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
- bot_owner: Optional[UserProfile] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
+ bot_owner: Optional["UserProfile"] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
- default_sending_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
- default_events_register_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_sending_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_events_register_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
-descriptors_by_handler_id: Dict[int, ClientDescriptor] = {}
+descriptors_by_handler_id: Dict[int, "ClientDescriptor"] = {}
-worker_classes: Dict[str, Type[QueueProcessingWorker]] = {}
-queues: Dict[str, Dict[str, Type[QueueProcessingWorker]]] = {}
+worker_classes: Dict[str, Type["QueueProcessingWorker"]] = {}
+queues: Dict[str, Dict[str, Type["QueueProcessingWorker"]]] = {}
-AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional[LDAPSearch] = None
+AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional["LDAPSearch"] = None
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-22 01:09:50 +02:00
|
|
|
events: List[Mapping[str, Any]] = []
|
2016-10-12 20:57:59 +02:00
|
|
|
with tornado_redirected_to_list(events):
|
2021-02-12 08:20:45 +01:00
|
|
|
result = self.api_post(sender, "/api/v1/typing", params)
|
2020-02-22 13:38:09 +01:00
|
|
|
|
2016-10-12 20:57:59 +02:00
|
|
|
self.assert_json_success(result)
|
2016-10-28 18:50:21 +02:00
|
|
|
self.assertEqual(len(events), 1)
|
2016-10-12 20:57:59 +02:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
event = events[0]["event"]
|
|
|
|
event_recipient_emails = {user["email"] for user in event["recipients"]}
|
|
|
|
event_user_ids = set(events[0]["users"])
|
|
|
|
event_recipient_user_ids = {user["user_id"] for user in event["recipients"]}
|
2016-10-28 18:50:21 +02:00
|
|
|
|
|
|
|
self.assertEqual(expected_recipient_ids, event_recipient_user_ids)
|
|
|
|
self.assertEqual(expected_recipient_ids, event_user_ids)
|
|
|
|
self.assertEqual(event_recipient_emails, expected_recipient_emails)
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assertEqual(event["sender"]["email"], sender.email)
|
|
|
|
self.assertEqual(event["type"], "typing")
|
|
|
|
self.assertEqual(event["op"], "start")
|
2016-10-12 20:57:59 +02:00
|
|
|
|
2020-02-22 13:38:09 +01:00
|
|
|
def test_stop_to_self(self) -> None:
|
2016-10-12 20:57:59 +02:00
|
|
|
"""
|
|
|
|
Sending stopped typing notification to yourself
|
|
|
|
is successful.
|
|
|
|
"""
|
2021-02-12 08:20:45 +01:00
|
|
|
user = self.example_user("hamlet")
|
2017-05-08 16:23:43 +02:00
|
|
|
email = user.email
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_recipient_emails = {email}
|
|
|
|
expected_recipient_ids = {user.id}
|
2016-10-12 20:57:59 +02:00
|
|
|
|
python: Convert assignment type annotations to Python 3.6 style.
This commit was split by tabbott; this piece covers the vast majority
of files in Zulip, but excludes scripts/, tools/, and puppet/ to help
ensure we at least show the right error messages for Xenial systems.
We can likely further refine the remaining pieces with some testing.
Generated by com2ann, with whitespace fixes and various manual fixes
for runtime issues:
- invoiced_through: Optional[LicenseLedger] = models.ForeignKey(
+ invoiced_through: Optional["LicenseLedger"] = models.ForeignKey(
-_apns_client: Optional[APNsClient] = None
+_apns_client: Optional["APNsClient"] = None
- notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- signup_notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ signup_notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- author: Optional[UserProfile] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
+ author: Optional["UserProfile"] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
- bot_owner: Optional[UserProfile] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
+ bot_owner: Optional["UserProfile"] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
- default_sending_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
- default_events_register_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_sending_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_events_register_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
-descriptors_by_handler_id: Dict[int, ClientDescriptor] = {}
+descriptors_by_handler_id: Dict[int, "ClientDescriptor"] = {}
-worker_classes: Dict[str, Type[QueueProcessingWorker]] = {}
-queues: Dict[str, Dict[str, Type[QueueProcessingWorker]]] = {}
+worker_classes: Dict[str, Type["QueueProcessingWorker"]] = {}
+queues: Dict[str, Dict[str, Type["QueueProcessingWorker"]]] = {}
-AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional[LDAPSearch] = None
+AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional["LDAPSearch"] = None
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-22 01:09:50 +02:00
|
|
|
events: List[Mapping[str, Any]] = []
|
2016-10-12 20:57:59 +02:00
|
|
|
with tornado_redirected_to_list(events):
|
2020-02-22 13:38:09 +01:00
|
|
|
params = dict(
|
2020-08-07 01:09:47 +02:00
|
|
|
to=orjson.dumps([user.id]).decode(),
|
2021-02-12 08:20:45 +01:00
|
|
|
op="stop",
|
2020-02-22 13:38:09 +01:00
|
|
|
)
|
2021-02-12 08:20:45 +01:00
|
|
|
result = self.api_post(user, "/api/v1/typing", params)
|
2020-02-22 13:38:09 +01:00
|
|
|
|
2016-10-12 20:57:59 +02:00
|
|
|
self.assert_json_success(result)
|
2016-10-28 18:50:21 +02:00
|
|
|
self.assertEqual(len(events), 1)
|
2016-10-12 20:57:59 +02:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
event = events[0]["event"]
|
|
|
|
event_recipient_emails = {user["email"] for user in event["recipients"]}
|
|
|
|
event_user_ids = set(events[0]["users"])
|
|
|
|
event_recipient_user_ids = {user["user_id"] for user in event["recipients"]}
|
2016-10-28 18:50:21 +02:00
|
|
|
|
|
|
|
self.assertEqual(expected_recipient_ids, event_recipient_user_ids)
|
|
|
|
self.assertEqual(expected_recipient_ids, event_user_ids)
|
|
|
|
self.assertEqual(event_recipient_emails, expected_recipient_emails)
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assertEqual(event["sender"]["email"], email)
|
|
|
|
self.assertEqual(event["type"], "typing")
|
|
|
|
self.assertEqual(event["op"], "stop")
|
2016-10-12 20:57:59 +02:00
|
|
|
|
2020-02-22 13:38:09 +01:00
|
|
|
def test_stop_to_another_user(self) -> None:
|
2016-10-12 20:57:59 +02:00
|
|
|
"""
|
|
|
|
Sending stopped typing notification to another user
|
|
|
|
is successful.
|
|
|
|
"""
|
2021-02-12 08:20:45 +01:00
|
|
|
sender = self.example_user("hamlet")
|
|
|
|
recipient = self.example_user("othello")
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_recipients = {sender, recipient}
|
|
|
|
expected_recipient_emails = {user.email for user in expected_recipients}
|
|
|
|
expected_recipient_ids = {user.id for user in expected_recipients}
|
2016-10-28 18:50:21 +02:00
|
|
|
|
python: Convert assignment type annotations to Python 3.6 style.
This commit was split by tabbott; this piece covers the vast majority
of files in Zulip, but excludes scripts/, tools/, and puppet/ to help
ensure we at least show the right error messages for Xenial systems.
We can likely further refine the remaining pieces with some testing.
Generated by com2ann, with whitespace fixes and various manual fixes
for runtime issues:
- invoiced_through: Optional[LicenseLedger] = models.ForeignKey(
+ invoiced_through: Optional["LicenseLedger"] = models.ForeignKey(
-_apns_client: Optional[APNsClient] = None
+_apns_client: Optional["APNsClient"] = None
- notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- signup_notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ signup_notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- author: Optional[UserProfile] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
+ author: Optional["UserProfile"] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
- bot_owner: Optional[UserProfile] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
+ bot_owner: Optional["UserProfile"] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
- default_sending_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
- default_events_register_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_sending_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_events_register_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
-descriptors_by_handler_id: Dict[int, ClientDescriptor] = {}
+descriptors_by_handler_id: Dict[int, "ClientDescriptor"] = {}
-worker_classes: Dict[str, Type[QueueProcessingWorker]] = {}
-queues: Dict[str, Dict[str, Type[QueueProcessingWorker]]] = {}
+worker_classes: Dict[str, Type["QueueProcessingWorker"]] = {}
+queues: Dict[str, Dict[str, Type["QueueProcessingWorker"]]] = {}
-AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional[LDAPSearch] = None
+AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional["LDAPSearch"] = None
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-22 01:09:50 +02:00
|
|
|
events: List[Mapping[str, Any]] = []
|
2016-10-12 20:57:59 +02:00
|
|
|
with tornado_redirected_to_list(events):
|
2020-02-22 13:38:09 +01:00
|
|
|
params = dict(
|
2020-08-07 01:09:47 +02:00
|
|
|
to=orjson.dumps([recipient.id]).decode(),
|
2021-02-12 08:20:45 +01:00
|
|
|
op="stop",
|
2020-02-22 13:38:09 +01:00
|
|
|
)
|
2021-02-12 08:20:45 +01:00
|
|
|
result = self.api_post(sender, "/api/v1/typing", params)
|
2020-02-22 13:38:09 +01:00
|
|
|
|
2016-10-12 20:57:59 +02:00
|
|
|
self.assert_json_success(result)
|
2016-10-28 18:50:21 +02:00
|
|
|
self.assertEqual(len(events), 1)
|
2016-10-12 20:57:59 +02:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
event = events[0]["event"]
|
|
|
|
event_recipient_emails = {user["email"] for user in event["recipients"]}
|
|
|
|
event_user_ids = set(events[0]["users"])
|
|
|
|
event_recipient_user_ids = {user["user_id"] for user in event["recipients"]}
|
2016-10-28 18:50:21 +02:00
|
|
|
|
|
|
|
self.assertEqual(expected_recipient_ids, event_recipient_user_ids)
|
|
|
|
self.assertEqual(expected_recipient_ids, event_user_ids)
|
|
|
|
self.assertEqual(event_recipient_emails, expected_recipient_emails)
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assertEqual(event["sender"]["email"], sender.email)
|
|
|
|
self.assertEqual(event["type"], "typing")
|
|
|
|
self.assertEqual(event["op"], "stop")
|