11from collections import OrderedDict , defaultdict
22from datetime import date
3+ from unittest .mock import patch
34
45import pytest
56import pytz
@@ -1597,60 +1598,6 @@ def test_transform_content(self, mocker, raw_html, expected_content):
15971598 @pytest .mark .parametrize (
15981599 "to_vary_in_each_message, expected_text, expected_attributes" ,
15991600 [
1600- case (
1601- {
1602- "reactions" : [
1603- {
1604- "emoji_name" : "thumbs_up" ,
1605- "emoji_code" : "1f44d" ,
1606- "user" : {
1607- "email" : "iago@zulip.com" ,
1608- "full_name" : "Iago" ,
1609- "id" : 5 ,
1610- },
1611- "reaction_type" : "unicode_emoji" ,
1612- },
1613- {
1614- "emoji_name" : "zulip" ,
1615- "emoji_code" : "zulip" ,
1616- "user" : {
1617- "email" : "iago@zulip.com" ,
1618- "full_name" : "Iago" ,
1619- "id" : 5 ,
1620- },
1621- "reaction_type" : "zulip_extra_emoji" ,
1622- },
1623- {
1624- "emoji_name" : "zulip" ,
1625- "emoji_code" : "zulip" ,
1626- "user" : {
1627- "email" : "AARON@zulip.com" ,
1628- "full_name" : "aaron" ,
1629- "id" : 1 ,
1630- },
1631- "reaction_type" : "zulip_extra_emoji" ,
1632- },
1633- {
1634- "emoji_name" : "heart" ,
1635- "emoji_code" : "2764" ,
1636- "user" : {
1637- "email" : "iago@zulip.com" ,
1638- "full_name" : "Iago" ,
1639- "id" : 5 ,
1640- },
1641- "reaction_type" : "unicode_emoji" ,
1642- },
1643- ],
1644- },
1645- " :thumbs_up: 1 :zulip: 2 :heart: 1 " ,
1646- [
1647- ("reaction" , 15 ),
1648- (None , 1 ),
1649- ("reaction_mine" , 11 ),
1650- (None , 1 ),
1651- ("reaction" , 11 ),
1652- ],
1653- ),
16541601 case (
16551602 {
16561603 "reactions" : [
@@ -1701,31 +1648,19 @@ def test_transform_content(self, mocker, raw_html, expected_content):
17011648 {
17021649 "emoji_name" : "zulip" ,
17031650 "emoji_code" : "zulip" ,
1704- "user" : {
1705- "email" : "iago@zulip.com" ,
1706- "full_name" : "Iago" ,
1707- "id" : 5 ,
1708- },
1651+ "user_id" : 5 ,
17091652 "reaction_type" : "unicode_emoji" ,
17101653 },
17111654 {
17121655 "emoji_name" : "zulip" ,
17131656 "emoji_code" : "zulip" ,
1714- "user" : {
1715- "email" : "AARON@zulip.com" ,
1716- "full_name" : "aaron" ,
1717- "id" : 1 ,
1718- },
1657+ "user_id" : 1 ,
17191658 "reaction_type" : "zulip_extra_emoji" ,
17201659 },
17211660 {
17221661 "emoji_name" : "zulip" ,
17231662 "emoji_code" : "zulip" ,
1724- "user" : {
1725- "email" : "shivam@zulip.com" ,
1726- "full_name" : "Shivam" ,
1727- "id" : 6 ,
1728- },
1663+ "user_id" : 6 ,
17291664 "reaction_type" : "unicode_emoji" ,
17301665 },
17311666 ],
@@ -1741,31 +1676,19 @@ def test_transform_content(self, mocker, raw_html, expected_content):
17411676 {
17421677 "emoji_name" : "heart" ,
17431678 "emoji_code" : "2764" ,
1744- "user" : {
1745- "email" : "iago@zulip.com" ,
1746- "full_name" : "Iago" ,
1747- "id" : 5 ,
1748- },
1679+ "user_id" : 5 ,
17491680 "reaction_type" : "unicode_emoji" ,
17501681 },
17511682 {
17521683 "emoji_name" : "zulip" ,
17531684 "emoji_code" : "zulip" ,
1754- "user" : {
1755- "email" : "AARON@zulip.com" ,
1756- "full_name" : "aaron" ,
1757- "id" : 1 ,
1758- },
1685+ "user_id" : 1 ,
17591686 "reaction_type" : "zulip_extra_emoji" ,
17601687 },
17611688 {
17621689 "emoji_name" : "zulip" ,
17631690 "emoji_code" : "zulip" ,
1764- "user" : {
1765- "email" : "shivam@zulip.com" ,
1766- "full_name" : "Shivam" ,
1767- "id" : 6 ,
1768- },
1691+ "user_id" : 6 ,
17691692 "reaction_type" : "unicode_emoji" ,
17701693 },
17711694 ],
@@ -1821,10 +1744,26 @@ def test_reactions_view(
18211744 msg_box = MessageBox (varied_message , self .model , None )
18221745 reactions = to_vary_in_each_message ["reactions" ]
18231746
1824- reactions_view = msg_box .reactions_view (reactions )
1747+ mock_all_users_by_id = {
1748+ 1 : {"full_name" : "aaron" },
1749+ 5 : {"full_name" : "Iago" },
1750+ 6 : {"full_name" : "Shivam" },
1751+ }
1752+
1753+ def mock_get_user_id (reaction ):
1754+ if "user_id" in reaction :
1755+ return reaction ["user_id" ]
1756+ return reaction ["user" ]["id" ]
1757+
1758+ with patch .object (
1759+ self .model ,
1760+ "get_user_id_from_reaction" ,
1761+ side_effect = mock_get_user_id ,
1762+ ), patch .object (self .model , "_all_users_by_id" , mock_all_users_by_id ):
1763+ reactions_view = msg_box .reactions_view (reactions )
18251764
1826- assert reactions_view .original_widget .text == expected_text
1827- assert reactions_view .original_widget .attrib == expected_attributes
1765+ assert reactions_view .original_widget .text == expected_text
1766+ assert reactions_view .original_widget .attrib == expected_attributes
18281767
18291768 @pytest .mark .parametrize (
18301769 "message_links, expected_text, expected_attrib, expected_footlinks_width" ,
0 commit comments