Changeset 129:29e517800b96 for wokkel/test
- Timestamp:
- Jun 4, 2009, 5:44:50 PM (13 years ago)
- Branch:
- wokkel-muc-client-support-24
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
wokkel/test/test_muc.py
r127 r129 1 # Copyright (c) 2003-200 8Ralph Meijer1 # Copyright (c) 2003-2009 Ralph Meijer 2 2 # See LICENSE for details. 3 3 … … 11 11 from twisted.internet import defer 12 12 from twisted.words.xish import domish, xpath 13 from twisted.words.protocols.jabber import error14 13 from twisted.words.protocols.jabber.jid import JID 15 14 16 from wokkel import data_form, iwokkel, muc, shim, disco 17 from wokkel.generic import parseXml 15 from wokkel import data_form, iwokkel, muc, disco 18 16 from wokkel.test.helpers import XmlStreamStub 19 17 20 try: 21 from twisted.words.protocols.jabber.xmlstream import toResponse 22 except ImportError: 23 from wokkel.compat import toResponse 18 from twisted.words.protocols.jabber.xmlstream import toResponse 24 19 25 20 … … 39 34 40 35 return d, func 36 41 37 42 38 … … 57 53 self.user_jid = JID('test@jabber.org/Testing') 58 54 55 59 56 def _createRoom(self): 60 57 """A helper method to create a test room. … … 81 78 """ 82 79 p = muc.UserPresence() 83 80 p['to'] = self.user_jid.full() 84 81 p['from'] = self.room_jid.full() 85 82 … … 90 87 self.failUnless(room.name==self.test_room, 'Wrong room name') 91 88 self.failUnless(room.inRoster(user), 'User not in roster') 92 93 89 90 94 91 d, self.protocol.userJoinedRoom = calledAsync(userPresence) 95 92 self.stub.send(p) … … 101 98 """ 102 99 m = muc.GroupChat('test@test.com',body='test') 103 100 m['from'] = self.room_jid.full() 104 101 105 102 self._createRoom() … … 108 105 self.failUnless(message=='test', "Wrong group chat message") 109 106 self.failUnless(room.name==self.test_room, 'Wrong room name') 110 111 107 108 112 109 d, self.protocol.receivedGroupChat = calledAsync(groupChat) 113 110 self.stub.send(m) … … 123 120 # check namespace 124 121 self.failUnless(query.uri==disco.NS_INFO, 'Wrong namespace') 125 122 126 123 127 124 d = self.protocol.disco(test_srv) … … 129 126 130 127 iq = self.stub.output[-1] 131 128 132 129 # send back a response 133 130 response = toResponse(iq, 'result') … … 138 135 name='Macbeth Chat Service', 139 136 type='text')) 140 141 self.stub.send(response) 142 return d 143 144 145 137 138 self.stub.send(response) 139 return d 140 141 146 142 def test_joinRoom(self): 147 143 """Joining a room 148 144 """ 149 145 150 146 def cb(room): 151 147 self.assertEquals(self.test_room, room.name) … … 158 154 self.failUnless(getattr(prs, 'x', None), 'No muc x element') 159 155 160 # send back user presence, they joined 156 # send back user presence, they joined 161 157 response = muc.UserPresence(frm=self.test_room+'@'+self.test_srv+'/'+self.test_nick) 162 158 self.stub.send(response) 163 159 return d 164 160 165 166 161 167 162 def test_joinRoomForbidden(self): … … 170 165 171 166 def cb(error): 172 167 173 168 self.failUnless(error.value.mucCondition=='forbidden','Wrong muc condition') 174 169 175 176 170 171 177 172 d = self.protocol.join(self.test_srv, self.test_room, self.test_nick) 178 173 d.addBoth(cb) … … 182 177 self.failUnless(getattr(prs, 'x', None), 'No muc x element') 183 178 # send back user presence, they joined 184 179 185 180 response = muc.PresenceError(error=muc.MUCError('auth', 186 181 'forbidden' … … 188 183 frm=self.room_jid.full()) 189 184 self.stub.send(response) 190 return d 185 return d 191 186 192 187 … … 196 191 197 192 def cb(error): 198 193 199 194 self.failUnless(error.value.mucCondition=='jid-malformed','Wrong muc condition') 200 195 201 202 196 197 203 198 d = self.protocol.join(self.test_srv, self.test_room, self.test_nick) 204 199 d.addBoth(cb) … … 208 203 self.failUnless(getattr(prs, 'x', None), 'No muc x element') 209 204 # send back user presence, they joined 210 205 211 206 response = muc.PresenceError(error=muc.MUCError('modify', 212 207 'jid-malformed' … … 214 209 frm=self.room_jid.full()) 215 210 self.stub.send(response) 216 return d 217 211 return d 218 212 219 213 … … 229 223 230 224 prs = self.stub.output[-1] 231 225 232 226 self.failUnless(prs['type']=='unavailable', 'Unavailable is not being sent') 233 227 234 228 response = prs 235 229 response['from'] = response['to'] … … 238 232 self.stub.send(response) 239 233 return d 240 234 241 235 242 236 def test_userPartsRoom(self): … … 245 239 246 240 p = muc.UnavailableUserPresence() 247 241 p['to'] = self.user_jid.full() 248 242 p['from'] = self.room_jid.full() 249 243 … … 259 253 self.failUnless(room.name==self.test_room, 'Wrong room name') 260 254 self.failUnless(room.inRoster(user)==False, 'User in roster') 261 255 262 256 d, self.protocol.userLeftRoom = calledAsync(userPresence) 263 257 self.stub.send(p) 264 258 return d 265 259 266 260 267 261 def test_ban(self): … … 272 266 self.failUnless(banned, 'Did not ban user') 273 267 274 268 275 269 d = self.protocol.ban(self.room_jid, banned, self.user_jid, reason='Spam') 276 270 d.addCallback(cb) 277 271 278 272 iq = self.stub.output[-1] 279 273 280 274 self.failUnless(xpath.matches("/iq[@type='set' and @to='%s']/query/item[@affiliation='outcast']" % (self.room_jid.userhost(),), iq), 'Wrong ban stanza') 281 275 … … 294 288 self.failUnless(kicked, 'Did not kick user') 295 289 296 290 297 291 d = self.protocol.kick(self.room_jid, kicked, self.user_jid, reason='Spam') 298 292 d.addCallback(cb) 299 293 300 294 iq = self.stub.output[-1] 301 295 302 296 self.failUnless(xpath.matches("/iq[@type='set' and @to='%s']/query/item[@affiliation='none']" % (self.room_jid.userhost(),), iq), 'Wrong kick stanza') 303 297 … … 308 302 return d 309 303 310 311 304 312 305 def test_password(self): 313 306 """Sending a password via presence to a password protected room. 314 307 """ 315 308 316 309 self.protocol.password(self.room_jid, 'secret') 317 318 prs = self.stub.output[-1] 319 310 311 prs = self.stub.output[-1] 312 320 313 self.failUnless(xpath.matches("/presence[@to='%s']/x/password[text()='secret']" % (self.room_jid.full(),), prs), 'Wrong presence stanza') 321 314 … … 325 318 """ 326 319 m = muc.HistoryMessage(self.room_jid.userhost(), self.protocol._makeTimeStamp(), body='test') 327 328 320 m['from'] = self.room_jid.full() 321 329 322 self._createRoom() 330 323 … … 332 325 self.failUnless(body=='test', "wrong message body") 333 326 self.failUnless(stamp, 'Does not have a history stamp') 334 327 335 328 336 329 d, self.protocol.receivedHistory = calledAsync(roomHistory) … … 369 362 self.failUnless(m.name=='message', 'Wrong stanza') 370 363 self.failUnless(xpath.matches("/message/delay", m), 'Invalid history stanza') 371 364 372 365 373 366 def test_invite(self): … … 383 376 384 377 385 386 378 def test_privateMessage(self): 387 379 """Send private messages to muc entities. … … 400 392 401 393 """ 402 394 403 395 def cb(iq): 404 396 # check for a result 405 397 self.failUnless(iq['type']=='result', 'We did not get a result') 406 398 407 399 d = self.protocol.register(self.room_jid) 408 400 d.addCallback(cb) … … 410 402 iq = self.stub.output[-1] 411 403 self.failUnless(xpath.matches("/iq/query[@xmlns='%s']" % (muc.NS_REQUEST), iq), 'Invalid iq register request') 412 413 response = toResponse(iq, 'result') 414 415 self.stub.send(response) 416 return d 404 405 response = toResponse(iq, 'result') 406 407 self.stub.send(response) 408 return d 409 417 410 418 411 def test_voice(self): … … 422 415 423 416 m = self.stub.output[-1] 424 417 425 418 self.failUnless(xpath.matches("/message/x[@type='submit']/field/value[text()='%s']" % (muc.NS_MUC_REQUEST,), m), 'Invalid voice message stanza') 426 419 … … 432 425 def cb(iq): 433 426 self.failUnless(iq['type']=='result', 'Not a result') 434 427 435 428 436 429 fields = [] … … 439 432 var='muc#roomconfig_roomname', 440 433 value=self.test_room)) 441 434 442 435 d = self.protocol.configure(self.room_jid.userhost(), fields) 443 436 d.addCallback(cb) … … 445 438 iq = self.stub.output[-1] 446 439 self.failUnless(xpath.matches("/iq/query[@xmlns='%s']/x"% (muc.NS_MUC_OWNER,), iq), 'Bad configure request') 447 440 448 441 response = toResponse(iq, 'result') 449 442 self.stub.send(response) … … 457 450 def cb(destroyed): 458 451 self.failUnless(destroyed==True, 'Room not destroyed.') 459 452 460 453 d = self.protocol.destroy(self.room_jid) 461 454 d.addCallback(cb) … … 463 456 iq = self.stub.output[-1] 464 457 self.failUnless(xpath.matches("/iq/query[@xmlns='%s']/destroy"% (muc.NS_MUC_OWNER,), iq), 'Bad configure request') 465 458 466 459 response = toResponse(iq, 'result') 467 460 self.stub.send(response) … … 473 466 """ 474 467 test_nick = 'newNick' 475 468 476 469 self._createRoom() 477 470 … … 487 480 self.failUnless(getattr(prs, 'x', None), 'No muc x element') 488 481 489 # send back user presence, they joined 482 # send back user presence, they joined 490 483 response = muc.UserPresence(frm=self.test_room+'@'+self.test_srv+'/'+test_nick) 491 492 self.stub.send(response) 493 return d 484 485 self.stub.send(response) 486 return d 487 494 488 495 489 def test_grantVoice(self): … … 501 495 self.failUnless(give_voice, 'Did not give voice user') 502 496 503 497 504 498 d = self.protocol.grantVoice(self.user_jid, self.room_jid, give_voice) 505 499 d.addCallback(cb) 506 500 507 501 iq = self.stub.output[-1] 508 502 509 503 self.failUnless(xpath.matches("/iq[@type='set' and @to='%s']/query/item[@role='participant']" % (self.room_jid.userhost(),), iq), 'Wrong voice stanza') 510 504 … … 530 524 self.failUnless(u.status == 'testing MUC', 'Wrong status') 531 525 self.failUnless(u.show == 'xa', 'Wrong show') 532 526 533 527 d = self.protocol.status(self.room_jid, 'xa', 'testing MUC') 534 528 d.addCallback(cb) … … 539 533 self.failUnless(getattr(prs, 'x', None), 'No muc x element') 540 534 541 # send back user presence, they joined 535 # send back user presence, they joined 542 536 response = muc.UserPresence(frm=self.room_jid.full()) 543 537 response.addElement('show', None, 'xa') 544 538 response.addElement('status', None, 'testing MUC') 545 539 self.stub.send(response) 546 return d 540 return d
Note: See TracChangeset
for help on using the changeset viewer.