Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/python-nbxmpp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorNicoco <nicoco@nicoco.fr>2022-12-09 12:59:46 +0300
committerPhilipp HΓΆrist <philipp@hoerist.com>2022-12-09 12:59:46 +0300
commit8293ab4cbeb94bd25525a119f3a53ef4beb5f80f (patch)
tree4fe5a9f0988204977fb052c91d2b1df2e3a817f0 /test
parent6f31072892ff530322f06c7d27ce22473483f932 (diff)
feat: Add message reactions (XEP-0444) support
Diffstat (limited to 'test')
-rw-r--r--test/unit/test_reactions.py137
1 files changed, 137 insertions, 0 deletions
diff --git a/test/unit/test_reactions.py b/test/unit/test_reactions.py
new file mode 100644
index 0000000..1db2952
--- /dev/null
+++ b/test/unit/test_reactions.py
@@ -0,0 +1,137 @@
+from test.lib.util import StanzaHandlerTest
+
+from nbxmpp.structs import Reactions as ReactionStruct
+from nbxmpp.modules.reactions import Reactions
+from nbxmpp.protocol import Message
+
+
+class MockLog:
+ @staticmethod
+ def warning(_):
+ pass
+
+
+class MockModule:
+ _log = MockLog
+
+ @staticmethod
+ def is_emoji(s):
+ return Reactions.is_emoji(s)
+
+
+class ReactionsTest(StanzaHandlerTest):
+ def test_reaction_parsing(self):
+ class P:
+ reactions: ReactionStruct
+
+ xml = '''
+ <message to='romeo@capulet.net/orchard' id='96d73204-a57a-11e9-88b8-4889e7820c76' type='chat'>
+ <reactions id='744f6e18-a57a-11e9-a656-4889e7820c76' xmlns='urn:xmpp:reactions:0'>
+ <reaction>πŸ‘‹
+ </reaction>
+ <reaction>🐒</reaction>
+ </reactions>
+ <store xmlns='urn:xmpp:hints'/>
+ </message>
+ '''
+ msg = Message(node=xml)
+ Reactions._process_message_reaction(MockModule, self, msg, P)
+
+ self.assertEqual(P.reactions.id, '744f6e18-a57a-11e9-a656-4889e7820c76')
+ self.assertEqual(P.reactions.emojis, {'πŸ‘‹', '🐒'})
+
+ def test_no_reactions(self):
+ class P:
+ reactions: ReactionStruct = None
+
+ xml = '''
+ <message to='romeo@capulet.net/orchard' id='96d73204-a57a-11e9-88b8-4889e7820c76' type='chat'>
+ <store xmlns='urn:xmpp:hints'/>
+ </message>
+ '''
+ msg = Message(node=xml)
+ Reactions._process_message_reaction(MockModule, self, msg, P)
+
+ self.assertIsNone(P.reactions)
+
+ def test_empty_reactions(self):
+ class P:
+ reactions: ReactionStruct
+
+ xml = '''
+ <message to='romeo@capulet.net/orchard' id='96d73204-a57a-11e9-88b8-4889e7820c76' type='chat'>
+ <reactions id='744f6e18-a57a-11e9-a656-4889e7820c76' xmlns='urn:xmpp:reactions:0' />
+ <store xmlns='urn:xmpp:hints'/>
+ </message>
+ '''
+ msg = Message(node=xml)
+ Reactions._process_message_reaction(MockModule, self, msg, P)
+
+ self.assertEqual(len(P.reactions.emojis), 0)
+
+ def test_invalid_reactions_no_id(self):
+ class P:
+ reactions: ReactionStruct
+
+ xml = '''
+ <message to='romeo@capulet.net/orchard' id='96d73204-a57a-11e9-88b8-4889e7820c76' type='chat'>
+ <reactions xmlns='urn:xmpp:reactions:0'>
+ <reaction>πŸ‘‹</reaction>
+ <reaction>🐒</reaction>
+ </reactions>
+ <store xmlns='urn:xmpp:hints'/>
+ </message>
+ '''
+ msg = Message(node=xml)
+ Reactions._process_message_reaction(MockModule, self, msg, P)
+ self.assertFalse(hasattr(P, 'reactions'))
+
+ def test_invalid_reactions_empty_id(self):
+ class P:
+ reactions: ReactionStruct
+
+ xml = '''
+ <message to='romeo@capulet.net/orchard' id='96d73204-a57a-11e9-88b8-4889e7820c76' type='chat'>
+ <reactions id='' xmlns='urn:xmpp:reactions:0'>
+ <reaction>πŸ‘‹</reaction>
+ <reaction>🐒</reaction>
+ </reactions>
+ <store xmlns='urn:xmpp:hints'/>
+ </message>
+ '''
+ msg = Message(node=xml)
+ Reactions._process_message_reaction(MockModule, self, msg, P)
+ self.assertFalse(hasattr(P, 'reactions'))
+
+ def test_invalid_reactions_empty_emoji(self):
+ class P:
+ reactions: ReactionStruct
+
+ xml = '''
+ <message to='romeo@capulet.net/orchard' id='96d73204-a57a-11e9-88b8-4889e7820c76' type='chat'>
+ <reactions id='sadfsadf' xmlns='urn:xmpp:reactions:0'>
+ <reaction></reaction>
+ <reaction>🐒</reaction>
+ </reactions>
+ <store xmlns='urn:xmpp:hints'/>
+ </message>
+ '''
+ msg = Message(node=xml)
+ Reactions._process_message_reaction(MockModule, self, msg, P)
+ self.assertEqual(P.reactions.emojis, {'🐒'})
+
+ def test_set_reactions(self):
+ x = Message()
+ x.setReactions('id', '🐒')
+ self.assertEqual(x.getReactions(), ('id', {'🐒'}))
+
+ x = Message()
+ x.setReactions('id', 'πŸ’πŸ‘‹')
+ self.assertEqual(x.getReactions(), ('id', {'🐒', 'πŸ‘‹'}))
+
+ x = Message()
+ x.setReactions('id', '')
+ self.assertEqual(x.getReactions(), ('id', set()))
+
+ x = Message()
+ self.assertIsNone(x.getReactions())