Exemplo n.º 1
0
    def test_request_error(self):
        payload_received = []
        errors_received = []

        def callback(payload):
            payload_received.append(payload)

        def error_callback(stanza):
            errors_received.append(stanza)

        processor = Processor([])
        request_software_version(processor, JID("*****@*****.**"), callback, error_callback)
        self.assertEqual(len(processor.stanzas_sent), 1)
        request = processor.stanzas_sent[0]
        self.assertIsInstance(request, Iq)
        self.assertEqual(request.stanza_type, "get")
        payload = request.get_payload(VersionPayload)
        self.assertIsNone(payload.name)
        self.assertIsNone(payload.version)
        self.assertIsNone(payload.os_name)
        response = request.make_error_response(u"service-unavailable")
        processor.uplink_receive(response)
        self.assertEqual(len(processor.stanzas_sent), 1)
        self.assertEqual(len(payload_received), 0)
        self.assertEqual(len(errors_received), 1)
        received = errors_received[0]
        self.assertIsInstance(received, Iq)
        self.assertEqual(received.stanza_type, "error")
Exemplo n.º 2
0
    def test_request(self):
        payload_received = []
        errors_received = []

        def callback(payload):
            payload_received.append(payload)

        def error_callback(stanza):
            errors_received.append(stanza)

        processor = Processor([])
        request_software_version(processor, JID("*****@*****.**"), callback, error_callback)
        self.assertEqual(len(processor.stanzas_sent), 1)
        request = processor.stanzas_sent[0]
        self.assertIsInstance(request, Iq)
        self.assertEqual(request.stanza_type, "get")
        payload = request.get_payload(VersionPayload)
        self.assertIsNone(payload.name)
        self.assertIsNone(payload.version)
        self.assertIsNone(payload.os_name)
        response = request.make_result_response()
        payload = XMLPayload(ElementTree.XML(IQ2)[0])
        response.set_payload(payload)
        processor.uplink_receive(response)
        self.assertEqual(len(processor.stanzas_sent), 1)
        self.assertEqual(len(payload_received), 1)
        self.assertEqual(len(errors_received), 0)
        payload = payload_received[0]
        self.assertEqual(payload.name, "NAME")
        self.assertEqual(payload.version, "VERSION")
        self.assertEqual(payload.os_name, "OS")
Exemplo n.º 3
0
    def test_request_error(self):
        payload_received = []
        errors_received = []

        def callback(payload):
            payload_received.append(payload)

        def error_callback(stanza):
            errors_received.append(stanza)

        processor = Processor([])
        request_software_version(processor, JID("*****@*****.**"), callback,
                                 error_callback)
        self.assertEqual(len(processor.stanzas_sent), 1)
        request = processor.stanzas_sent[0]
        self.assertIsInstance(request, Iq)
        self.assertEqual(request.stanza_type, "get")
        payload = request.get_payload(VersionPayload)
        self.assertIsNone(payload.name)
        self.assertIsNone(payload.version)
        self.assertIsNone(payload.os_name)
        response = request.make_error_response(u'service-unavailable')
        processor.uplink_receive(response)
        self.assertEqual(len(processor.stanzas_sent), 1)
        self.assertEqual(len(payload_received), 0)
        self.assertEqual(len(errors_received), 1)
        received = errors_received[0]
        self.assertIsInstance(received, Iq)
        self.assertEqual(received.stanza_type, "error")
Exemplo n.º 4
0
    def test_request(self):
        payload_received = []
        errors_received = []

        def callback(payload):
            payload_received.append(payload)

        def error_callback(stanza):
            errors_received.append(stanza)

        processor = Processor([])
        request_software_version(processor, JID("*****@*****.**"), callback,
                                 error_callback)
        self.assertEqual(len(processor.stanzas_sent), 1)
        request = processor.stanzas_sent[0]
        self.assertIsInstance(request, Iq)
        self.assertEqual(request.stanza_type, "get")
        payload = request.get_payload(VersionPayload)
        self.assertIsNone(payload.name)
        self.assertIsNone(payload.version)
        self.assertIsNone(payload.os_name)
        response = request.make_result_response()
        payload = XMLPayload(ElementTree.XML(IQ2)[0])
        response.set_payload(payload)
        processor.uplink_receive(response)
        self.assertEqual(len(processor.stanzas_sent), 1)
        self.assertEqual(len(payload_received), 1)
        self.assertEqual(len(errors_received), 0)
        payload = payload_received[0]
        self.assertEqual(payload.name, "NAME")
        self.assertEqual(payload.version, "VERSION")
        self.assertEqual(payload.os_name, "OS")
Exemplo n.º 5
0
 def handle_authorized(self, event):
     """Send the initial presence after log-in."""
     request_software_version(self.client, self.target_jid,
                                     self.success, self.failure)
Exemplo n.º 6
0
 def handle_authorized(self, event):
     """Send the initial presence after log-in."""
     request_software_version(self.client, self.target_jid, self.success,
                              self.failure)