当前位置: 首页>>代码示例>>Python>>正文


Python helpers.XmlStreamStub类代码示例

本文整理汇总了Python中wokkel.test.helpers.XmlStreamStub的典型用法代码示例。如果您正苦于以下问题:Python XmlStreamStub类的具体用法?Python XmlStreamStub怎么用?Python XmlStreamStub使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了XmlStreamStub类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: VersionHandlerTest

class VersionHandlerTest(unittest.TestCase):
    """
    Tests for L{wokkel.generic.VersionHandler}.
    """

    def test_onVersion(self):
        """
        Test response to incoming version request.
        """
        self.stub = XmlStreamStub()
        self.protocol = generic.VersionHandler('Test', '0.1.0')
        self.protocol.xmlstream = self.stub.xmlstream
        self.protocol.send = self.stub.xmlstream.send
        self.protocol.connectionInitialized()

        iq = domish.Element((None, 'iq'))
        iq['from'] = '[email protected]/Home'
        iq['to'] = 'example.org'
        iq['type'] = 'get'
        query = iq.addElement((NS_VERSION, 'query'))
        self.stub.send(iq)

        response = self.stub.output[-1]
        self.assertEquals('[email protected]/Home', response['to'])
        self.assertEquals('example.org', response['from'])
        self.assertEquals('result', response['type'])
        self.assertEquals(NS_VERSION, response.query.uri)
        elements = list(domish.generateElementsQNamed(response.query.children,
                                                      'name', NS_VERSION))
        self.assertEquals(1, len(elements))
        self.assertEquals('Test', unicode(elements[0]))
        elements = list(domish.generateElementsQNamed(response.query.children,
                                                      'version', NS_VERSION))
        self.assertEquals(1, len(elements))
        self.assertEquals('0.1.0', unicode(elements[0]))
开发者ID:thepaul,项目名称:wokkel,代码行数:35,代码来源:test_generic.py

示例2: setUp

 def setUp(self):
     """
     Set up stub and protocol for testing.
     """
     self.stub = XmlStreamStub()
     self.protocol = disco.DiscoClientProtocol()
     self.protocol.xmlstream = self.stub.xmlstream
     self.protocol.connectionInitialized()
开发者ID:carriercomm,项目名称:wokkel,代码行数:8,代码来源:test_disco.py

示例3: setUp

 def setUp(self):
     self.stub = XmlStreamStub()
     self.stub.xmlstream.factory = FactoryWithJID()
     self.protocol = protocols.AdminHandler()
     self.protocol.xmlstream = self.stub.xmlstream
     self.protocol.connectionInitialized()
     registry = getUtility(IRegistry)
     settings = registry.forInterface(IXMPPSettings, check=False)
     settings.xmpp_domain = u'example.com'
开发者ID:Anup888,项目名称:collective.xmpp.core,代码行数:9,代码来源:test_admin.py

示例4: setUp

    def setUp(self):
        self.stub = XmlStreamStub()
        self.protocol = muc.MUCClient()
        self.protocol.xmlstream = self.stub.xmlstream
        self.protocol.connectionInitialized()
        self.test_room = 'test'
        self.test_srv  = 'conference.example.org'
        self.test_nick = 'Nick'

        self.room_jid = JID(self.test_room+'@'+self.test_srv+'/'+self.test_nick)

        self.user_jid = JID('[email protected]/Testing')
开发者ID:Urthen,项目名称:Legacy-FritBot,代码行数:12,代码来源:test_muc.py

示例5: RosterClientProtocolTest

class RosterClientProtocolTest(unittest.TestCase):
    """
    Tests for L{xmppim.RosterClientProtocol}.
    """

    def setUp(self):
        self.stub = XmlStreamStub()
        self.protocol = xmppim.RosterClientProtocol()
        self.protocol.xmlstream = self.stub.xmlstream
        self.protocol.connectionInitialized()


    def test_removeItem(self):
        """
        Removing a roster item is setting an item with subscription C{remove}.
        """
        d = self.protocol.removeItem(JID('[email protected]'))

        # Inspect outgoing iq request

        iq = self.stub.output[-1]
        self.assertEquals('set', iq.getAttribute('type'))
        self.assertNotIdentical(None, iq.query)
        self.assertEquals(NS_ROSTER, iq.query.uri)

        children = list(domish.generateElementsQNamed(iq.query.children,
                                                      'item', NS_ROSTER))
        self.assertEquals(1, len(children))
        child = children[0]
        self.assertEquals('[email protected]', child['jid'])
        self.assertEquals('remove', child['subscription'])

        # Fake successful response

        response = toResponse(iq, 'result')
        self.stub.send(response)
        return d
开发者ID:thepaul,项目名称:wokkel,代码行数:37,代码来源:test_xmppim.py

示例6: setUp

    def setUp(self):
        self.stub = XmlStreamStub()
        self.protocol = mock.MockDifferentialSyncronisationHandler()
        self.protocol.xmlstream = self.stub.xmlstream
        self.protocol.connectionInitialized()

        self.original = \
            """
            Hamlet: Do you see yonder cloud that's almost in shape of a camel?
            Polonius: By the mass, and 'tis like a camel, indeed.
            Hamlet: Methinks it is like a weasel.
            Polonius: It is backed like a weasel.
            Hamlet: Or like a whale?
            Polonius: Very like a whale.
            """

        self.plain = \
            """
            Hamlet: Do you see the cloud over there that's almost the shape of a camel?
            Polonius: By golly, it is like a camel, indeed.
            Hamlet: I think it looks like a weasel.
            Polonius: It is shaped like a weasel.
            Hamlet: Or like a whale?
            Polonius: It's totally like a whale.
            """

        self.trekkie = \
            """
            Kirk: Do you see yonder cloud that's almost in shape of a Klingon?
            Spock: By the mass, and 'tis like a Klingon, indeed.
            Kirk: Methinks it is like a Vulcan.
            Spock: It is backed like a Vulcan.
            Kirk: Or like a Romulan?
            Spock: Very like a Romulan.
            """

        self.final = \
            """
            Kirk: Do you see the cloud over there that's almost the shape of a Klingon?
            Spock: By golly, it is like a Klingon, indeed.
            Kirk: I think it looks like a Vulcan.
            Spock: It is shaped like a Vulcan.
            Kirk: Or like a Romulan?
            Spock: It's totally like a Romulan.
            """

        self.protocol.mock_text = {'hamlet': self.original}
        self.dmp = diff_match_patch()
开发者ID:collective,项目名称:collective.xmpp.collaboration,代码行数:48,代码来源:test_protocol_functional.py

示例7: DifferentialSyncronisationHandlerFunctionalTest

class DifferentialSyncronisationHandlerFunctionalTest(unittest.TestCase):
    """
    Functional test for the DifferentialSynchronisationProtocol.
    """

    def setUp(self):
        self.stub = XmlStreamStub()
        self.protocol = mock.MockDifferentialSyncronisationHandler()
        self.protocol.xmlstream = self.stub.xmlstream
        self.protocol.connectionInitialized()

        self.original = \
            """
            Hamlet: Do you see yonder cloud that's almost in shape of a camel?
            Polonius: By the mass, and 'tis like a camel, indeed.
            Hamlet: Methinks it is like a weasel.
            Polonius: It is backed like a weasel.
            Hamlet: Or like a whale?
            Polonius: Very like a whale.
            """

        self.plain = \
            """
            Hamlet: Do you see the cloud over there that's almost the shape of a camel?
            Polonius: By golly, it is like a camel, indeed.
            Hamlet: I think it looks like a weasel.
            Polonius: It is shaped like a weasel.
            Hamlet: Or like a whale?
            Polonius: It's totally like a whale.
            """

        self.trekkie = \
            """
            Kirk: Do you see yonder cloud that's almost in shape of a Klingon?
            Spock: By the mass, and 'tis like a Klingon, indeed.
            Kirk: Methinks it is like a Vulcan.
            Spock: It is backed like a Vulcan.
            Kirk: Or like a Romulan?
            Spock: Very like a Romulan.
            """

        self.final = \
            """
            Kirk: Do you see the cloud over there that's almost the shape of a Klingon?
            Spock: By golly, it is like a Klingon, indeed.
            Kirk: I think it looks like a Vulcan.
            Spock: It is shaped like a Vulcan.
            Kirk: Or like a Romulan?
            Spock: It's totally like a Romulan.
            """

        self.protocol.mock_text = {'hamlet': self.original}
        self.dmp = diff_match_patch()

    def test_full_cycle(self):
        # foo logs in.
        xml = """<presence from='[email protected]' to='example.com'>
                    <query xmlns='http://jarn.com/ns/collaborative-editing'
                           node='hamlet'/>
                 </presence>"""
        self.stub.send(parseXml(xml))

        # bar logs in.
        xml = """<presence from='[email protected]' to='example.com'>
                    <query xmlns='http://jarn.com/ns/collaborative-editing'
                           node='hamlet'/>
                 </presence>"""
        self.stub.send(parseXml(xml))

        # foo changes the Sheakespearean text to plain english,
        # and creates a patch.
        original2plain_patch = self.dmp.patch_make(self.original, self.plain)
        original2plain_text = self.dmp.patch_toText(original2plain_patch)
        xml = "<iq from='[email protected]' to='example.com' type='set'>" + \
              "<patch xmlns='http://jarn.com/ns/collaborative-editing' node='hamlet'>" + \
              original2plain_text + \
              "</patch></iq>"
        self.stub.send(parseXml(xml))

        # Before receiving a patch from the server bar has already updated
        # his own version to trekkie and sends it away.
        original2trekkie_patch = self.dmp.patch_make(self.original, self.trekkie)
        original2trekkie_text = self.dmp.patch_toText(original2trekkie_patch)
        xml = "<iq from='[email protected]' to='example.com' type='set'>" + \
              "<patch xmlns='http://jarn.com/ns/collaborative-editing' node='hamlet'>" + \
              original2trekkie_text + \
              "</patch></iq>"
        self.stub.send(parseXml(xml))

        # So now, both have obtained a patch to apply each other changes on
        # the already changed document. They are the same and merged perfectly.
        iq_to_foo = self.stub.output[-1]
        plain2final_text = iq_to_foo.patch.children[0]
        plain2final_patch = self.dmp.patch_fromText(plain2final_text)
        foo_result = self.dmp.patch_apply(plain2final_patch, self.plain)
        foo_final = foo_result[0]
        self.assertEqual(self.final, foo_final)

        iq_to_bar = self.stub.output[-3]
        trekkie2final_text = iq_to_bar.patch.children[0]
#.........这里部分代码省略.........
开发者ID:collective,项目名称:collective.xmpp.collaboration,代码行数:101,代码来源:test_protocol_functional.py

示例8: AdminCommandsProtocolTest

class AdminCommandsProtocolTest(unittest.TestCase):
    """
    """

    def setUp(self):
        self.stub = XmlStreamStub()
        self.stub.xmlstream.factory = FactoryWithJID()
        self.protocol = protocols.AdminHandler()
        self.protocol.xmlstream = self.stub.xmlstream
        self.protocol.connectionInitialized()

    def test_addUser(self):
        self.protocol.addUser(u'[email protected]', u'secret')

        iq = self.stub.output[-1]
        self.assertEqual(u'example.com', iq.getAttribute(u'to'))
        self.assertEqual(u'set', iq.getAttribute(u'type'))
        self.assertEqual(protocols.NS_COMMANDS, iq.command.uri)
        self.failIf(iq.command is None)
        self.assertEqual(protocols.NODE_ADMIN_ADD_USER,
                         iq.command.getAttribute('node'))
        self.assertEqual('execute', iq.command.getAttribute('action'))
        response = toResponse(iq, u'result')
        response['to'] = \
            self.protocol.xmlstream.factory.authenticator.jid.full()
        command = response.addElement((protocols.NS_COMMANDS, u'command'))
        command[u'node'] = protocols.NODE_ADMIN_ADD_USER
        command[u'status'] = u'executing'
        command[u'sessionid'] = u'sid-0'
        form = data_form.Form(u'form')
        form_type = data_form.Field(u'hidden',
                                    var=u'FORM_TYPE',
                                    value=protocols.NODE_ADMIN)
        userjid = data_form.Field(u'jid-single',
                                  var=u'accountjid', required=True)
        password = data_form.Field(u'text-private',
                                   var=u'password', required=True)
        password_verify = data_form.Field(u'text-private',
                                          var=u'password-verify',
                                          required=True)
        form.addField(form_type)
        form.addField(userjid)
        form.addField(password)
        form.addField(password_verify)
        command.addContent(form.toElement())
        self.stub.send(response)

        iq = self.stub.output[-1]
        self.assertEqual(u'set', iq.getAttribute(u'type'))
        self.assertEqual(protocols.NS_COMMANDS, iq.command.uri)
        self.assertEqual(protocols.NODE_ADMIN_ADD_USER,
                         iq.command.getAttribute(u'node'))
        self.assertEqual(u'sid-0', iq.command.getAttribute(u'sessionid'))
        form = data_form.findForm(iq.command, protocols.NODE_ADMIN)
        self.assertEqual(u'submit', form.formType)
        self.failUnless(u'accountjid' in form.fields)
        self.assertEqual(u'[email protected]', form.fields['accountjid'].value)
        self.failUnless(u'password' in form.fields)
        self.assertEqual(u'secret', form.fields['password'].value)
        self.failUnless(u'password-verify' in form.fields)
        self.assertEqual(u'secret', form.fields['password-verify'].value)

    def test_deleteUsers(self):
        self.protocol.deleteUsers(u'[email protected]')

        iq = self.stub.output[-1]
        self.assertEqual(u'example.com', iq.getAttribute(u'to'))
        self.assertEqual(u'set', iq.getAttribute(u'type'))
        self.assertEqual(protocols.NS_COMMANDS, iq.command.uri)
        self.failIf(iq.command is None)
        self.assertEqual(protocols.NODE_ADMIN_DELETE_USER,
                         iq.command.getAttribute('node'))
        self.assertEqual('execute', iq.command.getAttribute('action'))
        response = toResponse(iq, u'result')
        response['to'] = \
            self.protocol.xmlstream.factory.authenticator.jid.full()
        command = response.addElement((protocols.NS_COMMANDS, u'command'))
        command[u'node'] = protocols.NODE_ADMIN_DELETE_USER
        command[u'status'] = u'executing'
        command[u'sessionid'] = u'sid-0'
        form = data_form.Form(u'form')
        form_type = data_form.Field(u'hidden',
                                    var=u'FORM_TYPE',
                                    value=protocols.NODE_ADMIN)
        userjids = data_form.Field(u'jid-multi',
                                  var=u'accountjids')
        form.addField(form_type)
        form.addField(userjids)
        command.addContent(form.toElement())
        self.stub.send(response)

        iq = self.stub.output[-1]
        self.assertEqual(u'set', iq.getAttribute(u'type'))
        self.assertEqual(protocols.NS_COMMANDS, iq.command.uri)
        self.assertEqual(protocols.NODE_ADMIN_DELETE_USER,
                         iq.command.getAttribute(u'node'))
        self.assertEqual(u'sid-0', iq.command.getAttribute(u'sessionid'))
        form = data_form.findForm(iq.command, protocols.NODE_ADMIN)
        self.assertEqual(u'submit', form.formType)
        self.failUnless(u'accountjids' in form.fields)
#.........这里部分代码省略.........
开发者ID:Blaastolen,项目名称:jarn.xmpp.twisted,代码行数:101,代码来源:test_admin.py

示例9: PingClientProtocolTest

class PingClientProtocolTest(unittest.TestCase):
    """
    Tests for L{ping.PingClientProtocol}.
    """

    def setUp(self):
        self.stub = XmlStreamStub()
        self.protocol = ping.PingClientProtocol()
        self.protocol.xmlstream = self.stub.xmlstream
        self.protocol.connectionInitialized()


    def test_ping(self):
        """
        Pinging a service should fire a deferred with None
        """
        def cb(result):
            self.assertIdentical(None, result)

        d = self.protocol.ping(JID("example.com"))
        d.addCallback(cb)

        iq = self.stub.output[-1]
        self.assertEqual(u'example.com', iq.getAttribute(u'to'))
        self.assertEqual(u'get', iq.getAttribute(u'type'))
        self.assertEqual('urn:xmpp:ping', iq.ping.uri)

        response = toResponse(iq, u'result')
        self.stub.send(response)

        return d


    def test_pingWithSender(self):
        """
        Pinging a service with a sender address should include that address.
        """
        d = self.protocol.ping(JID("example.com"),
                               sender=JID('[email protected]'))

        iq = self.stub.output[-1]
        self.assertEqual(u'[email protected]', iq.getAttribute(u'from'))

        response = toResponse(iq, u'result')
        self.stub.send(response)

        return d


    def test_pingNotSupported(self):
        """
        Pinging a service should fire a deferred with None if not supported.
        """
        def cb(result):
            self.assertIdentical(None, result)

        d = self.protocol.ping(JID("example.com"))
        d.addCallback(cb)

        iq = self.stub.output[-1]

        exc = StanzaError('service-unavailable')
        response = exc.toResponse(iq)
        self.stub.send(response)

        return d


    def test_pingStanzaError(self):
        """
        Pinging a service should errback a deferred on other (stanza) errors.
        """
        def cb(exc):
            self.assertEquals('item-not-found', exc.condition)

        d = self.protocol.ping(JID("example.com"))
        self.assertFailure(d, StanzaError)
        d.addCallback(cb)

        iq = self.stub.output[-1]

        exc = StanzaError('item-not-found')
        response = exc.toResponse(iq)
        self.stub.send(response)

        return d
开发者ID:B-Rich,项目名称:wokkel,代码行数:86,代码来源:test_ping.py

示例10: DifferentialSyncronisationHandlerTest

class DifferentialSyncronisationHandlerTest(unittest.TestCase):
    """
    Tests for the DifferentialSynchronisationProtocol.
    """

    def setUp(self):
        self.stub = XmlStreamStub()
        self.protocol = mock.MockDifferentialSyncronisationHandler()
        self.protocol.xmlstream = self.stub.xmlstream
        self.protocol.connectionInitialized()

    def test_onPresence(self):
        # User [email protected] joins
        self.protocol.mock_text['test-node'] = 'foo'
        xml = """<presence from='[email protected]' to='example.com'>
                    <query xmlns='http://jarn.com/ns/collaborative-editing'
                           node='test-node'/>
                 </presence>"""
        self.stub.send(parseXml(xml))
        self.assertEqual({u'test-node': set([u'[email protected]'])},
                         self.protocol.node_participants)
        self.assertEqual({u'[email protected]': set([u'test-node'])},
                          self.protocol.participant_nodes)
        self.assertEqual({u'test-node': 'foo'},
                         self.protocol.shadow_copies)

        # Another user joins:
        xml = """<presence from='[email protected]' to='example.com'>
                    <query xmlns='http://jarn.com/ns/collaborative-editing'
                           node='test-node'/>
                 </presence>"""
        self.stub.send(parseXml(xml))

        # The new user should receive a user-joined for the existing user.
        message = self.stub.output[-1]
        self.assertEqual(
            "<message to='[email protected]'>" +
            "<x xmlns='http://jarn.com/ns/collaborative-editing'>" +
            "<item action='user-joined' node='test-node' user='[email protected]'/>" +
            "</x></message>", message.toXml())

        #The already active user should receive a user-joined
        message = self.stub.output[-2]
        self.assertEqual(
            "<message to='[email protected]'>" +
            "<x xmlns='http://jarn.com/ns/collaborative-editing'>" +
            "<item action='user-joined' node='test-node' user='[email protected]'/>" +
            "</x></message>", message.toXml())

        # Then [email protected] leaves the node.

        xml = """<presence from='[email protected]' to='example.com'
                    type='unavailable'/>"""
        self.stub.send(parseXml(xml))

        # Make sure the [email protected] is indeed gone,
        self.assertEqual({u'test-node': set([u'[email protected]'])},
                         self.protocol.node_participants)
        self.assertEqual({u'[email protected]': set([u'test-node'])},
                         self.protocol.participant_nodes)

        # [email protected] should have received a notification
        message = self.stub.output[-1]
        self.assertEqual(
            "<message to='[email protected]'>" +
            "<x xmlns='http://jarn.com/ns/collaborative-editing'>" +
            "<item action='user-left' node='test-node' user='[email protected]'/>" +
            "</x></message>", message.toXml())

        # Then [email protected] leaves as well.
        xml = """<presence from='[email protected]' to='example.com'
                    type='unavailable'/>"""
        self.stub.send(parseXml(xml))

        self.assertEqual({}, self.protocol.node_participants)
        self.assertEqual({}, self.protocol.participant_nodes)
        self.assertEqual({}, self.protocol.shadow_copies)

    def test_getShadowCopyIQ(self):
        # User [email protected] joins
        self.protocol.mock_text['test-node'] = 'foo'
        xml = """<presence from='[email protected]' to='example.com'>
                    <query xmlns='http://jarn.com/ns/collaborative-editing'
                           node='test-node'/>
                 </presence>"""
        self.stub.send(parseXml(xml))

        # And requests the shadow copy of 'test-node'
        xml = """<iq from='[email protected]' to='example.com' type='get'>
                    <shadowcopy xmlns='http://jarn.com/ns/collaborative-editing'
                           node='test-node'/>
                 </iq>"""
        self.stub.send(parseXml(xml))
        response = self.stub.output[-1]
        self.assertEqual("<iq to='[email protected]' from='example.com' type='result'>" +
                         "<shadowcopy xmlns='http://jarn.com/ns/collaborative-editing' node='test-node'>foo</shadowcopy>" +
                         "</iq>", response.toXml())

        # Requesting the shadow copy of an non-existent node should result in Unauthorized error
        xml = """<iq from='[email protected]' to='example.com' type='get'>
#.........这里部分代码省略.........
开发者ID:collective,项目名称:collective.xmpp.collaboration,代码行数:101,代码来源:test_protocol.py

示例11: setUp

 def setUp(self):
     self.stub = XmlStreamStub()
     self.protocol = pubsub.PubSubClient()
     self.protocol.xmlstream = self.stub.xmlstream
     self.protocol.connectionInitialized()
开发者ID:Urthen,项目名称:Legacy-FritBot,代码行数:5,代码来源:test_pubsub.py

示例12: PubSubClientTest

class PubSubClientTest(unittest.TestCase):
    timeout = 2

    def setUp(self):
        self.stub = XmlStreamStub()
        self.protocol = pubsub.PubSubClient()
        self.protocol.xmlstream = self.stub.xmlstream
        self.protocol.connectionInitialized()


    def test_interface(self):
        """
        Do instances of L{pubsub.PubSubClient} provide L{iwokkel.IPubSubClient}?
        """
        verify.verifyObject(iwokkel.IPubSubClient, self.protocol)


    def test_eventItems(self):
        """
        Test receiving an items event resulting in a call to itemsReceived.
        """
        message = domish.Element((None, 'message'))
        message['from'] = 'pubsub.example.org'
        message['to'] = '[email protected]/home'
        event = message.addElement((NS_PUBSUB_EVENT, 'event'))
        items = event.addElement('items')
        items['node'] = 'test'
        item1 = items.addElement('item')
        item1['id'] = 'item1'
        item2 = items.addElement('retract')
        item2['id'] = 'item2'
        item3 = items.addElement('item')
        item3['id'] = 'item3'

        def itemsReceived(event):
            self.assertEquals(JID('[email protected]/home'), event.recipient)
            self.assertEquals(JID('pubsub.example.org'), event.sender)
            self.assertEquals('test', event.nodeIdentifier)
            self.assertEquals([item1, item2, item3], event.items)

        d, self.protocol.itemsReceived = calledAsync(itemsReceived)
        self.stub.send(message)
        return d


    def test_eventItemsCollection(self):
        """
        Test receiving an items event resulting in a call to itemsReceived.
        """
        message = domish.Element((None, 'message'))
        message['from'] = 'pubsub.example.org'
        message['to'] = '[email protected]/home'
        event = message.addElement((NS_PUBSUB_EVENT, 'event'))
        items = event.addElement('items')
        items['node'] = 'test'

        headers = shim.Headers([('Collection', 'collection')])
        message.addChild(headers)

        def itemsReceived(event):
            self.assertEquals(JID('[email protected]/home'), event.recipient)
            self.assertEquals(JID('pubsub.example.org'), event.sender)
            self.assertEquals('test', event.nodeIdentifier)
            self.assertEquals({'Collection': ['collection']}, event.headers)

        d, self.protocol.itemsReceived = calledAsync(itemsReceived)
        self.stub.send(message)
        return d


    def test_event_delete(self):
        """
        Test receiving a delete event resulting in a call to deleteReceived.
        """
        message = domish.Element((None, 'message'))
        message['from'] = 'pubsub.example.org'
        message['to'] = '[email protected]/home'
        event = message.addElement((NS_PUBSUB_EVENT, 'event'))
        items = event.addElement('delete')
        items['node'] = 'test'

        def deleteReceived(event):
            self.assertEquals(JID('[email protected]/home'), event.recipient)
            self.assertEquals(JID('pubsub.example.org'), event.sender)
            self.assertEquals('test', event.nodeIdentifier)

        d, self.protocol.deleteReceived = calledAsync(deleteReceived)
        self.stub.send(message)
        return d


    def test_event_purge(self):
        """
        Test receiving a purge event resulting in a call to purgeReceived.
        """
        message = domish.Element((None, 'message'))
        message['from'] = 'pubsub.example.org'
        message['to'] = '[email protected]/home'
        event = message.addElement((NS_PUBSUB_EVENT, 'event'))
        items = event.addElement('purge')
#.........这里部分代码省略.........
开发者ID:Urthen,项目名称:Legacy-FritBot,代码行数:101,代码来源:test_pubsub.py

示例13: PubSubCommandsProtocolTest

class PubSubCommandsProtocolTest(unittest.TestCase):
    """
    """

    def setUp(self):
        self.stub = XmlStreamStub()
        self.stub.xmlstream.factory = FactoryWithJID()
        self.protocol = protocols.PubSubHandler()
        self.protocol.xmlstream = self.stub.xmlstream
        self.protocol.connectionInitialized()

    def test_getNodes(self):
        d = self.protocol.getNodes(JID(u'pubsub.example.com'),
                                   u'foo_node')
        iq = self.stub.output[-1]
        self.assertEqual(u'pubsub.example.com', iq.getAttribute(u'to'))
        self.assertEqual(u'get', iq.getAttribute(u'type'))
        self.failIf(iq.query is None)
        self.assertEqual(protocols.NS_DISCO_ITEMS, iq.query.uri)
        self.assertEqual(u'foo_node', iq.query.getAttribute(u'node'))
        response = toResponse(iq, u'result')
        response['to'] = \
            self.protocol.xmlstream.factory.authenticator.jid.full()
        query = response.addElement((protocols.NS_DISCO_ITEMS, u'query'))
        query[u'node'] = u'foo_node'
        child1 = query.addElement('item')
        child1['node'] = 'foodoo_child_1'
        child1['name'] = 'Foodoo child one'
        child1['jid'] = u'pubsub.example.com'
        child2 = query.addElement('item')
        child2['node'] = 'foodoo_child_2'
        child2['jid'] = u'pubsub.example.com'

        self.stub.send(response)

        def cb(result):
            self.assertEqual(
                [{'node': 'foodoo_child_1',
                  'jid': u'pubsub.example.com',
                  'name': 'Foodoo child one'},
                 {'node': 'foodoo_child_2',
                  'jid': u'pubsub.example.com'}],
                 result)

        d.addCallback(cb)
        return d

    def test_getSubscriptions(self):
        d = self.protocol.getSubscriptions(JID(u'pubsub.example.com'),
                                           u'foo_node')
        iq = self.stub.output[-1]
        self.assertEqual(u'pubsub.example.com', iq.getAttribute(u'to'))
        self.assertEqual(u'get', iq.getAttribute(u'type'))
        self.failIf(iq.pubsub is None)
        self.assertEqual(protocols.NS_PUBSUB_OWNER, iq.pubsub.uri)
        self.failIf(iq.pubsub.subscriptions is None)
        self.assertEqual(u'foo_node',
                         iq.pubsub.subscriptions.getAttribute(u'node'))
        response = toResponse(iq, u'result')
        response['to'] = \
            self.protocol.xmlstream.factory.authenticator.jid.full()
        response.addElement((protocols.NS_PUBSUB_OWNER, u'pubsub'))
        subscriptions = response.pubsub.addElement(u'subscriptions')
        subscriptions[u'node'] = u'foo_node'
        subscription1 = subscriptions.addElement(u'subscription')
        subscription1[u'jid'] = u'[email protected]'
        subscription1[u'subscription'] = u'unconfigured'
        subscription2 = subscriptions.addElement(u'subscription')
        subscription2[u'jid'] = u'[email protected]'
        subscription2[u'subscription'] = u'subscribed'
        subscription2[u'subid'] = u'123-abc'

        self.stub.send(response)

        def cb(result):
            self.assertEqual(
                [(JID(u'[email protected]'), u'unconfigured'),
                 (JID(u'[email protected]'), u'subscribed')],
                 result)

        d.addCallback(cb)
        return d

    def test_setSubscriptions(self):
        d = self.protocol.setSubscriptions(
            JID(u'pubsub.example.com'),
            u'foo_node',
            [(JID(u'[email protected]'), u'subscribed'),
             (JID(u'[email protected]'), u'none')])

        iq = self.stub.output[-1]
        self.assertEqual(u'pubsub.example.com', iq.getAttribute(u'to'))
        self.assertEqual(u'set', iq.getAttribute(u'type'))
        self.failIf(iq.pubsub is None)
        self.assertEqual(protocols.NS_PUBSUB_OWNER, iq.pubsub.uri)
        self.failIf(iq.pubsub.subscriptions is None)
        self.assertEqual(u'foo_node',
                         iq.pubsub.subscriptions.getAttribute(u'node'))
        subscriptions = iq.pubsub.subscriptions.children
        self.assertEqual(2, len(subscriptions))
#.........这里部分代码省略.........
开发者ID:Anup888,项目名称:collective.xmpp.core,代码行数:101,代码来源:test_pubsub.py

示例14: DiscoClientProtocolTest

class DiscoClientProtocolTest(unittest.TestCase):
    """
    Tests for L{disco.DiscoClientProtocol}.
    """

    def setUp(self):
        """
        Set up stub and protocol for testing.
        """
        self.stub = XmlStreamStub()
        self.protocol = disco.DiscoClientProtocol()
        self.protocol.xmlstream = self.stub.xmlstream
        self.protocol.connectionInitialized()

    def test_requestItems(self):
        """
        Test request sent out by C{requestItems} and parsing of response.
        """

        def cb(items):
            items = list(items)
            self.assertEqual(2, len(items))
            self.assertEqual(JID(u"test.example.org"), items[0].entity)

        d = self.protocol.requestItems(JID(u"example.org"), u"foo")
        d.addCallback(cb)

        iq = self.stub.output[-1]
        self.assertEqual(u"example.org", iq.getAttribute(u"to"))
        self.assertEqual(u"get", iq.getAttribute(u"type"))
        self.assertEqual(u"foo", iq.query.getAttribute(u"node"))
        self.assertEqual(NS_DISCO_ITEMS, iq.query.uri)

        response = toResponse(iq, u"result")
        query = response.addElement((NS_DISCO_ITEMS, u"query"))

        element = query.addElement(u"item")
        element[u"jid"] = u"test.example.org"
        element[u"node"] = u"music"
        element[u"name"] = u"Music from the time of Shakespeare"

        element = query.addElement(u"item")
        element[u"jid"] = u"test2.example.org"

        self.stub.send(response)
        return d

    def test_requestItemsFrom(self):
        """
        A disco items request can be sent with an explicit sender address.
        """
        d = self.protocol.requestItems(JID(u"example.org"), sender=JID(u"test.example.org"))

        iq = self.stub.output[-1]
        self.assertEqual(u"test.example.org", iq.getAttribute(u"from"))

        response = toResponse(iq, u"result")
        response.addElement((NS_DISCO_ITEMS, u"query"))
        self.stub.send(response)

        return d

    def test_requestInfo(self):
        """
        Test request sent out by C{requestInfo} and parsing of response.
        """

        def cb(info):
            self.assertIn((u"conference", u"text"), info.identities)
            self.assertIn(u"http://jabber.org/protocol/disco#info", info.features)
            self.assertIn(u"http://jabber.org/protocol/muc", info.features)

        d = self.protocol.requestInfo(JID(u"example.org"), "foo")
        d.addCallback(cb)

        iq = self.stub.output[-1]
        self.assertEqual(u"example.org", iq.getAttribute(u"to"))
        self.assertEqual(u"get", iq.getAttribute(u"type"))
        self.assertEqual(u"foo", iq.query.getAttribute(u"node"))
        self.assertEqual(NS_DISCO_INFO, iq.query.uri)

        response = toResponse(iq, u"result")
        query = response.addElement((NS_DISCO_INFO, u"query"))

        element = query.addElement(u"identity")
        element[u"category"] = u"conference"  # required
        element[u"type"] = u"text"  # required
        element[u"name"] = u"Romeo and Juliet, Act II, Scene II"  # optional

        element = query.addElement("feature")
        element[u"var"] = u"http://jabber.org/protocol/disco#info"  # required

        element = query.addElement(u"feature")
        element[u"var"] = u"http://jabber.org/protocol/muc"

        self.stub.send(response)
        return d

    def test_requestInfoFrom(self):
        """
#.........这里部分代码省略.........
开发者ID:carriercomm,项目名称:wokkel,代码行数:101,代码来源:test_disco.py

示例15: setUp

 def setUp(self):
     self.stub = XmlStreamStub()
     self.protocol = xmppim.RosterClientProtocol()
     self.protocol.xmlstream = self.stub.xmlstream
     self.protocol.connectionInitialized()
开发者ID:thepaul,项目名称:wokkel,代码行数:5,代码来源:test_xmppim.py


注:本文中的wokkel.test.helpers.XmlStreamStub类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。