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


Python XmlStreamStub.send方法代码示例

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


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

示例1: VersionHandlerTest

# 需要导入模块: from wokkel.test.helpers import XmlStreamStub [as 别名]
# 或者: from wokkel.test.helpers.XmlStreamStub import send [as 别名]
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,代码行数:37,代码来源:test_generic.py

示例2: RosterClientProtocolTest

# 需要导入模块: from wokkel.test.helpers import XmlStreamStub [as 别名]
# 或者: from wokkel.test.helpers.XmlStreamStub import send [as 别名]
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,代码行数:39,代码来源:test_xmppim.py

示例3: PingClientProtocolTest

# 需要导入模块: from wokkel.test.helpers import XmlStreamStub [as 别名]
# 或者: from wokkel.test.helpers.XmlStreamStub import send [as 别名]
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,代码行数:88,代码来源:test_ping.py

示例4: PingHandlerTest

# 需要导入模块: from wokkel.test.helpers import XmlStreamStub [as 别名]
# 或者: from wokkel.test.helpers.XmlStreamStub import send [as 别名]
class PingHandlerTest(unittest.TestCase):
    """
    Tests for L{ping.PingHandler}.
    """

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


    def test_onPing(self):
        """
        A ping should have a simple result response.
        """
        xml = """<iq from='[email protected]' to='example.com' type='get'>
                   <ping xmlns='urn:xmpp:ping'/>
                 </iq>"""
        self.stub.send(parseXml(xml))

        response = self.stub.output[-1]
        self.assertEquals('example.com', response.getAttribute('from'))
        self.assertEquals('[email protected]', response.getAttribute('to'))
        self.assertEquals('result', response.getAttribute('type'))


    def test_interfaceIDisco(self):
        """
        The ping handler should provice Service Discovery information.
        """
        verify.verifyObject(iwokkel.IDisco, self.protocol)


    def test_getDiscoInfo(self):
        """
        The ping namespace should be returned as a supported feature.
        """
        def cb(info):
            discoInfo = disco.DiscoInfo()
            for item in info:
                discoInfo.append(item)
            self.assertIn('urn:xmpp:ping', discoInfo.features)

        d = defer.maybeDeferred(self.protocol.getDiscoInfo,
                                JID('[email protected]/home'),
                                JID('pubsub.example.org'),
                                '')
        d.addCallback(cb)
        return d


    def test_getDiscoInfoNode(self):
        """
        The ping namespace should not be returned for a node.
        """
        def cb(info):
            discoInfo = disco.DiscoInfo()
            for item in info:
                discoInfo.append(item)
            self.assertNotIn('urn:xmpp:ping', discoInfo.features)

        d = defer.maybeDeferred(self.protocol.getDiscoInfo,
                                JID('[email protected]/home'),
                                JID('pubsub.example.org'),
                                'test')
        d.addCallback(cb)
        return d


    def test_getDiscoItems(self):
        """
        Items are not supported by this handler, so an empty list is expected.
        """
        def cb(items):
            self.assertEquals(0, len(items))

        d = defer.maybeDeferred(self.protocol.getDiscoItems,
                                JID('[email protected]/home'),
                                JID('pubsub.example.org'),
                                '')
        d.addCallback(cb)
        return d
开发者ID:B-Rich,项目名称:wokkel,代码行数:85,代码来源:test_ping.py

示例5: DifferentialSyncronisationHandlerFunctionalTest

# 需要导入模块: from wokkel.test.helpers import XmlStreamStub [as 别名]
# 或者: from wokkel.test.helpers.XmlStreamStub import send [as 别名]
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,代码行数:103,代码来源:test_protocol_functional.py

示例6: AdminCommandsProtocolTest

# 需要导入模块: from wokkel.test.helpers import XmlStreamStub [as 别名]
# 或者: from wokkel.test.helpers.XmlStreamStub import send [as 别名]
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,代码行数:103,代码来源:test_admin.py

示例7: DifferentialSyncronisationHandlerTest

# 需要导入模块: from wokkel.test.helpers import XmlStreamStub [as 别名]
# 或者: from wokkel.test.helpers.XmlStreamStub import send [as 别名]
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,代码行数:103,代码来源:test_protocol.py

示例8: PubSubClientTest

# 需要导入模块: from wokkel.test.helpers import XmlStreamStub [as 别名]
# 或者: from wokkel.test.helpers.XmlStreamStub import send [as 别名]
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,代码行数:103,代码来源:test_pubsub.py

示例9: PubSubCommandsProtocolTest

# 需要导入模块: from wokkel.test.helpers import XmlStreamStub [as 别名]
# 或者: from wokkel.test.helpers.XmlStreamStub import send [as 别名]
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,代码行数:103,代码来源:test_pubsub.py

示例10: DiscoClientProtocolTest

# 需要导入模块: from wokkel.test.helpers import XmlStreamStub [as 别名]
# 或者: from wokkel.test.helpers.XmlStreamStub import send [as 别名]
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,代码行数:103,代码来源:test_disco.py

示例11: MucClientTest

# 需要导入模块: from wokkel.test.helpers import XmlStreamStub [as 别名]
# 或者: from wokkel.test.helpers.XmlStreamStub import send [as 别名]
class MucClientTest(unittest.TestCase):
    timeout = 2

    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')

    def _createRoom(self):
        """A helper method to create a test room.
        """
        # create a room
        self.current_room = muc.Room(self.test_room, self.test_srv, self.test_nick)
        self.protocol._setRoom(self.current_room)


    def test_interface(self):
        """
        Do instances of L{muc.MUCClient} provide L{iwokkel.IMUCClient}?
        """
        verify.verifyObject(iwokkel.IMUCClient, self.protocol)


    def test_userJoinedRoom(self):
        """The client receives presence from an entity joining the room.

        This tests the class L{muc.UserPresence} and the userJoinedRoom event method.

        The test sends the user presence and tests if the event method is called.

        """
        p = muc.UserPresence()
	p['to'] = self.user_jid.full()
        p['from'] = self.room_jid.full()

        # create a room
        self._createRoom()

        def userPresence(room, user):
            self.failUnless(room.name==self.test_room, 'Wrong room name')
            self.failUnless(room.inRoster(user), 'User not in roster')
            	           
	
        d, self.protocol.userJoinedRoom = calledAsync(userPresence)
        self.stub.send(p)
        return d


    def test_groupChat(self):
        """The client receives a groupchat message from an entity in the room.
        """
        m = muc.GroupChat('[email protected]',body='test')
	m['from'] = self.room_jid.full()

        self._createRoom()

        def groupChat(room, user, message):
            self.failUnless(message=='test', "Wrong group chat message")
            self.failUnless(room.name==self.test_room, 'Wrong room name')
            	           
	
        d, self.protocol.receivedGroupChat = calledAsync(groupChat)
        self.stub.send(m)
        return d


    def test_discoServerSupport(self):
        """Disco support from client to server.
        """
        test_srv = 'shakespeare.lit'

        def cb(query):
            # check namespace
            self.failUnless(query.uri==disco.NS_INFO, 'Wrong namespace')
            

        d = self.protocol.disco(test_srv)
        d.addCallback(cb)

        iq = self.stub.output[-1]
        
        # send back a response
        response = toResponse(iq, 'result')
        response.addElement('query', disco.NS_INFO)
        # need to add information to response
        response.query.addChild(disco.DiscoFeature(muc.NS_MUC))
        response.query.addChild(disco.DiscoIdentity(category='conference',
                                                    name='Macbeth Chat Service',
                                                    type='text'))
        
        self.stub.send(response)
        return d
#.........这里部分代码省略.........
开发者ID:Urthen,项目名称:Legacy-FritBot,代码行数:103,代码来源:test_muc.py


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