Changeset 145:216c953d8ecd
- Timestamp:
- Aug 8, 2011, 1:43:09 PM (11 years ago)
- Branch:
- wokkel-muc-client-support-24
- Location:
- wokkel
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
wokkel/muc.py
r144 r145 10 10 U{XEP-0045<http://www.xmpp.org/extensions/xep-0045.html>}. 11 11 """ 12 import datetime13 12 from dateutil.tz import tzutc 14 13 15 14 from zope.interface import implements 16 15 17 from twisted.internet import defer , reactor16 from twisted.internet import defer 18 17 from twisted.words.protocols.jabber import jid, error, xmlstream 19 18 from twisted.words.xish import domish … … 39 38 PRESENCE = '/presence' 40 39 41 GROUPCHAT = MESSAGE +'[@type="groupchat"]/body' 42 SUBJECT = MESSAGE +'[@type="groupchat"]/subject' 40 GROUPCHAT = MESSAGE +'[@type="groupchat"]' 43 41 44 42 DEFER_TIMEOUT = 30 # basic timeout is 30 seconds … … 263 261 def toElement(self): 264 262 """ 265 Returns a L{domish.Element} representing the xml for thehistory options.263 Returns a L{domish.Element} representing the history options. 266 264 """ 267 265 element = domish.Element((NS_MUC, 'history')) … … 315 313 @type state: L{int} 316 314 317 @ivar occupantJID: The JID of the occupant in the room. Generated from roomIdentifier, service, and nick. 315 @ivar occupantJID: The JID of the occupant in the room. Generated from 316 roomIdentifier, service, and nick. 318 317 @type occupantJID: L{jid.JID} 319 318 """ … … 460 459 timeout = None 461 460 462 def __init__(self):463 XMPPHandler.__init__(self)464 465 self._rooms = {}466 self._deferreds = []467 468 461 presenceTypeParserMap = { 469 462 'error': generic.ErrorStanza, … … 472 465 } 473 466 467 def __init__(self, reactor=None): 468 XMPPHandler.__init__(self) 469 470 self._rooms = {} 471 self._deferreds = [] 472 473 if reactor: 474 self._reactor = reactor 475 else: 476 from twisted.internet import reactor 477 self._reactor = reactor 478 479 474 480 def connectionInitialized(self): 475 481 """ … … 481 487 """ 482 488 xmppim.BasePresenceProtocol.connectionInitialized(self) 483 484 489 self.xmlstream.addObserver(GROUPCHAT, self._onGroupChat) 485 self.xmlstream.addObserver(SUBJECT, self._onSubject)486 # TODO: add history487 488 490 self.initialized() 489 491 … … 502 504 503 505 504 def _getRoom(self, occupantJID):506 def _getRoom(self, roomJID): 505 507 """ 506 508 Grab a room from the room collection. … … 511 513 @type occupantJID: L{jid.JID} 512 514 """ 513 roomJID = occupantJID.userhostJID()514 515 return self._rooms.get(roomJID) 515 516 … … 550 551 self._userLeavesRoom(occupantJID) 551 552 553 552 554 def _userLeavesRoom(self, occupantJID): 553 555 # when a user leaves a room we need to update it 554 room = self._getRoom(occupantJID )556 room = self._getRoom(occupantJID.userhostJID()) 555 557 if room is None: 556 558 # not in the room yet … … 576 578 577 579 # grab room 578 room = self._getRoom(occupantJID )580 room = self._getRoom(occupantJID.userhostJID()) 579 581 if room is None: 580 582 # not in the room yet … … 600 602 A group chat message has been received from a MUC room. 601 603 602 There are a few event methods that may get called here. receviedGroupChat and receivedHistory 604 There are a few event methods that may get called here. 605 L{receivedGroupChat}, L{receivedHistory} or L{receivedHistory}. 603 606 """ 604 607 message = GroupChat.fromElement(element) 605 608 606 609 occupantJID = message.sender 607 608 610 if not occupantJID: 609 # need to return an error here XXX610 611 return 611 612 612 room = self._getRoom(occupantJID) 613 roomJID = occupantJID.userhostJID() 614 615 room = self._getRoom(roomJID) 613 616 if room is None: 614 617 # not in the room yet … … 621 624 user = None 622 625 623 if message.delay is None: 626 if message.subject: 627 self.receivedSubject(room, user, message.subject) 628 elif message.delay is None: 624 629 self.receivedGroupChat(room, user, message) 625 630 else: … … 627 632 628 633 629 def _onSubject(self, msg): 630 """ 631 A subject has been sent from a MUC room. 632 """ 633 if not msg.hasAttribute('from'): 634 return 635 occupantJID = jid.internJID(msg['from']) 636 637 # grab room 638 room = self._getRoom(occupantJID) 639 if room is None: 640 # not in the room yet 641 return 642 643 self.receivedSubject(occupantJID, unicode(msg.subject)) 644 645 646 def _makeTimeStamp(self, stamp=None): 647 # create a timestamp 648 if stamp is None: 649 stamp = datetime.datetime.now() 650 651 return stamp.strftime('%Y%m%dT%H:%M:%S') 652 653 654 def _joinedRoom(self, d, prs): 634 def _joinedRoom(self, presence): 655 635 """ 656 636 We have presence that says we joined a room. 657 637 """ 658 occupantJID = jid.internJID(prs['from']) 659 660 # check for errors 661 if prs.hasAttribute('type') and prs['type'] == 'error': 662 d.errback(error.exceptionFromStanza(prs)) 663 else: 664 # change the state of the room 665 room = self._getRoom(occupantJID) 666 room.state = 'joined' 667 668 # grab status 669 status = getattr(prs.x, 'status', None) 670 if status: 671 room.status = status.getAttribute('code', None) 672 673 d.callback(room) 674 675 676 def _leftRoom(self, d, prs): 638 roomJID = presence.sender.userhostJID() 639 640 # change the state of the room 641 room = self._getRoom(roomJID) 642 room.state = 'joined' 643 644 # grab status 645 if presence.statusCode: 646 room.status = presence.statusCode 647 648 return room 649 650 651 def _leftRoom(self, presence): 677 652 """ 678 653 We have presence that says we left a room. 679 654 """ 680 occupantJID = jid.internJID(prs['from']) 681 682 # check for errors 683 if prs.hasAttribute('type') and prs['type'] == 'error': 684 d.errback(error.exceptionFromStanza(prs)) 685 else: 686 # change the state of the room 687 self._removeRoom(occupantJID) 688 689 d.callback(True) 655 occupantJID = presence.sender 656 657 # change the state of the room 658 self._removeRoom(occupantJID) 659 660 return True 690 661 691 662 … … 785 756 786 757 787 def sendDeferred(self, obj, timeout): 788 """ 789 Send data or a domish element, adding a deferred with a timeout. 790 791 @param obj: The object to send over the wire. 792 @type obj: L{domish.Element} or C{unicode} 793 794 @param timeout: The number of seconds to wait before the deferred is timed out. 758 def sendDeferred(self, stanza): 759 """ 760 Send presence stanza, adding a deferred with a timeout. 761 762 @param stanza: The presence stanza to send over the wire. 763 @type stanza: L{generic.Stanza} 764 765 @param timeout: The number of seconds to wait before the deferred is 766 timed out. 795 767 @type timeout: L{int} 796 768 … … 798 770 """ 799 771 d = defer.Deferred() 800 self._deferreds.append(d) 801 772 773 def onResponse(element): 774 if element.getAttribute('type') == 'error': 775 d.errback(error.exceptionFromStanza(element)) 776 else: 777 d.callback(UserPresence.fromElement(element)) 802 778 803 779 def onTimeout(): 804 i = 0 805 for xd in self._deferreds: 806 if d == xd: 807 self._deferreds.pop(i) 808 d.errback(xmlstream.TimeoutError("Timeout waiting for response.")) 809 i += 1 810 811 call = reactor.callLater(timeout, onTimeout) 780 d.errback(xmlstream.TimeoutError("Timeout waiting for response.")) 781 782 call = self._reactor.callLater(DEFER_TIMEOUT, onTimeout) 812 783 813 784 def cancelTimeout(result): … … 819 790 d.addBoth(cancelTimeout) 820 791 821 self.xmlstream.send(obj) 792 query = "/presence[@from='%s' or (@from='%s' and @type='error')]" % ( 793 stanza.recipient.full(), stanza.recipient.userhost()) 794 self.xmlstream.addOnetimeObserver(query, onResponse, priority=1) 795 self.xmlstream.send(stanza.toElement()) 822 796 return d 823 797 … … 841 815 def getConfigureForm(self, roomJID): 842 816 """ 843 Grab the configuration form from the room. This sends an iq request to the room. 817 Grab the configuration form from the room. 818 819 This sends an iq request to the room. 844 820 845 821 @param roomJID: The bare JID of the room. … … 876 852 presence.history = HistoryOptions(maxstanzas=history) 877 853 878 d = self.sendDeferred(presence.toElement(), timeout=DEFER_TIMEOUT) 879 880 # add observer for joining the room 881 query = PRESENCE + u"[@from='%s']" % room.occupantJID 882 self.xmlstream.addOnetimeObserver(query, self._joinedRoom, 1, d) 883 854 d = self.sendDeferred(presence) 855 d.addCallback(self._joinedRoom) 884 856 return d 885 857 … … 903 875 904 876 905 def _changed(self, d, occupantJID, prs):877 def _changed(self, presence, occupantJID): 906 878 """ 907 879 Callback for changing the nick and status. 908 880 """ 909 910 status = getattr(prs, 'status', None) 911 show = getattr(prs, 'show', None) 912 913 room = self._getRoom(occupantJID) 914 915 user = self._changeUserStatus(room, occupantJID, status, show) 916 917 d.callback(room) 881 room = self._getRoom(occupantJID.userhostJID()) 882 self._changeUserStatus(room, occupantJID, presence.status, presence.show) 883 884 return room 918 885 919 886 … … 930 897 @type nick: C{unicode} 931 898 """ 932 933 934 899 room = self._getRoom(roomJID) 935 900 … … 939 904 # Create presence 940 905 presence = BasicPresence(recipient=room.occupantJID) 941 d = self.sendDeferred(presence.toElement(), timeout=DEFER_TIMEOUT) 942 943 # Add observer for joining the room 944 query = PRESENCE+"[@from='%s']" % (room.occupantJID.full()) 945 self.xmlstream.addOnetimeObserver(query, self._changed, 1, d, roomJID) 946 906 907 d = self.sendDeferred(presence) 908 d.addCallback(self._changed, room.occupantJID) 947 909 return d 948 910 949 911 950 def leave(self, occupantJID):912 def leave(self, roomJID): 951 913 """ 952 914 Leave a MUC room. … … 954 916 See: http://xmpp.org/extensions/xep-0045.html#exit 955 917 956 @param occupantJID: The Room JID of the room to leave.957 @type occupantJID: L{jid.JID}958 """ 959 room = self._getRoom( occupantJID)918 @param roomJID: The Room JID of the room to leave. 919 @type roomJID: L{jid.JID} 920 """ 921 room = self._getRoom(roomJID) 960 922 961 923 presence = xmppim.AvailabilityPresence(recipient=room.occupantJID, 962 924 available=False) 963 925 964 d = self.sendDeferred(presence.toElement(), timeout=DEFER_TIMEOUT) 965 # add observer for joining the room 966 query = PRESENCE + u"[@from='%s' and @type='unavailable']" % (room.occupantJID) 967 self.xmlstream.addOnetimeObserver(query, self._leftRoom, 1, d) 968 926 d = self.sendDeferred(presence) 927 d.addCallback(self._leftRoom) 969 928 return d 970 929 971 930 972 def status(self, occupantJID, show=None, status=None):931 def status(self, roomJID, show=None, status=None): 973 932 """ 974 933 Change user status. … … 976 935 See: http://xmpp.org/extensions/xep-0045.html#changepres 977 936 978 @param occupantJID: The room jabber/xmpp entity id for the requested configuration form. 979 @type occupantJID: L{jid.JID} 980 981 @param show: The availability of the entity. Common values are xa, available, etc 937 @param roomJID: The Room JID of the room. 938 @type roomJID: L{jid.JID} 939 940 @param show: The availability of the entity. Common values are xa, 941 available, etc 982 942 @type show: C{unicode} 983 943 … … 985 945 @type show: C{unicode} 986 946 """ 987 room = self._getRoom( occupantJID)947 room = self._getRoom(roomJID) 988 948 989 949 presence = BasicPresence(recipient=room.occupantJID, 990 950 show=show, status=status) 991 951 992 d = self.sendDeferred(presence.toElement(), timeout=DEFER_TIMEOUT) 993 994 # add observer for joining the room 995 query = PRESENCE + u"[@from='%s']" % room.occupantJID 996 self.xmlstream.addOnetimeObserver(query, self._changed, 1, d, occupantJID) 997 952 d = self.sendDeferred(presence) 953 d.addCallback(self._changed, room.occupantJID) 998 954 return d 999 955 … … 1177 1133 Get an owner list from a room. 1178 1134 1179 @param roomJID: The room jabber/xmpp entity id for the requested member list. 1135 @param roomJID: The room jabber/xmpp entity id for the requested member 1136 list. 1180 1137 @type roomJID: L{jid.JID} 1181 1138 """ … … 1189 1146 Grab the registration form for a MUC room. 1190 1147 1191 @param room: The room jabber/xmpp entity id for the requested registration form. 1148 @param room: The room jabber/xmpp entity id for the requested 1149 registration form. 1192 1150 @type room: L{jid.JID} 1193 1151 """ -
wokkel/test/test_muc.py
r144 r145 12 12 13 13 from twisted.trial import unittest 14 from twisted.internet import defer 14 from twisted.internet import defer, task 15 15 from twisted.words.xish import domish, xpath 16 16 from twisted.words.protocols.jabber.jid import JID 17 from twisted.words.protocols.jabber.error import StanzaError 18 from twisted.words.protocols.jabber.xmlstream import TimeoutError, toResponse 17 19 18 20 from wokkel import data_form, iwokkel, muc … … 20 22 from wokkel.test.helpers import XmlStreamStub 21 23 22 from twisted.words.protocols.jabber.xmlstream import toResponse23 24 24 25 NS_MUC_ADMIN = 'http://jabber.org/protocol/muc#admin' … … 40 41 return d, func 41 42 42 class MucClientTest(unittest.TestCase): 43 44 45 class MUCClientTest(unittest.TestCase): 43 46 timeout = 2 44 47 45 48 def setUp(self): 46 49 self.stub = XmlStreamStub() 47 self.protocol = muc.MUCClient() 50 self.clock = task.Clock() 51 self.protocol = muc.MUCClient(reactor=self.clock) 48 52 self.protocol.xmlstream = self.stub.xmlstream 49 53 self.protocol.connectionInitialized() … … 102 106 103 107 108 def test_receivedSubject(self): 109 """ 110 Subject received from a room we're in are passed to receivedSubject. 111 """ 112 xml = u""" 113 <message to='%s' from='%s' type='groupchat'> 114 <subject>test</subject> 115 </message> 116 """ % (self.userJID, self.occupantJID) 117 118 self._createRoom() 119 120 # add user to room 121 user = muc.User(self.nick) 122 room = self.protocol._getRoom(self.roomJID) 123 room.addUser(user) 124 125 def receivedSubject(room, user, subject): 126 self.assertEquals('test', subject, "Wrong group chat message") 127 self.assertEquals(self.roomIdentifier, room.roomIdentifier, 128 'Wrong room name') 129 self.assertEquals(self.nick, user.nick) 130 131 d, self.protocol.receivedSubject = calledAsync(receivedSubject) 132 self.stub.send(parseXml(xml)) 133 return d 134 135 104 136 def test_receivedGroupChat(self): 105 137 """ … … 144 176 145 177 146 def test_join Room(self):178 def test_join(self): 147 179 """ 148 180 Joining a room waits for confirmation, deferred fires room. … … 155 187 d.addCallback(cb) 156 188 157 prs= self.stub.output[-1]158 self.assertEquals('presence', prs.name, "Need to be presence")159 self.assertNotIdentical(None, prs.x, 'No muc x element')189 element = self.stub.output[-1] 190 self.assertEquals('presence', element.name, "Need to be presence") 191 self.assertNotIdentical(None, element.x, 'No muc x element') 160 192 161 193 # send back user presence, they joined … … 171 203 172 204 173 def test_join RoomForbidden(self):174 """ 175 Client joining a room and getting a forbidden error.205 def test_joinForbidden(self): 206 """ 207 A forbidden error in response to a join errbacks with L{StanzaError}. 176 208 """ 177 209 178 210 def cb(error): 179 self.assertEquals('forbidden', error. value.condition,211 self.assertEquals('forbidden', error.condition, 180 212 'Wrong muc condition') 181 213 182 214 d = self.protocol.join(self.service, self.roomIdentifier, self.nick) 183 d.addBoth(cb) 184 185 prs = self.stub.output[-1] 186 self.assertEquals('presence', prs.name, "Need to be presence") 187 self.assertNotIdentical(None, prs.x, 'No muc x element') 215 self.assertFailure(d, StanzaError) 216 d.addCallback(cb) 188 217 189 218 # send back error, forbidden … … 199 228 200 229 201 def test_joinRoomBadJID(self): 230 def test_joinForbiddenFromRoomJID(self): 231 """ 232 An error response to a join sent from the room JID should errback. 233 234 Some service implementations send error stanzas from the room JID 235 instead of the JID the join presence was sent to. 236 """ 237 238 d = self.protocol.join(self.service, self.roomIdentifier, self.nick) 239 self.assertFailure(d, StanzaError) 240 241 # send back error, forbidden 242 xml = u""" 243 <presence from='%s' type='error'> 244 <error type='auth'> 245 <forbidden xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/> 246 </error> 247 </presence> 248 """ % (self.roomJID) 249 self.stub.send(parseXml(xml)) 250 return d 251 252 253 def test_joinBadJID(self): 202 254 """ 203 255 Client joining a room and getting a jid-malformed error. … … 205 257 206 258 def cb(error): 207 self.assertEquals('jid-malformed', error. value.condition,259 self.assertEquals('jid-malformed', error.condition, 208 260 'Wrong muc condition') 209 261 210 262 d = self.protocol.join(self.service, self.roomIdentifier, self.nick) 211 d.addBoth(cb) 212 213 prs = self.stub.output[-1] 214 self.assertEquals('presence', prs.name, "Need to be presence") 215 self.assertNotIdentical(None, prs.x, 'No muc x element') 263 self.assertFailure(d, StanzaError) 264 d.addCallback(cb) 216 265 217 266 # send back error, bad JID … … 227 276 228 277 229 def test_partRoom(self): 278 def test_joinTimeout(self): 279 """ 280 After not receiving a response to a join, errback with L{TimeoutError}. 281 """ 282 283 d = self.protocol.join(self.service, self.roomIdentifier, self.nick) 284 self.assertFailure(d, TimeoutError) 285 self.clock.advance(muc.DEFER_TIMEOUT) 286 return d 287 288 289 def test_leave(self): 230 290 """ 231 291 Client leaves a room … … 235 295 236 296 self._createRoom() 237 d = self.protocol.leave(self. occupantJID)238 d.addCallback(cb) 239 240 prs= self.stub.output[-1]241 242 self.assertEquals('unavailable', prs['type'],297 d = self.protocol.leave(self.roomJID) 298 d.addCallback(cb) 299 300 element = self.stub.output[-1] 301 302 self.assertEquals('unavailable', element['type'], 243 303 'Unavailable is not being sent') 244 304 … … 250 310 251 311 252 def test_user PartsRoom(self):253 """ 254 An entity leaves the room, a presence of type unavailable is received by the client.312 def test_userLeftRoom(self): 313 """ 314 Unavailable presence from a participant removes it from the room. 255 315 """ 256 316 … … 264 324 # add user to room 265 325 user = muc.User(self.nick) 266 room = self.protocol._getRoom(self. occupantJID)326 room = self.protocol._getRoom(self.roomJID) 267 327 room.addUser(user) 268 328 269 def user Presence(room, user):329 def userLeftRoom(room, user): 270 330 self.assertEquals(self.roomIdentifier, room.roomIdentifier, 271 331 'Wrong room name') 272 332 self.assertFalse(room.inRoster(user), 'User in roster') 273 333 274 d, self.protocol.userLeftRoom = calledAsync(user Presence)334 d, self.protocol.userLeftRoom = calledAsync(userLeftRoom) 275 335 self.stub.send(parseXml(xml)) 276 336 return d … … 338 398 self.protocol.password(self.occupantJID, 'secret') 339 399 340 prs= self.stub.output[-1]400 element = self.stub.output[-1] 341 401 342 402 self.assertTrue(xpath.matches( 343 403 u"/presence[@to='%s']/x/password" 344 404 "[text()='secret']" % (self.occupantJID,), 345 prs),405 element), 346 406 'Wrong presence stanza') 347 407 348 408 349 def test_ historyReceived(self):409 def test_receivedHistory(self): 350 410 """ 351 411 Receiving history on room join. … … 362 422 363 423 364 def historyReceived(room, user, message):424 def receivedHistory(room, user, message): 365 425 self.assertEquals('test', message.body, "wrong message body") 366 426 stamp = datetime(2002, 10, 13, 23, 58, 37, tzinfo=tzutc()) … … 368 428 'Does not have a history stamp') 369 429 370 d, self.protocol.receivedHistory = calledAsync( historyReceived)430 d, self.protocol.receivedHistory = calledAsync(receivedHistory) 371 431 self.stub.send(parseXml(xml)) 372 432 return d … … 380 440 thread = "e0ffe42b28561960c6b12b944a092794b9683a38" 381 441 # create messages 382 msg= domish.Element((None, 'message'))383 msg['to'] = 'testing@example.com'384 msg['type'] = 'chat'385 msg.addElement('body', None, 'test')386 msg.addElement('thread', None, thread)387 388 archive.append({'stanza': msg,442 element = domish.Element((None, 'message')) 443 element['to'] = 'testing@example.com' 444 element['type'] = 'chat' 445 element.addElement('body', None, 'test') 446 element.addElement('thread', None, thread) 447 448 archive.append({'stanza': element, 389 449 'timestamp': datetime(2002, 10, 13, 23, 58, 37, 390 450 tzinfo=tzutc())}) 391 451 392 msg= domish.Element((None, 'message'))393 msg['to'] = 'testing2@example.com'394 msg['type'] = 'chat'395 msg.addElement('body', None, 'yo')396 msg.addElement('thread', None, thread)397 398 archive.append({'stanza': msg,452 element = domish.Element((None, 'message')) 453 element['to'] = 'testing2@example.com' 454 element['type'] = 'chat' 455 element.addElement('body', None, 'yo') 456 element.addElement('thread', None, thread) 457 458 archive.append({'stanza': element, 399 459 'timestamp': datetime(2002, 10, 13, 23, 58, 43, 400 460 tzinfo=tzutc())}) … … 404 464 405 465 while len(self.stub.output)>0: 406 m= self.stub.output.pop()466 element = self.stub.output.pop() 407 467 # check for delay element 408 self.assertEquals('message', m.name, 'Wrong stanza') 409 self.assertTrue(xpath.matches("/message/delay", m), 'Invalid history stanza') 468 self.assertEquals('message', element.name, 'Wrong stanza') 469 self.assertTrue(xpath.matches("/message/delay", element), 470 'Invalid history stanza') 410 471 411 472 … … 558 619 559 620 560 def test_nick Change(self):621 def test_nick(self): 561 622 """ 562 623 Send a nick change to the server. 563 624 """ 564 test_nick = 'newNick'625 newNick = 'newNick' 565 626 566 627 self._createRoom() … … 568 629 def cb(room): 569 630 self.assertEquals(self.roomIdentifier, room.roomIdentifier) 570 self.assertEquals( test_nick, room.nick)571 572 d = self.protocol.nick(self. occupantJID, test_nick)573 d.addCallback(cb) 574 575 prs= self.stub.output[-1]576 self.assertEquals('presence', prs.name, "Need to be presence")577 self.assertNotIdentical(None, prs.x, 'No muc x element')631 self.assertEquals(newNick, room.nick) 632 633 d = self.protocol.nick(self.roomJID, newNick) 634 d.addCallback(cb) 635 636 element = self.stub.output[-1] 637 self.assertEquals('presence', element.name, "Need to be presence") 638 self.assertNotIdentical(None, element.x, 'No muc x element') 578 639 579 640 # send back user presence, nick changed 580 xml = """581 <presence from='%s @%s/%s'>641 xml = u""" 642 <presence from='%s/%s'> 582 643 <x xmlns='http://jabber.org/protocol/muc#user'> 583 644 <item affiliation='member' role='participant'/> 584 645 </x> 585 646 </presence> 586 """ % (self.roomIdentifier, self.service, test_nick) 647 """ % (self.roomJID, newNick) 648 self.stub.send(parseXml(xml)) 649 return d 650 651 652 def test_nickConflict(self): 653 """ 654 If the server finds the new nick in conflict, the errback is called. 655 """ 656 newNick = 'newNick' 657 658 self._createRoom() 659 660 d = self.protocol.nick(self.roomJID, newNick) 661 self.assertFailure(d, StanzaError) 662 663 element = self.stub.output[-1] 664 self.assertEquals('presence', element.name, "Need to be presence") 665 self.assertNotIdentical(None, element.x, 'No muc x element') 666 667 # send back user presence, nick changed 668 xml = u""" 669 <presence from='%s/%s' type='error'> 670 <x xmlns='http://jabber.org/protocol/muc'/> 671 <error type='cancel'> 672 <conflict xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/> 673 </error> 674 </presence> 675 """ % (self.roomJID, newNick) 587 676 self.stub.send(parseXml(xml)) 588 677 return d … … 598 687 self.assertTrue(give_voice, 'Did not give voice user') 599 688 600 d = self.protocol.grantVoice(self.occupantJID, nick, sender=self.userJID) 689 d = self.protocol.grantVoice(self.occupantJID, nick, 690 sender=self.userJID) 601 691 d.addCallback(cb) 602 692 … … 612 702 613 703 614 def test_ changeStatus(self):704 def test_status(self): 615 705 """ 616 706 Change status 617 707 """ 618 708 self._createRoom() 619 room = self.protocol._getRoom(self. occupantJID)709 room = self.protocol._getRoom(self.roomJID) 620 710 user = muc.User(self.nick) 621 711 room.addUser(user) … … 628 718 self.assertEquals('xa', user.show, 'Wrong show') 629 719 630 d = self.protocol.status(self. occupantJID, 'xa', 'testing MUC')631 d.addCallback(cb) 632 633 prs= self.stub.output[-1]634 635 self.assertEquals('presence', prs.name, "Need to be presence")636 self.assertTrue(getattr( prs, 'x', None), 'No muc x element')720 d = self.protocol.status(self.roomJID, 'xa', 'testing MUC') 721 d.addCallback(cb) 722 723 element = self.stub.output[-1] 724 725 self.assertEquals('presence', element.name, "Need to be presence") 726 self.assertTrue(getattr(element, 'x', None), 'No muc x element') 637 727 638 728 # send back user presence, status changed
Note: See TracChangeset
for help on using the changeset viewer.