mirror of
https://github.com/zulip/zulip.git
synced 2025-11-16 03:41:58 +00:00
test_reactions.py: Extract EmojiBaseReaction test class.
This commit is contained in:
committed by
Tim Abbott
parent
8a4fc9970f
commit
9a4d5fe1f8
@@ -352,34 +352,61 @@ class ReactionEventTest(ZulipTestCase):
|
|||||||
self.assertEqual(event['emoji_name'], 'smile')
|
self.assertEqual(event['emoji_name'], 'smile')
|
||||||
self.assertEqual(event['message_id'], pm_id)
|
self.assertEqual(event['message_id'], pm_id)
|
||||||
|
|
||||||
class DefaultEmojiReactionTests(ZulipTestCase):
|
class EmojiReactionBase(ZulipTestCase):
|
||||||
|
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
||||||
|
self.reaction_type = 'realm_emoji'
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
def post_reaction(self, reaction_info: Dict[str, str], message_id: int=1,
|
def post_reaction(self, reaction_info: Dict[str, str], message_id: int=1,
|
||||||
sender: str='hamlet') -> HttpResponse:
|
sender: str='hamlet') -> HttpResponse:
|
||||||
reaction_info['reaction_type'] = 'unicode_emoji'
|
if 'reaction_type' not in reaction_info:
|
||||||
|
reaction_info['reaction_type'] = self.reaction_type
|
||||||
sender = self.example_email(sender)
|
sender = self.example_email(sender)
|
||||||
result = self.client_post('/api/v1/messages/%s/reactions' % (message_id,),
|
result = self.client_post('/api/v1/messages/%s/reactions' % (message_id,),
|
||||||
reaction_info,
|
reaction_info,
|
||||||
**self.api_auth(sender))
|
**self.api_auth(sender))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def post_zulip_reaction(self, message_id: int=1, sender: str='hamlet') -> HttpResponse:
|
||||||
|
reaction_info = {
|
||||||
|
'emoji_name': 'zulip',
|
||||||
|
'emoji_code': 'zulip',
|
||||||
|
'reaction_type': 'zulip_extra_emoji',
|
||||||
|
}
|
||||||
|
result = self.post_reaction(reaction_info, message_id, sender)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
def delete_reaction(self, reaction_info: Dict[str, str], message_id: int=1,
|
def delete_reaction(self, reaction_info: Dict[str, str], message_id: int=1,
|
||||||
sender: str='hamlet') -> HttpResponse:
|
sender: str='hamlet') -> HttpResponse:
|
||||||
reaction_info['reaction_type'] = 'unicode_emoji'
|
if 'reaction_type' not in reaction_info:
|
||||||
|
reaction_info['reaction_type'] = self.reaction_type
|
||||||
sender = self.example_email(sender)
|
sender = self.example_email(sender)
|
||||||
result = self.client_delete('/api/v1/messages/%s/reactions' % (message_id,),
|
result = self.client_delete('/api/v1/messages/%s/reactions' % (message_id,),
|
||||||
reaction_info,
|
reaction_info,
|
||||||
**self.api_auth(sender))
|
**self.api_auth(sender))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def get_message_reactions(self, message_id: int, emoji_code: Text,
|
def delete_zulip_reaction(self, message_id: int=1, sender: str='hamlet') -> HttpResponse:
|
||||||
reaction_type: Text) -> List[Reaction]:
|
reaction_info = {
|
||||||
|
'emoji_name': 'zulip',
|
||||||
|
'emoji_code': 'zulip',
|
||||||
|
'reaction_type': 'zulip_extra_emoji',
|
||||||
|
}
|
||||||
|
result = self.delete_reaction(reaction_info, message_id, sender)
|
||||||
|
return result
|
||||||
|
|
||||||
|
def get_message_reactions(self, message_id: int, emoji_code: str,
|
||||||
|
reaction_type: str) -> List[Reaction]:
|
||||||
message = Message.objects.get(id=message_id)
|
message = Message.objects.get(id=message_id)
|
||||||
reactions = Reaction.objects.filter(message=message,
|
reactions = Reaction.objects.filter(message=message,
|
||||||
emoji_code=emoji_code,
|
emoji_code=emoji_code,
|
||||||
reaction_type=reaction_type)
|
reaction_type=reaction_type)
|
||||||
return list(reactions)
|
return list(reactions)
|
||||||
|
|
||||||
|
class DefaultEmojiReactionTests(EmojiReactionBase):
|
||||||
def setUp(self) -> None:
|
def setUp(self) -> None:
|
||||||
|
self.reaction_type = 'unicode_emoji'
|
||||||
reaction_info = {
|
reaction_info = {
|
||||||
'emoji_name': 'hamburger',
|
'emoji_name': 'hamburger',
|
||||||
'emoji_code': '1f354',
|
'emoji_code': '1f354',
|
||||||
@@ -528,19 +555,7 @@ class DefaultEmojiReactionTests(ZulipTestCase):
|
|||||||
self.assertTrue(user_message.flags.read)
|
self.assertTrue(user_message.flags.read)
|
||||||
self.assertFalse(user_message.flags.starred)
|
self.assertFalse(user_message.flags.starred)
|
||||||
|
|
||||||
class ZulipExtraEmojiReactionTest(ZulipTestCase):
|
class ZulipExtraEmojiReactionTest(EmojiReactionBase):
|
||||||
def post_zulip_reaction(self, message_id: int=1, sender: Text='hamlet') -> HttpResponse:
|
|
||||||
sender = self.example_email(sender)
|
|
||||||
reaction_info = {
|
|
||||||
'emoji_name': 'zulip',
|
|
||||||
'emoji_code': 'zulip',
|
|
||||||
'reaction_type': 'zulip_extra_emoji',
|
|
||||||
}
|
|
||||||
result = self.client_post('/api/v1/messages/%s/reactions' % (message_id,),
|
|
||||||
reaction_info,
|
|
||||||
**self.api_auth(sender))
|
|
||||||
return result
|
|
||||||
|
|
||||||
def test_add_zulip_emoji_reaction(self) -> None:
|
def test_add_zulip_emoji_reaction(self) -> None:
|
||||||
result = self.post_zulip_reaction()
|
result = self.post_zulip_reaction()
|
||||||
self.assert_json_success(result)
|
self.assert_json_success(result)
|
||||||
@@ -556,56 +571,14 @@ class ZulipExtraEmojiReactionTest(ZulipTestCase):
|
|||||||
result = self.post_zulip_reaction()
|
result = self.post_zulip_reaction()
|
||||||
self.assert_json_success(result)
|
self.assert_json_success(result)
|
||||||
|
|
||||||
sender = self.example_email('hamlet')
|
result = self.delete_zulip_reaction()
|
||||||
reaction_info = {
|
|
||||||
'emoji_name': 'zulip',
|
|
||||||
'emoji_code': 'zulip',
|
|
||||||
'reaction_type': 'zulip_extra_emoji',
|
|
||||||
}
|
|
||||||
result = self.client_delete('/api/v1/messages/1/reactions',
|
|
||||||
reaction_info,
|
|
||||||
**self.api_auth(sender))
|
|
||||||
self.assert_json_success(result)
|
self.assert_json_success(result)
|
||||||
|
|
||||||
def test_delete_non_existent_zulip_reaction(self) -> None:
|
def test_delete_non_existent_zulip_reaction(self) -> None:
|
||||||
sender = self.example_email('hamlet')
|
result = self.delete_zulip_reaction()
|
||||||
reaction_info = {
|
|
||||||
'emoji_name': 'zulip',
|
|
||||||
'emoji_code': 'zulip',
|
|
||||||
'reaction_type': 'zulip_extra_emoji',
|
|
||||||
}
|
|
||||||
result = self.client_delete('/api/v1/messages/1/reactions',
|
|
||||||
reaction_info,
|
|
||||||
**self.api_auth(sender))
|
|
||||||
self.assert_json_error(result, "Reaction doesn't exist.")
|
self.assert_json_error(result, "Reaction doesn't exist.")
|
||||||
|
|
||||||
class RealmEmojiReactionTests(ZulipTestCase):
|
class RealmEmojiReactionTests(EmojiReactionBase):
|
||||||
def post_reaction(self, reaction_info: Dict[str, str], message_id: int=1,
|
|
||||||
sender: str='hamlet') -> HttpResponse:
|
|
||||||
reaction_info['reaction_type'] = 'realm_emoji'
|
|
||||||
sender = self.example_email(sender)
|
|
||||||
result = self.client_post('/api/v1/messages/%s/reactions' % (message_id,),
|
|
||||||
reaction_info,
|
|
||||||
**self.api_auth(sender))
|
|
||||||
return result
|
|
||||||
|
|
||||||
def delete_reaction(self, reaction_info: Dict[str, str], message_id: int=1,
|
|
||||||
sender: str='hamlet') -> HttpResponse:
|
|
||||||
reaction_info['reaction_type'] = 'realm_emoji'
|
|
||||||
sender = self.example_email(sender)
|
|
||||||
result = self.client_delete('/api/v1/messages/%s/reactions' % (message_id,),
|
|
||||||
reaction_info,
|
|
||||||
**self.api_auth(sender))
|
|
||||||
return result
|
|
||||||
|
|
||||||
def get_message_reactions(self, message_id: int, emoji_code: Text,
|
|
||||||
reaction_type: Text) -> List[Reaction]:
|
|
||||||
message = Message.objects.get(id=message_id)
|
|
||||||
reactions = Reaction.objects.filter(message=message,
|
|
||||||
emoji_code=emoji_code,
|
|
||||||
reaction_type=reaction_type)
|
|
||||||
return list(reactions)
|
|
||||||
|
|
||||||
def test_add_realm_emoji(self) -> None:
|
def test_add_realm_emoji(self) -> None:
|
||||||
reaction_info = {
|
reaction_info = {
|
||||||
'emoji_name': 'green_tick',
|
'emoji_name': 'green_tick',
|
||||||
@@ -699,7 +672,7 @@ class RealmEmojiReactionTests(ZulipTestCase):
|
|||||||
**self.api_auth(sender))
|
**self.api_auth(sender))
|
||||||
self.assert_json_error(result, "Emoji for this emoji code not found.")
|
self.assert_json_error(result, "Emoji for this emoji code not found.")
|
||||||
|
|
||||||
class ReactionAPIEventTest(ZulipTestCase):
|
class ReactionAPIEventTest(EmojiReactionBase):
|
||||||
def test_add_event(self) -> None:
|
def test_add_event(self) -> None:
|
||||||
"""
|
"""
|
||||||
Recipients of the message receive the reaction event
|
Recipients of the message receive the reaction event
|
||||||
@@ -708,16 +681,8 @@ class ReactionAPIEventTest(ZulipTestCase):
|
|||||||
pm_sender = self.example_user('hamlet')
|
pm_sender = self.example_user('hamlet')
|
||||||
pm_recipient = self.example_user('othello')
|
pm_recipient = self.example_user('othello')
|
||||||
reaction_sender = pm_recipient
|
reaction_sender = pm_recipient
|
||||||
|
pm_id = self.send_personal_message(pm_sender.email, pm_recipient.email)
|
||||||
result = self.client_post("/api/v1/messages", {"type": "private",
|
|
||||||
"content": "Test message",
|
|
||||||
"to": pm_recipient.email},
|
|
||||||
**self.api_auth(pm_sender.email))
|
|
||||||
self.assert_json_success(result)
|
|
||||||
pm_id = result.json()['id']
|
|
||||||
|
|
||||||
expected_recipient_ids = set([pm_sender.id, pm_recipient.id])
|
expected_recipient_ids = set([pm_sender.id, pm_recipient.id])
|
||||||
|
|
||||||
reaction_info = {
|
reaction_info = {
|
||||||
'emoji_name': 'hamburger',
|
'emoji_name': 'hamburger',
|
||||||
'emoji_code': '1f354',
|
'emoji_code': '1f354',
|
||||||
@@ -725,9 +690,9 @@ class ReactionAPIEventTest(ZulipTestCase):
|
|||||||
}
|
}
|
||||||
events = [] # type: List[Mapping[str, Any]]
|
events = [] # type: List[Mapping[str, Any]]
|
||||||
with tornado_redirected_to_list(events):
|
with tornado_redirected_to_list(events):
|
||||||
result = self.client_post('/api/v1/messages/%s/reactions' % (pm_id,),
|
result = self.post_reaction(reaction_info,
|
||||||
reaction_info,
|
message_id=pm_id,
|
||||||
**self.api_auth(reaction_sender.email))
|
sender=reaction_sender.short_name)
|
||||||
self.assert_json_success(result)
|
self.assert_json_success(result)
|
||||||
self.assertEqual(len(events), 1)
|
self.assertEqual(len(events), 1)
|
||||||
|
|
||||||
@@ -753,32 +718,21 @@ class ReactionAPIEventTest(ZulipTestCase):
|
|||||||
pm_sender = self.example_user('hamlet')
|
pm_sender = self.example_user('hamlet')
|
||||||
pm_recipient = self.example_user('othello')
|
pm_recipient = self.example_user('othello')
|
||||||
reaction_sender = pm_recipient
|
reaction_sender = pm_recipient
|
||||||
|
pm_id = self.send_personal_message(pm_sender.email, pm_recipient.email)
|
||||||
result = self.client_post("/api/v1/messages", {"type": "private",
|
|
||||||
"content": "Test message",
|
|
||||||
"to": pm_recipient.email},
|
|
||||||
**self.api_auth(pm_sender.email))
|
|
||||||
self.assert_json_success(result)
|
|
||||||
content = result.json()
|
|
||||||
pm_id = content['id']
|
|
||||||
|
|
||||||
expected_recipient_ids = set([pm_sender.id, pm_recipient.id])
|
expected_recipient_ids = set([pm_sender.id, pm_recipient.id])
|
||||||
|
|
||||||
reaction_info = {
|
reaction_info = {
|
||||||
'emoji_name': 'hamburger',
|
'emoji_name': 'hamburger',
|
||||||
'emoji_code': '1f354',
|
'emoji_code': '1f354',
|
||||||
'reaction_type': 'unicode_emoji',
|
'reaction_type': 'unicode_emoji',
|
||||||
}
|
}
|
||||||
add = self.client_post('/api/v1/messages/%s/reactions' % (pm_id,),
|
add = self.post_reaction(reaction_info, message_id=pm_id, sender=reaction_sender.short_name)
|
||||||
reaction_info,
|
|
||||||
**self.api_auth(reaction_sender.email))
|
|
||||||
self.assert_json_success(add)
|
self.assert_json_success(add)
|
||||||
|
|
||||||
events = [] # type: List[Mapping[str, Any]]
|
events = [] # type: List[Mapping[str, Any]]
|
||||||
with tornado_redirected_to_list(events):
|
with tornado_redirected_to_list(events):
|
||||||
result = self.client_delete('/api/v1/messages/%s/reactions' % (pm_id,),
|
result = self.delete_reaction(reaction_info,
|
||||||
reaction_info,
|
message_id=pm_id,
|
||||||
**self.api_auth(reaction_sender.email))
|
sender=reaction_sender.short_name)
|
||||||
self.assert_json_success(result)
|
self.assert_json_success(result)
|
||||||
self.assertEqual(len(events), 1)
|
self.assertEqual(len(events), 1)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user