1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
"""
Slixmpp: The Slick XMPP Library
Copyright (C) 2020 Mathieu Pasquet
This file is part of Slixmpp.
See the file LICENSE for copying permission.
"""
import unittest
from slixmpp import Message
from slixmpp.test import SlixTest
from slixmpp.plugins.xep_0444 import XEP_0444
import slixmpp.plugins.xep_0444.stanza as stanza
from slixmpp.xmlstream import register_stanza_plugin
class TestReactions(SlixTest):
def setUp(self):
register_stanza_plugin(Message, stanza.Reactions)
register_stanza_plugin(stanza.Reactions, stanza.Reaction)
def testCreateReactions(self):
"""Testing creating Reactions."""
xmlstring = """
<message>
<reactions xmlns="urn:xmpp:reactions:0" id="abcd">
<reaction>😃</reaction>
<reaction>🤗</reaction>
</reactions>
</message>
"""
msg = self.Message()
msg['reactions']['id'] = 'abcd'
msg['reactions']['values'] = ['😃', '🤗']
self.check(msg, xmlstring, use_values=False)
self.assertEqual({'😃', '🤗'}, msg['reactions']['values'])
def testCreateReactionsUnrestricted(self):
"""Testing creating Reactions with the extra all_chars arg."""
try:
import emoji
except ImportError:
# No emoji package: this test does not make sense
return
xmlstring = """
<message>
<reactions xmlns="urn:xmpp:reactions:0" id="abcd">
<reaction>😃</reaction>
<reaction>🤗</reaction>
<reaction>toto</reaction>
</reactions>
</message>
"""
msg = self.Message()
msg['reactions']['id'] = 'abcd'
msg['reactions'].set_values(['😃', '🤗', 'toto'], all_chars=True)
self.check(msg, xmlstring, use_values=False)
self.assertEqual({'😃', '🤗'}, msg['reactions']['values'])
self.assertEqual({'😃', '🤗', 'toto'}, msg['reactions'].get_values(all_chars=True))
with self.assertRaises(ValueError):
msg['reactions'].set_values(['😃', '🤗', 'toto'], all_chars=False)
suite = unittest.TestLoader().loadTestsFromTestCase(TestReactions)
|