2018-05-10 19:00:29 +02:00
|
|
|
from typing import Any, Dict, List, Mapping
|
2017-10-08 15:42:41 +02:00
|
|
|
from unittest import mock
|
2016-11-03 18:49:00 +01:00
|
|
|
|
2020-06-11 00:54:34 +02:00
|
|
|
import ujson
|
|
|
|
from django.http import HttpResponse
|
|
|
|
|
|
|
|
from zerver.lib.cache import cache_get, to_dict_cache_key_id
|
2017-05-01 07:29:56 +02:00
|
|
|
from zerver.lib.emoji import emoji_name_to_emoji_code
|
2020-05-23 12:58:18 +02:00
|
|
|
from zerver.lib.message import extract_message_dict
|
2017-05-01 07:29:56 +02:00
|
|
|
from zerver.lib.request import JsonableError
|
2016-11-03 18:49:00 +01:00
|
|
|
from zerver.lib.test_classes import ZulipTestCase
|
2020-07-16 17:06:39 +02:00
|
|
|
from zerver.lib.test_helpers import tornado_redirected_to_list, zulip_reaction_info
|
2020-06-11 00:54:34 +02:00
|
|
|
from zerver.models import Message, Reaction, RealmEmoji, UserMessage, get_realm
|
|
|
|
|
2016-11-03 18:49:00 +01:00
|
|
|
|
|
|
|
class ReactionEmojiTest(ZulipTestCase):
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_missing_emoji(self) -> None:
|
2016-11-03 18:49:00 +01:00
|
|
|
"""
|
|
|
|
Sending reaction without emoji fails
|
|
|
|
"""
|
2020-03-10 11:48:26 +01:00
|
|
|
sender = self.example_user("hamlet")
|
2019-10-10 19:03:09 +02:00
|
|
|
reaction_info = {
|
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
|
|
|
'emoji_name': '',
|
2019-10-10 19:03:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
result = self.api_post(sender, '/api/v1/messages/1/reactions',
|
|
|
|
reaction_info)
|
2017-01-17 08:54:50 +01:00
|
|
|
self.assertEqual(result.status_code, 400)
|
2016-11-03 18:49:00 +01:00
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_add_invalid_emoji(self) -> None:
|
2016-11-03 18:49:00 +01:00
|
|
|
"""
|
2016-12-04 10:50:32 +01:00
|
|
|
Sending invalid emoji fails
|
2016-11-03 18:49:00 +01:00
|
|
|
"""
|
2020-03-10 11:48:26 +01:00
|
|
|
sender = self.example_user("hamlet")
|
2019-10-10 19:03:09 +02:00
|
|
|
reaction_info = {
|
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
|
|
|
'emoji_name': 'foo',
|
2019-10-10 19:03:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
result = self.api_post(sender, '/api/v1/messages/1/reactions',
|
|
|
|
reaction_info)
|
2016-12-04 10:50:32 +01:00
|
|
|
self.assert_json_error(result, "Emoji 'foo' does not exist")
|
2016-11-03 18:49:00 +01:00
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_add_deactivated_realm_emoji(self) -> None:
|
2017-05-23 08:41:30 +02:00
|
|
|
"""
|
|
|
|
Sending deactivated realm emoji fails.
|
|
|
|
"""
|
2017-07-22 21:05:13 +02:00
|
|
|
emoji = RealmEmoji.objects.get(name="green_tick")
|
2017-05-23 08:41:30 +02:00
|
|
|
emoji.deactivated = True
|
|
|
|
emoji.save(update_fields=['deactivated'])
|
2020-03-10 11:48:26 +01:00
|
|
|
sender = self.example_user("hamlet")
|
2019-10-10 19:03:09 +02:00
|
|
|
reaction_info = {
|
|
|
|
'emoji_name': 'green_tick',
|
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
|
|
|
'reaction_type': 'realm_emoji',
|
2019-10-10 19:03:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
result = self.api_post(sender, '/api/v1/messages/1/reactions',
|
|
|
|
reaction_info)
|
2017-07-22 21:05:13 +02:00
|
|
|
self.assert_json_error(result, "Emoji 'green_tick' does not exist")
|
2017-05-23 08:41:30 +02:00
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_valid_emoji(self) -> None:
|
2016-11-03 18:49:00 +01:00
|
|
|
"""
|
|
|
|
Reacting with valid emoji succeeds
|
|
|
|
"""
|
2020-03-10 11:48:26 +01:00
|
|
|
sender = self.example_user("hamlet")
|
2019-10-10 19:03:09 +02:00
|
|
|
reaction_info = {
|
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
|
|
|
'emoji_name': 'smile',
|
2019-10-10 19:03:09 +02:00
|
|
|
}
|
|
|
|
|
2020-03-22 17:44:27 +01:00
|
|
|
base_query = Reaction.objects.filter(user_profile=sender,
|
|
|
|
message=Message.objects.get(id=1),
|
|
|
|
)
|
2019-10-10 19:03:09 +02:00
|
|
|
result = self.api_post(sender, '/api/v1/messages/1/reactions',
|
|
|
|
reaction_info)
|
2016-11-03 18:49:00 +01:00
|
|
|
self.assert_json_success(result)
|
|
|
|
self.assertEqual(200, result.status_code)
|
2020-03-22 17:44:27 +01:00
|
|
|
self.assertTrue(base_query.filter(emoji_name=reaction_info['emoji_name']).exists())
|
|
|
|
|
|
|
|
reaction_info['emoji_name'] = 'green_tick'
|
|
|
|
result = self.api_post(sender, '/api/v1/messages/1/reactions',
|
|
|
|
reaction_info)
|
|
|
|
self.assert_json_success(result)
|
|
|
|
self.assertEqual(200, result.status_code)
|
|
|
|
self.assertTrue(base_query.filter(emoji_name=reaction_info['emoji_name']).exists())
|
2016-11-03 18:49:00 +01:00
|
|
|
|
2020-05-23 12:58:18 +02:00
|
|
|
def test_cached_reaction_data(self) -> None:
|
|
|
|
"""
|
|
|
|
Formatted reactions data is saved in cache.
|
|
|
|
"""
|
|
|
|
sender = self.example_user("hamlet")
|
|
|
|
reaction_info = {
|
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
|
|
|
'emoji_name': 'smile',
|
2020-05-23 12:58:18 +02:00
|
|
|
}
|
|
|
|
result = self.api_post(sender, '/api/v1/messages/1/reactions',
|
|
|
|
reaction_info)
|
|
|
|
|
|
|
|
self.assert_json_success(result)
|
|
|
|
self.assertEqual(200, result.status_code)
|
|
|
|
key = to_dict_cache_key_id(1)
|
|
|
|
message = extract_message_dict(cache_get(key)[0])
|
|
|
|
|
|
|
|
expected_reaction_data = [{
|
|
|
|
'emoji_name': 'smile',
|
2020-06-30 21:16:29 +02:00
|
|
|
'emoji_code': '1f642',
|
2020-05-23 12:58:18 +02:00
|
|
|
'reaction_type': 'unicode_emoji',
|
|
|
|
'user': {
|
|
|
|
'email': 'user10@zulip.testserver',
|
|
|
|
'id': 10,
|
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
|
|
|
'full_name': 'King Hamlet',
|
2020-05-23 12:58:18 +02:00
|
|
|
},
|
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
|
|
|
'user_id': 10,
|
2020-05-23 12:58:18 +02:00
|
|
|
}]
|
|
|
|
self.assertEqual(expected_reaction_data, message['reactions'])
|
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_zulip_emoji(self) -> None:
|
2017-05-01 05:16:39 +02:00
|
|
|
"""
|
|
|
|
Reacting with zulip emoji succeeds
|
|
|
|
"""
|
2020-03-10 11:48:26 +01:00
|
|
|
sender = self.example_user("hamlet")
|
2019-10-10 19:03:09 +02:00
|
|
|
reaction_info = {
|
|
|
|
'emoji_name': 'zulip',
|
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
|
|
|
'reaction_type': 'zulip_extra_emoji',
|
2019-10-10 19:03:09 +02:00
|
|
|
}
|
2020-03-22 17:44:27 +01:00
|
|
|
base_query = Reaction.objects.filter(user_profile=sender,
|
|
|
|
emoji_name=reaction_info['emoji_name'])
|
2019-10-10 19:03:09 +02:00
|
|
|
|
|
|
|
result = self.api_post(sender, '/api/v1/messages/1/reactions',
|
|
|
|
reaction_info)
|
2017-05-01 05:16:39 +02:00
|
|
|
self.assert_json_success(result)
|
|
|
|
self.assertEqual(200, result.status_code)
|
2020-03-22 17:44:27 +01:00
|
|
|
self.assertTrue(base_query.filter(message=Message.objects.get(id=1)).exists())
|
|
|
|
|
|
|
|
reaction_info.pop('reaction_type')
|
|
|
|
result = self.api_post(sender, '/api/v1/messages/2/reactions',
|
|
|
|
reaction_info)
|
|
|
|
self.assert_json_success(result)
|
|
|
|
self.assertEqual(200, result.status_code)
|
|
|
|
self.assertTrue(base_query.filter(message=Message.objects.get(id=2)).exists())
|
2017-05-01 05:16:39 +02:00
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_valid_emoji_react_historical(self) -> None:
|
2017-03-23 04:15:32 +01:00
|
|
|
"""
|
|
|
|
Reacting with valid emoji on a historical message succeeds
|
|
|
|
"""
|
|
|
|
stream_name = "Saxony"
|
2017-08-25 06:01:29 +02:00
|
|
|
self.subscribe(self.example_user("cordelia"), stream_name)
|
2020-03-07 11:43:05 +01:00
|
|
|
message_id = self.send_stream_message(self.example_user("cordelia"), stream_name)
|
2017-03-23 04:15:32 +01:00
|
|
|
|
2017-05-07 21:25:59 +02:00
|
|
|
user_profile = self.example_user('hamlet')
|
2020-03-10 11:48:26 +01:00
|
|
|
sender = user_profile
|
2017-03-23 04:15:32 +01:00
|
|
|
|
|
|
|
# Verify that hamlet did not receive the message.
|
|
|
|
self.assertFalse(UserMessage.objects.filter(user_profile=user_profile,
|
|
|
|
message_id=message_id).exists())
|
|
|
|
|
|
|
|
# Have hamlet react to the message
|
2019-10-10 19:03:09 +02:00
|
|
|
reaction_info = {
|
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
|
|
|
'emoji_name': 'smile',
|
2019-10-10 19:03:09 +02:00
|
|
|
}
|
|
|
|
|
2020-06-10 06:41:04 +02:00
|
|
|
result = self.api_post(sender, f'/api/v1/messages/{message_id}/reactions',
|
2019-10-10 19:03:09 +02:00
|
|
|
reaction_info)
|
2017-03-23 04:15:32 +01:00
|
|
|
self.assert_json_success(result)
|
|
|
|
|
|
|
|
# Fetch the now-created UserMessage object to confirm it exists and is historical
|
|
|
|
user_message = UserMessage.objects.get(user_profile=user_profile, message_id=message_id)
|
|
|
|
self.assertTrue(user_message.flags.historical)
|
|
|
|
self.assertTrue(user_message.flags.read)
|
|
|
|
self.assertFalse(user_message.flags.starred)
|
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_valid_realm_emoji(self) -> None:
|
2016-11-03 18:49:00 +01:00
|
|
|
"""
|
|
|
|
Reacting with valid realm emoji succeeds
|
|
|
|
"""
|
2020-03-10 11:48:26 +01:00
|
|
|
sender = self.example_user("hamlet")
|
2016-11-03 18:49:00 +01:00
|
|
|
|
2019-10-10 19:03:09 +02:00
|
|
|
reaction_info = {
|
|
|
|
'emoji_name': 'green_tick',
|
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
|
|
|
'reaction_type': 'realm_emoji',
|
2019-10-10 19:03:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
result = self.api_post(sender, '/api/v1/messages/1/reactions',
|
|
|
|
reaction_info)
|
2016-11-03 18:49:00 +01:00
|
|
|
self.assert_json_success(result)
|
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_emoji_name_to_emoji_code(self) -> None:
|
2017-05-01 07:29:56 +02:00
|
|
|
"""
|
|
|
|
An emoji name is mapped canonically to emoji code.
|
|
|
|
"""
|
|
|
|
realm = get_realm('zulip')
|
2017-12-15 16:54:07 +01:00
|
|
|
realm_emoji = RealmEmoji.objects.get(name="green_tick")
|
2017-05-01 07:29:56 +02:00
|
|
|
|
|
|
|
# Test active realm emoji.
|
|
|
|
emoji_code, reaction_type = emoji_name_to_emoji_code(realm, 'green_tick')
|
2017-12-15 16:54:07 +01:00
|
|
|
self.assertEqual(emoji_code, str(realm_emoji.id))
|
2017-05-01 07:29:56 +02:00
|
|
|
self.assertEqual(reaction_type, 'realm_emoji')
|
|
|
|
|
|
|
|
# Test deactivated realm emoji.
|
2017-12-15 16:54:07 +01:00
|
|
|
realm_emoji.deactivated = True
|
|
|
|
realm_emoji.save(update_fields=['deactivated'])
|
2017-05-01 07:29:56 +02:00
|
|
|
with self.assertRaises(JsonableError) as exc:
|
|
|
|
emoji_name_to_emoji_code(realm, 'green_tick')
|
|
|
|
self.assertEqual(str(exc.exception), "Emoji 'green_tick' does not exist")
|
|
|
|
|
|
|
|
# Test ':zulip:' emoji.
|
|
|
|
emoji_code, reaction_type = emoji_name_to_emoji_code(realm, 'zulip')
|
|
|
|
self.assertEqual(emoji_code, 'zulip')
|
|
|
|
self.assertEqual(reaction_type, 'zulip_extra_emoji')
|
|
|
|
|
|
|
|
# Test unicode emoji.
|
|
|
|
emoji_code, reaction_type = emoji_name_to_emoji_code(realm, 'astonished')
|
|
|
|
self.assertEqual(emoji_code, '1f632')
|
|
|
|
self.assertEqual(reaction_type, 'unicode_emoji')
|
|
|
|
|
|
|
|
# Test override unicode emoji.
|
|
|
|
overriding_emoji = RealmEmoji.objects.create(
|
|
|
|
name='astonished', realm=realm, file_name='astonished')
|
|
|
|
emoji_code, reaction_type = emoji_name_to_emoji_code(realm, 'astonished')
|
2017-12-15 16:54:07 +01:00
|
|
|
self.assertEqual(emoji_code, str(overriding_emoji.id))
|
2017-05-01 07:29:56 +02:00
|
|
|
self.assertEqual(reaction_type, 'realm_emoji')
|
|
|
|
|
|
|
|
# Test deactivate over-ridding realm emoji.
|
|
|
|
overriding_emoji.deactivated = True
|
|
|
|
overriding_emoji.save(update_fields=['deactivated'])
|
|
|
|
emoji_code, reaction_type = emoji_name_to_emoji_code(realm, 'astonished')
|
|
|
|
self.assertEqual(emoji_code, '1f632')
|
|
|
|
self.assertEqual(reaction_type, 'unicode_emoji')
|
|
|
|
|
|
|
|
# Test override `:zulip:` emoji.
|
|
|
|
overriding_emoji = RealmEmoji.objects.create(
|
|
|
|
name='zulip', realm=realm, file_name='zulip')
|
|
|
|
emoji_code, reaction_type = emoji_name_to_emoji_code(realm, 'zulip')
|
2017-12-15 16:54:07 +01:00
|
|
|
self.assertEqual(emoji_code, str(overriding_emoji.id))
|
2017-05-01 07:29:56 +02:00
|
|
|
self.assertEqual(reaction_type, 'realm_emoji')
|
|
|
|
|
|
|
|
# Test non-existent emoji.
|
|
|
|
with self.assertRaises(JsonableError) as exc:
|
|
|
|
emoji_name_to_emoji_code(realm, 'invalid_emoji')
|
|
|
|
self.assertEqual(str(exc.exception), "Emoji 'invalid_emoji' does not exist")
|
|
|
|
|
2016-11-03 18:49:00 +01:00
|
|
|
class ReactionMessageIDTest(ZulipTestCase):
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_missing_message_id(self) -> None:
|
2016-11-03 18:49:00 +01:00
|
|
|
"""
|
|
|
|
Reacting without a message_id fails
|
|
|
|
"""
|
2020-03-10 11:48:26 +01:00
|
|
|
sender = self.example_user("hamlet")
|
2019-10-10 19:03:09 +02:00
|
|
|
reaction_info = {
|
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
|
|
|
'emoji_name': 'smile',
|
2019-10-10 19:03:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
result = self.api_post(sender, '/api/v1/messages//reactions',
|
|
|
|
reaction_info)
|
2016-12-16 02:01:34 +01:00
|
|
|
self.assertEqual(result.status_code, 404)
|
2016-11-03 18:49:00 +01:00
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_invalid_message_id(self) -> None:
|
2016-11-03 18:49:00 +01:00
|
|
|
"""
|
|
|
|
Reacting to an invalid message id fails
|
|
|
|
"""
|
2020-03-10 11:48:26 +01:00
|
|
|
sender = self.example_user("hamlet")
|
2019-10-10 19:03:09 +02:00
|
|
|
reaction_info = {
|
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
|
|
|
'emoji_name': 'smile',
|
2019-10-10 19:03:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
result = self.api_post(sender, '/api/v1/messages/-1/reactions',
|
|
|
|
reaction_info)
|
2016-12-16 02:01:34 +01:00
|
|
|
self.assertEqual(result.status_code, 404)
|
2016-11-03 18:49:00 +01:00
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_inaccessible_message_id(self) -> None:
|
2016-11-03 18:49:00 +01:00
|
|
|
"""
|
|
|
|
Reacting to a inaccessible (for instance, private) message fails
|
|
|
|
"""
|
2020-03-10 11:48:26 +01:00
|
|
|
pm_sender = self.example_user("hamlet")
|
2020-03-12 14:17:25 +01:00
|
|
|
pm_recipient = self.example_user("othello")
|
2020-03-10 11:48:26 +01:00
|
|
|
reaction_sender = self.example_user("iago")
|
2016-11-03 18:49:00 +01:00
|
|
|
|
2017-12-14 19:02:31 +01:00
|
|
|
result = self.api_post(pm_sender,
|
|
|
|
"/api/v1/messages", {"type": "private",
|
|
|
|
"content": "Test message",
|
2020-03-12 14:17:25 +01:00
|
|
|
"to": pm_recipient.email})
|
2016-11-03 18:49:00 +01:00
|
|
|
self.assert_json_success(result)
|
2017-08-16 09:51:15 +02:00
|
|
|
pm_id = result.json()['id']
|
2019-10-10 19:03:09 +02:00
|
|
|
reaction_info = {
|
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
|
|
|
'emoji_name': 'smile',
|
2019-10-10 19:03:09 +02:00
|
|
|
}
|
|
|
|
|
2020-06-10 06:41:04 +02:00
|
|
|
result = self.api_post(reaction_sender, f'/api/v1/messages/{pm_id}/reactions',
|
2019-10-10 19:03:09 +02:00
|
|
|
reaction_info)
|
2016-11-03 18:49:00 +01:00
|
|
|
self.assert_json_error(result, "Invalid message(s)")
|
|
|
|
|
|
|
|
class ReactionTest(ZulipTestCase):
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_add_existing_reaction(self) -> None:
|
2016-11-03 18:49:00 +01:00
|
|
|
"""
|
|
|
|
Creating the same reaction twice fails
|
|
|
|
"""
|
2020-03-10 11:48:26 +01:00
|
|
|
pm_sender = self.example_user("hamlet")
|
|
|
|
pm_recipient = self.example_user("othello")
|
2016-11-03 18:49:00 +01:00
|
|
|
reaction_sender = pm_recipient
|
|
|
|
|
2017-12-14 19:02:31 +01:00
|
|
|
pm = self.api_post(pm_sender,
|
|
|
|
"/api/v1/messages", {"type": "private",
|
|
|
|
"content": "Test message",
|
2020-03-10 11:48:26 +01:00
|
|
|
"to": pm_recipient.email})
|
2016-11-03 18:49:00 +01:00
|
|
|
self.assert_json_success(pm)
|
|
|
|
content = ujson.loads(pm.content)
|
2016-12-04 10:50:32 +01:00
|
|
|
|
2016-11-03 18:49:00 +01:00
|
|
|
pm_id = content['id']
|
2019-10-10 19:03:09 +02:00
|
|
|
|
|
|
|
reaction_info = {
|
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
|
|
|
'emoji_name': 'smile',
|
2019-10-10 19:03:09 +02:00
|
|
|
}
|
|
|
|
|
2020-06-10 06:41:04 +02:00
|
|
|
first = self.api_post(reaction_sender, f'/api/v1/messages/{pm_id}/reactions',
|
2019-10-10 19:03:09 +02:00
|
|
|
reaction_info)
|
2016-11-03 18:49:00 +01:00
|
|
|
self.assert_json_success(first)
|
2019-10-10 19:03:09 +02:00
|
|
|
|
2020-06-10 06:41:04 +02:00
|
|
|
second = self.api_post(reaction_sender, f'/api/v1/messages/{pm_id}/reactions',
|
2019-10-10 19:03:09 +02:00
|
|
|
reaction_info)
|
|
|
|
self.assert_json_error(second, "Reaction already exists.")
|
2016-11-03 18:49:00 +01:00
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_remove_nonexisting_reaction(self) -> None:
|
2016-11-30 08:14:46 +01:00
|
|
|
"""
|
|
|
|
Removing a reaction twice fails
|
|
|
|
"""
|
2020-03-10 11:48:26 +01:00
|
|
|
pm_sender = self.example_user("hamlet")
|
|
|
|
pm_recipient = self.example_user("othello")
|
2016-11-30 08:14:46 +01:00
|
|
|
reaction_sender = pm_recipient
|
|
|
|
|
2017-12-14 19:02:31 +01:00
|
|
|
pm = self.api_post(pm_sender,
|
|
|
|
"/api/v1/messages", {"type": "private",
|
|
|
|
"content": "Test message",
|
2020-03-10 11:48:26 +01:00
|
|
|
"to": pm_recipient.email})
|
2016-11-30 08:14:46 +01:00
|
|
|
self.assert_json_success(pm)
|
2019-10-10 19:03:09 +02:00
|
|
|
|
2016-11-30 08:14:46 +01:00
|
|
|
content = ujson.loads(pm.content)
|
|
|
|
pm_id = content['id']
|
2019-10-10 19:03:09 +02:00
|
|
|
reaction_info = {
|
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
|
|
|
'emoji_name': 'smile',
|
2019-10-10 19:03:09 +02:00
|
|
|
}
|
|
|
|
|
2020-06-10 06:41:04 +02:00
|
|
|
add = self.api_post(reaction_sender, f'/api/v1/messages/{pm_id}/reactions',
|
2019-10-10 19:03:09 +02:00
|
|
|
reaction_info)
|
2016-11-30 08:14:46 +01:00
|
|
|
self.assert_json_success(add)
|
|
|
|
|
2020-06-10 06:41:04 +02:00
|
|
|
first = self.api_delete(reaction_sender, f'/api/v1/messages/{pm_id}/reactions',
|
2019-10-10 19:03:09 +02:00
|
|
|
reaction_info)
|
2016-11-30 08:14:46 +01:00
|
|
|
self.assert_json_success(first)
|
|
|
|
|
2020-06-10 06:41:04 +02:00
|
|
|
second = self.api_delete(reaction_sender, f'/api/v1/messages/{pm_id}/reactions',
|
2019-10-10 19:03:09 +02:00
|
|
|
reaction_info)
|
|
|
|
self.assert_json_error(second, "Reaction doesn't exist.")
|
2016-11-30 08:14:46 +01:00
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_remove_existing_reaction_with_renamed_emoji(self) -> None:
|
2017-10-08 15:42:41 +02:00
|
|
|
"""
|
|
|
|
Removes an old existing reaction but the name of emoji got changed during
|
|
|
|
various emoji infra changes.
|
|
|
|
"""
|
2019-10-10 19:03:09 +02:00
|
|
|
realm = get_realm('zulip')
|
2020-03-10 11:48:26 +01:00
|
|
|
sender = self.example_user("hamlet")
|
2019-10-10 19:03:09 +02:00
|
|
|
emoji_code, reaction_type = emoji_name_to_emoji_code(realm, 'smile')
|
|
|
|
reaction_info = {
|
|
|
|
'emoji_name': 'smile',
|
|
|
|
'emoji_code': emoji_code,
|
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
|
|
|
'reaction_type': reaction_type,
|
2019-10-10 19:03:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
result = self.api_post(sender, '/api/v1/messages/1/reactions', reaction_info)
|
2017-10-08 15:42:41 +02:00
|
|
|
self.assert_json_success(result)
|
|
|
|
|
|
|
|
with mock.patch('zerver.lib.emoji.name_to_codepoint', name_to_codepoint={}):
|
2019-10-10 19:03:09 +02:00
|
|
|
result = self.api_delete(sender, '/api/v1/messages/1/reactions', reaction_info)
|
2017-10-08 15:42:41 +02:00
|
|
|
self.assert_json_success(result)
|
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_remove_existing_reaction_with_deactivated_realm_emoji(self) -> None:
|
2017-10-08 15:42:41 +02:00
|
|
|
"""
|
|
|
|
Removes an old existing reaction but the realm emoji used there has been deactivated.
|
|
|
|
"""
|
2020-03-10 11:48:26 +01:00
|
|
|
sender = self.example_user("hamlet")
|
2019-10-10 19:03:09 +02:00
|
|
|
|
|
|
|
emoji = RealmEmoji.objects.get(name="green_tick")
|
|
|
|
|
|
|
|
reaction_info = {
|
|
|
|
'emoji_name': 'green_tick',
|
|
|
|
'emoji_code': str(emoji.id),
|
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
|
|
|
'reaction_type': 'realm_emoji',
|
2019-10-10 19:03:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
result = self.api_post(sender, '/api/v1/messages/1/reactions', reaction_info)
|
2017-10-08 15:42:41 +02:00
|
|
|
self.assert_json_success(result)
|
|
|
|
|
|
|
|
# Deactivate realm emoji.
|
|
|
|
emoji.deactivated = True
|
|
|
|
emoji.save(update_fields=['deactivated'])
|
2019-10-10 19:03:09 +02:00
|
|
|
result = self.api_delete(sender, '/api/v1/messages/1/reactions', reaction_info)
|
2017-10-08 15:42:41 +02:00
|
|
|
self.assert_json_success(result)
|
2016-11-30 08:14:46 +01:00
|
|
|
|
2016-11-03 18:49:00 +01:00
|
|
|
class ReactionEventTest(ZulipTestCase):
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_add_event(self) -> None:
|
2016-11-03 18:49:00 +01:00
|
|
|
"""
|
|
|
|
Recipients of the message receive the reaction event
|
|
|
|
and event contains relevant data
|
|
|
|
"""
|
2017-05-24 02:42:31 +02:00
|
|
|
pm_sender = self.example_user('hamlet')
|
|
|
|
pm_recipient = self.example_user('othello')
|
2016-11-03 18:49:00 +01:00
|
|
|
reaction_sender = pm_recipient
|
|
|
|
|
2020-03-10 11:48:26 +01:00
|
|
|
result = self.api_post(pm_sender,
|
2017-12-14 19:02:31 +01:00
|
|
|
"/api/v1/messages", {"type": "private",
|
|
|
|
"content": "Test message",
|
|
|
|
"to": pm_recipient.email})
|
2016-11-03 18:49:00 +01:00
|
|
|
self.assert_json_success(result)
|
2017-08-16 09:51:15 +02:00
|
|
|
pm_id = result.json()['id']
|
2016-11-03 18:49:00 +01:00
|
|
|
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_recipient_ids = {pm_sender.id, pm_recipient.id}
|
2016-11-03 18:49:00 +01:00
|
|
|
|
2019-10-10 19:03:09 +02:00
|
|
|
reaction_info = {
|
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
|
|
|
'emoji_name': 'smile',
|
2019-10-10 19:03:09 +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-11-03 18:49:00 +01:00
|
|
|
with tornado_redirected_to_list(events):
|
2020-06-10 06:41:04 +02:00
|
|
|
result = self.api_post(reaction_sender, f'/api/v1/messages/{pm_id}/reactions',
|
2019-10-10 19:03:09 +02:00
|
|
|
reaction_info)
|
2016-11-03 18:49:00 +01:00
|
|
|
self.assert_json_success(result)
|
|
|
|
self.assertEqual(len(events), 1)
|
|
|
|
|
|
|
|
event = events[0]['event']
|
|
|
|
event_user_ids = set(events[0]['users'])
|
|
|
|
|
|
|
|
self.assertEqual(expected_recipient_ids, event_user_ids)
|
2017-05-24 02:42:31 +02:00
|
|
|
self.assertEqual(event['user']['email'], reaction_sender.email)
|
2016-11-03 18:49:00 +01:00
|
|
|
self.assertEqual(event['type'], 'reaction')
|
|
|
|
self.assertEqual(event['op'], 'add')
|
|
|
|
self.assertEqual(event['emoji_name'], 'smile')
|
|
|
|
self.assertEqual(event['message_id'], pm_id)
|
2016-11-30 08:14:46 +01:00
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_remove_event(self) -> None:
|
2016-11-30 08:14:46 +01:00
|
|
|
"""
|
|
|
|
Recipients of the message receive the reaction event
|
|
|
|
and event contains relevant data
|
|
|
|
"""
|
2017-05-24 02:42:31 +02:00
|
|
|
pm_sender = self.example_user('hamlet')
|
|
|
|
pm_recipient = self.example_user('othello')
|
2016-11-30 08:14:46 +01:00
|
|
|
reaction_sender = pm_recipient
|
|
|
|
|
2020-03-10 11:48:26 +01:00
|
|
|
result = self.api_post(pm_sender,
|
2017-12-14 19:02:31 +01:00
|
|
|
"/api/v1/messages", {"type": "private",
|
|
|
|
"content": "Test message",
|
|
|
|
"to": pm_recipient.email})
|
2016-11-30 08:14:46 +01:00
|
|
|
self.assert_json_success(result)
|
2017-08-17 08:42:19 +02:00
|
|
|
content = result.json()
|
2016-11-30 08:14:46 +01:00
|
|
|
pm_id = content['id']
|
|
|
|
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_recipient_ids = {pm_sender.id, pm_recipient.id}
|
2016-11-30 08:14:46 +01:00
|
|
|
|
2019-10-10 19:03:09 +02:00
|
|
|
reaction_info = {
|
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
|
|
|
'emoji_name': 'smile',
|
2019-10-10 19:03:09 +02:00
|
|
|
}
|
|
|
|
|
2020-06-10 06:41:04 +02:00
|
|
|
add = self.api_post(reaction_sender, f'/api/v1/messages/{pm_id}/reactions',
|
2019-10-10 19:03:09 +02:00
|
|
|
reaction_info)
|
2016-11-30 08:14:46 +01:00
|
|
|
self.assert_json_success(add)
|
|
|
|
|
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-11-30 08:14:46 +01:00
|
|
|
with tornado_redirected_to_list(events):
|
2020-06-10 06:41:04 +02:00
|
|
|
result = self.api_delete(reaction_sender, f'/api/v1/messages/{pm_id}/reactions',
|
2019-10-10 19:03:09 +02:00
|
|
|
reaction_info)
|
2016-11-30 08:14:46 +01:00
|
|
|
self.assert_json_success(result)
|
|
|
|
self.assertEqual(len(events), 1)
|
|
|
|
|
|
|
|
event = events[0]['event']
|
|
|
|
event_user_ids = set(events[0]['users'])
|
|
|
|
|
|
|
|
self.assertEqual(expected_recipient_ids, event_user_ids)
|
2017-05-24 02:42:31 +02:00
|
|
|
self.assertEqual(event['user']['email'], reaction_sender.email)
|
2016-11-30 08:14:46 +01:00
|
|
|
self.assertEqual(event['type'], 'reaction')
|
|
|
|
self.assertEqual(event['op'], 'remove')
|
|
|
|
self.assertEqual(event['emoji_name'], 'smile')
|
|
|
|
self.assertEqual(event['message_id'], pm_id)
|
2017-10-08 09:34:59 +02:00
|
|
|
|
2017-11-18 20:52:22 +01:00
|
|
|
class EmojiReactionBase(ZulipTestCase):
|
2019-05-30 13:01:06 +02:00
|
|
|
"""Reusable testing functions for emoji reactions tests. Be careful when
|
|
|
|
changing this: It's used in test_retention.py as well."""
|
2020-04-22 01:45:30 +02:00
|
|
|
|
2017-11-18 20:52:22 +01:00
|
|
|
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
2020-07-16 17:06:39 +02:00
|
|
|
def post_reaction(self, reaction_info: Dict[str, str]) -> HttpResponse:
|
|
|
|
message_id = 1
|
|
|
|
|
|
|
|
result = self.api_post(
|
|
|
|
self.example_user('hamlet'),
|
|
|
|
f'/api/v1/messages/{message_id}/reactions',
|
|
|
|
reaction_info
|
|
|
|
)
|
2017-10-08 09:34:59 +02:00
|
|
|
return result
|
|
|
|
|
2020-07-16 17:06:39 +02:00
|
|
|
def post_other_reaction(self, reaction_info: Dict[str, str]) -> HttpResponse:
|
|
|
|
message_id = 1
|
2017-11-18 20:52:22 +01:00
|
|
|
|
2020-07-16 17:06:39 +02:00
|
|
|
result = self.api_post(
|
|
|
|
self.example_user('AARON'),
|
|
|
|
f'/api/v1/messages/{message_id}/reactions',
|
|
|
|
reaction_info
|
|
|
|
)
|
2017-11-18 20:52:22 +01:00
|
|
|
return result
|
|
|
|
|
2020-07-16 17:06:39 +02:00
|
|
|
def delete_reaction(self, reaction_info: Dict[str, str]) -> HttpResponse:
|
|
|
|
message_id = 1
|
2017-10-08 09:34:59 +02:00
|
|
|
|
2020-07-16 17:06:39 +02:00
|
|
|
result = self.api_delete(
|
|
|
|
self.example_user('hamlet'),
|
|
|
|
f'/api/v1/messages/{message_id}/reactions',
|
|
|
|
reaction_info
|
|
|
|
)
|
2017-11-18 20:52:22 +01:00
|
|
|
return result
|
|
|
|
|
|
|
|
def get_message_reactions(self, message_id: int, emoji_code: str,
|
|
|
|
reaction_type: str) -> List[Reaction]:
|
2017-10-08 09:34:59 +02:00
|
|
|
message = Message.objects.get(id=message_id)
|
|
|
|
reactions = Reaction.objects.filter(message=message,
|
|
|
|
emoji_code=emoji_code,
|
|
|
|
reaction_type=reaction_type)
|
|
|
|
return list(reactions)
|
|
|
|
|
2017-11-18 20:52:22 +01:00
|
|
|
class DefaultEmojiReactionTests(EmojiReactionBase):
|
2017-11-05 10:51:25 +01:00
|
|
|
def setUp(self) -> None:
|
2019-10-19 20:47:00 +02:00
|
|
|
super().setUp()
|
2017-10-08 09:34:59 +02:00
|
|
|
reaction_info = {
|
2020-07-16 17:06:39 +02:00
|
|
|
'reaction_type': 'unicode_emoji',
|
2017-10-08 09:34:59 +02:00
|
|
|
'emoji_name': 'hamburger',
|
|
|
|
'emoji_code': '1f354',
|
|
|
|
}
|
|
|
|
result = self.post_reaction(reaction_info)
|
|
|
|
self.assert_json_success(result)
|
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_add_default_emoji_reaction(self) -> None:
|
2017-10-08 09:34:59 +02:00
|
|
|
reaction_info = {
|
2020-07-16 17:06:39 +02:00
|
|
|
'reaction_type': 'unicode_emoji',
|
2017-10-08 09:34:59 +02:00
|
|
|
'emoji_name': 'thumbs_up',
|
|
|
|
'emoji_code': '1f44d',
|
|
|
|
}
|
|
|
|
result = self.post_reaction(reaction_info)
|
|
|
|
self.assert_json_success(result)
|
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_add_default_emoji_invalid_code(self) -> None:
|
2017-10-08 09:34:59 +02:00
|
|
|
reaction_info = {
|
2020-07-16 17:06:39 +02:00
|
|
|
'reaction_type': 'unicode_emoji',
|
2017-10-08 09:34:59 +02:00
|
|
|
'emoji_name': 'hamburger',
|
|
|
|
'emoji_code': 'TBD',
|
|
|
|
}
|
|
|
|
result = self.post_reaction(reaction_info)
|
2018-03-08 01:35:07 +01:00
|
|
|
self.assert_json_error(result, 'Invalid emoji code.')
|
2017-10-08 09:34:59 +02:00
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_add_default_emoji_invalid_name(self) -> None:
|
2017-10-08 09:34:59 +02:00
|
|
|
reaction_info = {
|
2020-07-16 17:06:39 +02:00
|
|
|
'reaction_type': 'unicode_emoji',
|
2017-10-08 09:34:59 +02:00
|
|
|
'emoji_name': 'non-existent',
|
|
|
|
'emoji_code': '1f44d',
|
|
|
|
}
|
|
|
|
result = self.post_reaction(reaction_info)
|
|
|
|
self.assert_json_error(result, 'Invalid emoji name.')
|
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_add_to_existing_renamed_default_emoji_reaction(self) -> None:
|
2017-10-08 09:34:59 +02:00
|
|
|
hamlet = self.example_user('hamlet')
|
|
|
|
message = Message.objects.get(id=1)
|
|
|
|
reaction = Reaction.objects.create(user_profile=hamlet,
|
|
|
|
message=message,
|
|
|
|
emoji_name='old_name',
|
|
|
|
emoji_code='1f603',
|
|
|
|
reaction_type='unicode_emoji',
|
|
|
|
)
|
|
|
|
reaction_info = {
|
2020-07-16 17:06:39 +02:00
|
|
|
'reaction_type': 'unicode_emoji',
|
2017-10-08 09:34:59 +02:00
|
|
|
'emoji_name': 'smiley',
|
|
|
|
'emoji_code': '1f603',
|
|
|
|
}
|
2020-07-16 17:06:39 +02:00
|
|
|
result = self.post_other_reaction(reaction_info)
|
2017-10-08 09:34:59 +02:00
|
|
|
self.assert_json_success(result)
|
|
|
|
|
|
|
|
reactions = self.get_message_reactions(1, '1f603', 'unicode_emoji')
|
|
|
|
for reaction in reactions:
|
|
|
|
self.assertEqual(reaction.emoji_name, 'old_name')
|
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_add_duplicate_reaction(self) -> None:
|
2017-10-08 09:34:59 +02:00
|
|
|
reaction_info = {
|
2020-07-16 17:06:39 +02:00
|
|
|
'reaction_type': 'unicode_emoji',
|
2017-10-08 09:34:59 +02:00
|
|
|
'emoji_name': 'non-existent',
|
|
|
|
'emoji_code': '1f354',
|
|
|
|
}
|
|
|
|
result = self.post_reaction(reaction_info)
|
|
|
|
self.assert_json_error(result, 'Reaction already exists.')
|
|
|
|
|
2018-07-09 08:45:56 +02:00
|
|
|
def test_add_reaction_by_name(self) -> None:
|
|
|
|
reaction_info = {
|
2020-07-16 17:06:39 +02:00
|
|
|
'reaction_type': 'unicode_emoji',
|
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
|
|
|
'emoji_name': '+1',
|
2018-07-09 08:45:56 +02:00
|
|
|
}
|
|
|
|
result = self.post_reaction(reaction_info)
|
|
|
|
self.assert_json_success(result)
|
|
|
|
hamlet = self.example_user('hamlet')
|
|
|
|
message = Message.objects.get(id=1)
|
|
|
|
self.assertTrue(
|
|
|
|
Reaction.objects.filter(user_profile=hamlet,
|
|
|
|
message=message,
|
|
|
|
emoji_name=reaction_info['emoji_name'],
|
|
|
|
emoji_code='1f44d',
|
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
|
|
|
reaction_type='unicode_emoji').exists(),
|
2018-07-09 08:45:56 +02:00
|
|
|
)
|
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_preserve_non_canonical_name(self) -> None:
|
2017-10-08 09:34:59 +02:00
|
|
|
reaction_info = {
|
2020-07-16 17:06:39 +02:00
|
|
|
'reaction_type': 'unicode_emoji',
|
2017-10-08 09:34:59 +02:00
|
|
|
'emoji_name': '+1',
|
|
|
|
'emoji_code': '1f44d',
|
|
|
|
}
|
|
|
|
result = self.post_reaction(reaction_info)
|
|
|
|
self.assert_json_success(result)
|
|
|
|
|
|
|
|
reactions = self.get_message_reactions(1, '1f44d', 'unicode_emoji')
|
|
|
|
for reaction in reactions:
|
|
|
|
self.assertEqual(reaction.emoji_name, '+1')
|
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_reaction_name_collapse(self) -> None:
|
2017-10-08 09:34:59 +02:00
|
|
|
reaction_info = {
|
2020-07-16 17:06:39 +02:00
|
|
|
'reaction_type': 'unicode_emoji',
|
2017-10-08 09:34:59 +02:00
|
|
|
'emoji_name': '+1',
|
|
|
|
'emoji_code': '1f44d',
|
|
|
|
}
|
|
|
|
result = self.post_reaction(reaction_info)
|
|
|
|
self.assert_json_success(result)
|
|
|
|
|
|
|
|
reaction_info['emoji_name'] = 'thumbs_up'
|
2020-07-16 17:06:39 +02:00
|
|
|
result = self.post_other_reaction(reaction_info)
|
2017-10-08 09:34:59 +02:00
|
|
|
self.assert_json_success(result)
|
|
|
|
|
|
|
|
reactions = self.get_message_reactions(1, '1f44d', 'unicode_emoji')
|
|
|
|
for reaction in reactions:
|
|
|
|
self.assertEqual(reaction.emoji_name, '+1')
|
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_delete_default_emoji_reaction(self) -> None:
|
2017-10-08 09:34:59 +02:00
|
|
|
reaction_info = {
|
2020-07-16 17:06:39 +02:00
|
|
|
'reaction_type': 'unicode_emoji',
|
2017-10-08 09:34:59 +02:00
|
|
|
'emoji_name': 'hamburger',
|
|
|
|
'emoji_code': '1f354',
|
|
|
|
}
|
|
|
|
result = self.delete_reaction(reaction_info)
|
|
|
|
self.assert_json_success(result)
|
|
|
|
|
2018-07-09 10:48:42 +02:00
|
|
|
def test_delete_insufficient_arguments_reaction(self) -> None:
|
|
|
|
result = self.delete_reaction({})
|
|
|
|
self.assert_json_error(result, 'At least one of the following '
|
|
|
|
'arguments must be present: emoji_name, '
|
|
|
|
'emoji_code')
|
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_delete_non_existing_emoji_reaction(self) -> None:
|
2017-10-08 09:34:59 +02:00
|
|
|
reaction_info = {
|
2020-07-16 17:06:39 +02:00
|
|
|
'reaction_type': 'unicode_emoji',
|
2017-10-08 09:34:59 +02:00
|
|
|
'emoji_name': 'thumbs_up',
|
|
|
|
'emoji_code': '1f44d',
|
|
|
|
}
|
|
|
|
result = self.delete_reaction(reaction_info)
|
|
|
|
self.assert_json_error(result, "Reaction doesn't exist.")
|
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_delete_renamed_default_emoji(self) -> None:
|
2017-10-08 09:34:59 +02:00
|
|
|
hamlet = self.example_user('hamlet')
|
|
|
|
message = Message.objects.get(id=1)
|
|
|
|
Reaction.objects.create(user_profile=hamlet,
|
|
|
|
message=message,
|
|
|
|
emoji_name='old_name',
|
|
|
|
emoji_code='1f44f',
|
|
|
|
reaction_type='unicode_emoji',
|
|
|
|
)
|
|
|
|
|
|
|
|
reaction_info = {
|
2020-07-16 17:06:39 +02:00
|
|
|
'reaction_type': 'unicode_emoji',
|
2017-10-08 09:34:59 +02:00
|
|
|
'emoji_name': 'new_name',
|
|
|
|
'emoji_code': '1f44f',
|
|
|
|
}
|
|
|
|
result = self.delete_reaction(reaction_info)
|
|
|
|
self.assert_json_success(result)
|
|
|
|
|
2018-07-09 10:48:42 +02:00
|
|
|
def test_delete_reaction_by_name(self) -> None:
|
|
|
|
hamlet = self.example_user('hamlet')
|
|
|
|
message = Message.objects.get(id=1)
|
|
|
|
Reaction.objects.create(user_profile=hamlet,
|
|
|
|
message=message,
|
|
|
|
emoji_name='+1',
|
|
|
|
emoji_code='1f44d',
|
|
|
|
reaction_type='unicode_emoji',
|
|
|
|
)
|
|
|
|
|
|
|
|
reaction_info = {
|
2020-07-16 17:06:39 +02:00
|
|
|
'reaction_type': 'unicode_emoji',
|
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
|
|
|
'emoji_name': '+1',
|
2018-07-09 10:48:42 +02:00
|
|
|
}
|
|
|
|
result = self.delete_reaction(reaction_info)
|
|
|
|
self.assert_json_success(result)
|
|
|
|
self.assertFalse(
|
|
|
|
Reaction.objects.filter(user_profile=hamlet,
|
|
|
|
message=message,
|
|
|
|
emoji_name=reaction_info['emoji_name'],
|
|
|
|
emoji_code='1f44d',
|
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
|
|
|
reaction_type='unicode_emoji').exists(),
|
2018-07-09 10:48:42 +02:00
|
|
|
)
|
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_react_historical(self) -> None:
|
2017-10-08 09:34:59 +02:00
|
|
|
"""
|
|
|
|
Reacting with valid emoji on a historical message succeeds.
|
|
|
|
"""
|
|
|
|
stream_name = "Saxony"
|
|
|
|
self.subscribe(self.example_user("cordelia"), stream_name)
|
2020-03-07 11:43:05 +01:00
|
|
|
message_id = self.send_stream_message(self.example_user("cordelia"), stream_name)
|
2017-10-08 09:34:59 +02:00
|
|
|
|
|
|
|
user_profile = self.example_user('hamlet')
|
|
|
|
|
|
|
|
# Verify that hamlet did not receive the message.
|
|
|
|
self.assertFalse(UserMessage.objects.filter(user_profile=user_profile,
|
|
|
|
message_id=message_id).exists())
|
|
|
|
|
|
|
|
# Have hamlet react to the message
|
|
|
|
reaction_info = {
|
2020-07-16 17:06:39 +02:00
|
|
|
'reaction_type': 'unicode_emoji',
|
2017-10-08 09:34:59 +02:00
|
|
|
'emoji_name': 'hamburger',
|
|
|
|
'emoji_code': '1f354',
|
|
|
|
}
|
2020-07-16 17:06:39 +02:00
|
|
|
|
|
|
|
result = self.api_post(
|
|
|
|
user_profile,
|
|
|
|
f'/api/v1/messages/{message_id}/reactions',
|
|
|
|
reaction_info
|
|
|
|
)
|
2017-10-08 09:34:59 +02:00
|
|
|
self.assert_json_success(result)
|
|
|
|
|
|
|
|
# Fetch the now-created UserMessage object to confirm it exists and is historical
|
|
|
|
user_message = UserMessage.objects.get(user_profile=user_profile, message_id=message_id)
|
|
|
|
self.assertTrue(user_message.flags.historical)
|
|
|
|
self.assertTrue(user_message.flags.read)
|
|
|
|
self.assertFalse(user_message.flags.starred)
|
|
|
|
|
2017-11-18 20:52:22 +01:00
|
|
|
class ZulipExtraEmojiReactionTest(EmojiReactionBase):
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_add_zulip_emoji_reaction(self) -> None:
|
2020-07-16 17:06:39 +02:00
|
|
|
result = self.post_reaction(zulip_reaction_info())
|
2017-10-08 09:34:59 +02:00
|
|
|
self.assert_json_success(result)
|
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_add_duplicate_zulip_reaction(self) -> None:
|
2020-07-16 17:06:39 +02:00
|
|
|
result = self.post_reaction(zulip_reaction_info())
|
2017-10-08 09:34:59 +02:00
|
|
|
self.assert_json_success(result)
|
|
|
|
|
2020-07-16 17:06:39 +02:00
|
|
|
result = self.post_reaction(zulip_reaction_info())
|
2017-10-08 09:34:59 +02:00
|
|
|
self.assert_json_error(result, 'Reaction already exists.')
|
|
|
|
|
2017-11-19 07:07:29 +01:00
|
|
|
def test_add_invalid_extra_emoji(self) -> None:
|
|
|
|
reaction_info = {
|
|
|
|
'emoji_name': 'extra_emoji',
|
|
|
|
'emoji_code': 'extra_emoji',
|
|
|
|
'reaction_type': 'zulip_extra_emoji',
|
|
|
|
}
|
|
|
|
result = self.post_reaction(reaction_info)
|
2018-03-08 01:35:07 +01:00
|
|
|
self.assert_json_error(result, 'Invalid emoji code.')
|
2017-11-19 07:07:29 +01:00
|
|
|
|
2017-11-21 00:25:40 +01:00
|
|
|
def test_add_invalid_emoji_name(self) -> None:
|
|
|
|
reaction_info = {
|
|
|
|
'emoji_name': 'zulip_invalid',
|
|
|
|
'emoji_code': 'zulip',
|
|
|
|
'reaction_type': 'zulip_extra_emoji',
|
|
|
|
}
|
|
|
|
result = self.post_reaction(reaction_info)
|
|
|
|
self.assert_json_error(result, 'Invalid emoji name.')
|
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_delete_zulip_emoji(self) -> None:
|
2020-07-16 17:06:39 +02:00
|
|
|
result = self.post_reaction(zulip_reaction_info())
|
2017-10-08 09:34:59 +02:00
|
|
|
self.assert_json_success(result)
|
|
|
|
|
2020-07-16 17:06:39 +02:00
|
|
|
result = self.delete_reaction(zulip_reaction_info())
|
2017-10-08 09:34:59 +02:00
|
|
|
self.assert_json_success(result)
|
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_delete_non_existent_zulip_reaction(self) -> None:
|
2020-07-16 17:06:39 +02:00
|
|
|
result = self.delete_reaction(zulip_reaction_info())
|
2017-10-08 09:34:59 +02:00
|
|
|
self.assert_json_error(result, "Reaction doesn't exist.")
|
|
|
|
|
2017-11-18 20:52:22 +01:00
|
|
|
class RealmEmojiReactionTests(EmojiReactionBase):
|
2017-12-15 16:54:07 +01:00
|
|
|
def setUp(self) -> None:
|
2019-10-19 20:47:00 +02:00
|
|
|
super().setUp()
|
2017-12-15 16:54:07 +01:00
|
|
|
green_tick_emoji = RealmEmoji.objects.get(name="green_tick")
|
|
|
|
self.default_reaction_info = {
|
2020-07-16 17:06:39 +02:00
|
|
|
'reaction_type': 'realm_emoji',
|
2017-10-08 09:34:59 +02:00
|
|
|
'emoji_name': 'green_tick',
|
2017-12-15 16:54:07 +01:00
|
|
|
'emoji_code': str(green_tick_emoji.id),
|
2017-10-08 09:34:59 +02:00
|
|
|
}
|
2017-12-15 16:54:07 +01:00
|
|
|
|
|
|
|
def test_add_realm_emoji(self) -> None:
|
|
|
|
result = self.post_reaction(self.default_reaction_info)
|
2017-10-08 09:34:59 +02:00
|
|
|
self.assert_json_success(result)
|
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_add_realm_emoji_invalid_code(self) -> None:
|
2017-10-08 09:34:59 +02:00
|
|
|
reaction_info = {
|
2020-07-16 17:06:39 +02:00
|
|
|
'reaction_type': 'realm_emoji',
|
2017-10-08 09:34:59 +02:00
|
|
|
'emoji_name': 'green_tick',
|
2017-12-15 16:54:07 +01:00
|
|
|
'emoji_code': '9999',
|
2017-10-08 09:34:59 +02:00
|
|
|
}
|
|
|
|
result = self.post_reaction(reaction_info)
|
2018-03-11 18:55:20 +01:00
|
|
|
self.assert_json_error(result, 'Invalid custom emoji.')
|
2017-10-08 09:34:59 +02:00
|
|
|
|
2017-11-21 00:25:40 +01:00
|
|
|
def test_add_realm_emoji_invalid_name(self) -> None:
|
2018-03-11 18:55:20 +01:00
|
|
|
green_tick_emoji = RealmEmoji.objects.get(name="green_tick")
|
2017-11-21 00:25:40 +01:00
|
|
|
reaction_info = {
|
2020-07-16 17:06:39 +02:00
|
|
|
'reaction_type': 'realm_emoji',
|
2017-11-21 00:25:40 +01:00
|
|
|
'emoji_name': 'bogus_name',
|
2018-03-11 18:55:20 +01:00
|
|
|
'emoji_code': str(green_tick_emoji.id),
|
2017-11-21 00:25:40 +01:00
|
|
|
}
|
|
|
|
result = self.post_reaction(reaction_info)
|
2018-03-11 18:55:20 +01:00
|
|
|
self.assert_json_error(result, 'Invalid custom emoji name.')
|
2017-11-21 00:25:40 +01:00
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_add_deactivated_realm_emoji(self) -> None:
|
2017-10-08 09:34:59 +02:00
|
|
|
emoji = RealmEmoji.objects.get(name="green_tick")
|
|
|
|
emoji.deactivated = True
|
|
|
|
emoji.save(update_fields=['deactivated'])
|
|
|
|
|
2017-12-15 16:54:07 +01:00
|
|
|
result = self.post_reaction(self.default_reaction_info)
|
2018-03-08 01:35:07 +01:00
|
|
|
self.assert_json_error(result, 'This custom emoji has been deactivated.')
|
2017-10-08 09:34:59 +02:00
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_add_to_existing_deactivated_realm_emoji_reaction(self) -> None:
|
2017-12-15 16:54:07 +01:00
|
|
|
result = self.post_reaction(self.default_reaction_info)
|
2017-10-08 09:34:59 +02:00
|
|
|
self.assert_json_success(result)
|
|
|
|
|
|
|
|
emoji = RealmEmoji.objects.get(name="green_tick")
|
|
|
|
emoji.deactivated = True
|
|
|
|
emoji.save(update_fields=['deactivated'])
|
|
|
|
|
2020-07-16 17:06:39 +02:00
|
|
|
result = self.post_other_reaction(self.default_reaction_info)
|
2017-10-08 09:34:59 +02:00
|
|
|
self.assert_json_success(result)
|
|
|
|
|
2017-12-15 16:54:07 +01:00
|
|
|
reactions = self.get_message_reactions(1,
|
|
|
|
self.default_reaction_info['emoji_code'],
|
|
|
|
'realm_emoji')
|
2017-10-08 09:34:59 +02:00
|
|
|
self.assertEqual(len(reactions), 2)
|
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_remove_realm_emoji_reaction(self) -> None:
|
2017-12-15 16:54:07 +01:00
|
|
|
result = self.post_reaction(self.default_reaction_info)
|
2017-10-08 09:34:59 +02:00
|
|
|
self.assert_json_success(result)
|
|
|
|
|
2017-12-15 16:54:07 +01:00
|
|
|
result = self.delete_reaction(self.default_reaction_info)
|
2017-10-08 09:34:59 +02:00
|
|
|
self.assert_json_success(result)
|
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_remove_deactivated_realm_emoji_reaction(self) -> None:
|
2017-12-15 16:54:07 +01:00
|
|
|
result = self.post_reaction(self.default_reaction_info)
|
2017-10-08 09:34:59 +02:00
|
|
|
self.assert_json_success(result)
|
|
|
|
|
|
|
|
emoji = RealmEmoji.objects.get(name="green_tick")
|
|
|
|
emoji.deactivated = True
|
|
|
|
emoji.save(update_fields=['deactivated'])
|
|
|
|
|
2017-12-15 16:54:07 +01:00
|
|
|
result = self.delete_reaction(self.default_reaction_info)
|
2017-10-08 09:34:59 +02:00
|
|
|
self.assert_json_success(result)
|
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_remove_non_existent_realm_emoji_reaction(self) -> None:
|
2017-10-08 09:34:59 +02:00
|
|
|
reaction_info = {
|
2020-07-16 17:06:39 +02:00
|
|
|
'reaction_type': 'realm_emoji',
|
2017-10-08 09:34:59 +02:00
|
|
|
'emoji_name': 'non_existent',
|
|
|
|
'emoji_code': 'TBD',
|
|
|
|
}
|
|
|
|
result = self.delete_reaction(reaction_info)
|
|
|
|
self.assert_json_error(result, "Reaction doesn't exist.")
|
|
|
|
|
|
|
|
def test_invalid_reaction_type(self) -> None:
|
|
|
|
reaction_info = {
|
|
|
|
'emoji_name': 'zulip',
|
|
|
|
'emoji_code': 'zulip',
|
|
|
|
'reaction_type': 'nonexistent_emoji_type',
|
|
|
|
}
|
2020-03-10 11:48:26 +01:00
|
|
|
sender = self.example_user("hamlet")
|
2017-10-08 09:34:59 +02:00
|
|
|
message_id = 1
|
2020-06-10 06:41:04 +02:00
|
|
|
result = self.api_post(sender, f'/api/v1/messages/{message_id}/reactions',
|
2017-12-14 19:02:31 +01:00
|
|
|
reaction_info)
|
2017-11-19 07:07:29 +01:00
|
|
|
self.assert_json_error(result, "Invalid emoji type.")
|
2017-10-08 09:34:59 +02:00
|
|
|
|
2017-11-18 20:52:22 +01:00
|
|
|
class ReactionAPIEventTest(EmojiReactionBase):
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_add_event(self) -> None:
|
2017-10-08 09:34:59 +02:00
|
|
|
"""
|
|
|
|
Recipients of the message receive the reaction event
|
|
|
|
and event contains relevant data
|
|
|
|
"""
|
|
|
|
pm_sender = self.example_user('hamlet')
|
|
|
|
pm_recipient = self.example_user('othello')
|
|
|
|
reaction_sender = pm_recipient
|
2020-03-07 11:43:05 +01:00
|
|
|
pm_id = self.send_personal_message(pm_sender, pm_recipient)
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_recipient_ids = {pm_sender.id, pm_recipient.id}
|
2017-10-08 09:34:59 +02:00
|
|
|
reaction_info = {
|
|
|
|
'emoji_name': 'hamburger',
|
|
|
|
'emoji_code': '1f354',
|
|
|
|
'reaction_type': 'unicode_emoji',
|
|
|
|
}
|
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]] = []
|
2017-10-08 09:34:59 +02:00
|
|
|
with tornado_redirected_to_list(events):
|
2020-07-16 17:06:39 +02:00
|
|
|
self.api_post(
|
|
|
|
reaction_sender,
|
|
|
|
f'/api/v1/messages/{pm_id}/reactions',
|
|
|
|
reaction_info
|
|
|
|
)
|
|
|
|
|
2017-10-08 09:34:59 +02:00
|
|
|
self.assertEqual(len(events), 1)
|
|
|
|
|
|
|
|
event = events[0]['event']
|
|
|
|
event_user_ids = set(events[0]['users'])
|
|
|
|
|
|
|
|
self.assertEqual(expected_recipient_ids, event_user_ids)
|
|
|
|
self.assertEqual(event['user']['user_id'], reaction_sender.id)
|
|
|
|
self.assertEqual(event['user']['email'], reaction_sender.email)
|
|
|
|
self.assertEqual(event['user']['full_name'], reaction_sender.full_name)
|
|
|
|
self.assertEqual(event['type'], 'reaction')
|
|
|
|
self.assertEqual(event['op'], 'add')
|
|
|
|
self.assertEqual(event['message_id'], pm_id)
|
|
|
|
self.assertEqual(event['emoji_name'], reaction_info['emoji_name'])
|
|
|
|
self.assertEqual(event['emoji_code'], reaction_info['emoji_code'])
|
|
|
|
self.assertEqual(event['reaction_type'], reaction_info['reaction_type'])
|
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_remove_event(self) -> None:
|
2017-10-08 09:34:59 +02:00
|
|
|
"""
|
|
|
|
Recipients of the message receive the reaction event
|
|
|
|
and event contains relevant data
|
|
|
|
"""
|
|
|
|
pm_sender = self.example_user('hamlet')
|
|
|
|
pm_recipient = self.example_user('othello')
|
|
|
|
reaction_sender = pm_recipient
|
2020-03-07 11:43:05 +01:00
|
|
|
pm_id = self.send_personal_message(pm_sender, pm_recipient)
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_recipient_ids = {pm_sender.id, pm_recipient.id}
|
2017-10-08 09:34:59 +02:00
|
|
|
reaction_info = {
|
|
|
|
'emoji_name': 'hamburger',
|
|
|
|
'emoji_code': '1f354',
|
|
|
|
'reaction_type': 'unicode_emoji',
|
|
|
|
}
|
2020-07-16 17:06:39 +02:00
|
|
|
add = self.api_post(
|
|
|
|
reaction_sender,
|
|
|
|
f'/api/v1/messages/{pm_id}/reactions',
|
|
|
|
reaction_info,
|
|
|
|
)
|
2017-10-08 09:34:59 +02:00
|
|
|
self.assert_json_success(add)
|
|
|
|
|
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]] = []
|
2017-10-08 09:34:59 +02:00
|
|
|
with tornado_redirected_to_list(events):
|
2020-07-16 17:06:39 +02:00
|
|
|
result = self.api_delete(
|
|
|
|
reaction_sender,
|
|
|
|
f'/api/v1/messages/{pm_id}/reactions',
|
|
|
|
reaction_info,
|
|
|
|
)
|
|
|
|
|
2017-10-08 09:34:59 +02:00
|
|
|
self.assert_json_success(result)
|
|
|
|
self.assertEqual(len(events), 1)
|
|
|
|
|
|
|
|
event = events[0]['event']
|
|
|
|
event_user_ids = set(events[0]['users'])
|
|
|
|
|
|
|
|
self.assertEqual(expected_recipient_ids, event_user_ids)
|
|
|
|
self.assertEqual(event['user']['user_id'], reaction_sender.id)
|
|
|
|
self.assertEqual(event['user']['email'], reaction_sender.email)
|
|
|
|
self.assertEqual(event['user']['full_name'], reaction_sender.full_name)
|
|
|
|
self.assertEqual(event['type'], 'reaction')
|
|
|
|
self.assertEqual(event['op'], 'remove')
|
|
|
|
self.assertEqual(event['message_id'], pm_id)
|
|
|
|
self.assertEqual(event['emoji_name'], reaction_info['emoji_name'])
|
|
|
|
self.assertEqual(event['emoji_code'], reaction_info['emoji_code'])
|
|
|
|
self.assertEqual(event['reaction_type'], reaction_info['reaction_type'])
|