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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
import unittest
from slixmpp import Message, Presence, Iq, JID
from slixmpp.test import SlixTest
from slixmpp.plugins.xep_0045.stanza import (
MUCPresence,
MUCJoin,
MUCMessage,
MUCAdminQuery,
MUCAdminItem,
MUCHistory,
MUCOwnerQuery,
MUCOwnerDestroy,
MUCStatus,
MUCInvite,
MUCDecline,
MUCUserItem,
MUCActor,
)
from slixmpp.xmlstream import register_stanza_plugin, ET
class TestMUC(SlixTest):
def setUp(self):
register_stanza_plugin(MUCPresence, MUCUserItem)
register_stanza_plugin(MUCMessage, MUCUserItem)
register_stanza_plugin(MUCUserItem, MUCActor)
register_stanza_plugin(MUCMessage, MUCInvite)
register_stanza_plugin(MUCMessage, MUCDecline)
register_stanza_plugin(MUCMessage, MUCStatus)
register_stanza_plugin(MUCPresence, MUCStatus)
register_stanza_plugin(Presence, MUCPresence)
register_stanza_plugin(Presence, MUCJoin)
register_stanza_plugin(MUCJoin, MUCHistory)
register_stanza_plugin(Message, MUCMessage)
register_stanza_plugin(Iq, MUCAdminQuery)
register_stanza_plugin(Iq, MUCOwnerQuery)
register_stanza_plugin(MUCOwnerQuery, MUCOwnerDestroy)
register_stanza_plugin(MUCAdminQuery, MUCAdminItem, iterable=True)
def testPresence(self):
presence = Presence()
presence['from'] = JID('muc@service/nick')
presence['muc']['item']['affiliation'] = 'member'
presence['muc']['item']['role'] = 'participant'
presence['muc']['status_codes'] = (100, 110, 210)
self.check(presence, """
<presence from='muc@service/nick'>
<x xmlns='http://jabber.org/protocol/muc#user'>
<item affiliation='member' role='participant'/>
<status code='100'/>
<status code='110'/>
<status code='210'/>
</x>
</presence>
""", use_values=False)
def testPresenceReason(self):
presence = Presence()
presence['from'] = JID('muc@service/nick')
presence['muc']['item']['affiliation'] = 'member'
presence['muc']['item']['role'] = 'participant'
presence['muc']['item']['reason'] = 'coucou'
presence['muc']['item']['actor']['nick'] = 'JPR'
self.check(presence, """
<presence from='muc@service/nick'>
<x xmlns='http://jabber.org/protocol/muc#user'>
<item affiliation='member' role='participant'>
<actor nick="JPR"/>
<reason>coucou</reason>
</item>
</x>
</presence>
""", use_values=False)
def testPresenceLegacy(self):
presence = Presence()
presence['from'] = JID('muc@service/nick')
presence['muc']['affiliation'] = 'member'
presence['muc']['role'] = 'participant'
presence['muc']['status_codes'] = (100, 110, 210)
self.check(presence, """
<presence from='muc@service/nick'>
<x xmlns='http://jabber.org/protocol/muc#user'>
<item affiliation='member' role='participant'/>
<status code='100'/>
<status code='110'/>
<status code='210'/>
</x>
</presence>
""", use_values=False)
def testInvite(self):
message = Message()
message['from'] = 'user@server'
message['to'] = 'muc@service'
message['muc']['invite']['to'] = JID('user2@server2')
message['muc']['invite']['reason'] = 'Hey'
self.check(message, """
<message
from='user@server'
to='muc@service'>
<x xmlns='http://jabber.org/protocol/muc#user'>
<invite to='user2@server2'>
<reason>Hey</reason>
</invite>
</x>
</message>
""", use_values=False)
def testAdmin(self):
iq = Iq()
iq['id'] = '0'
iq['type'] = 'set'
iq.enable('mucadmin_query')
items = [
('none', 'test@example/a'),
('owner', 'owner@example/a'),
]
for aff, jid in items:
item_el = MUCAdminItem()
item_el['affiliation'] = aff
item_el['jid'] = jid
iq['mucadmin_query'].append(item_el)
self.check(iq, """
<iq type='set' id='0'>
<query xmlns='http://jabber.org/protocol/muc#admin'>
<item jid='test@example/a'
affiliation='none'/>
<item jid='owner@example/a'
affiliation='owner'/>
</query>
</iq>
""", use_values=False)
def testSetAffiliation(self):
iq = Iq()
iq['type'] = 'set'
iq['id'] = '1'
iq['mucadmin_query']['item']['jid'] = JID('test@example.com')
iq['mucadmin_query']['item']['affiliation'] = 'owner'
self.check(iq, """
<iq type='set' id='1'>
<query xmlns='http://jabber.org/protocol/muc#admin'>
<item jid='test@example.com'
affiliation='owner'/>
</query>
</iq>
""", use_values=False)
suite = unittest.TestLoader().loadTestsFromTestCase(TestMUC)
|