def test_throwing_validity_parameter(self):
        self.AckServerResource.render_GET = mock.Mock(
            wraps=self.AckServerResource.render_GET)

        routedConnector = HttpConnector(
            'dst', 'http://127.0.0.1:%s/send' % self.AckServer.getHost().port)
        content = 'test_throwing_http_connector test content'
        self.testDeliverSMPdu.params['short_message'] = content

        # Set validity_period in deliver_sm and send it
        deliver_sm = copy.copy(self.testDeliverSMPdu)
        vp = datetime.today() + timedelta(minutes=20)
        deliver_sm.params['validity_period'] = vp
        self.publishRoutedDeliverSmContent(self.routingKey,
                                           self.testDeliverSMPdu, '1', 'src',
                                           routedConnector)

        yield waitFor(1)

        # No message retries must be made since ACK was received
        self.assertEqual(self.AckServerResource.render_GET.call_count, 1)

        callArgs = self.AckServerResource.render_GET.call_args_list[0][0][
            0].args
        self.assertTrue('validity' in callArgs)
        self.assertEqual(str(vp), callArgs['validity'][0])
    def test_throwing_http_with_message_payload(self):
        """Related to #380
        Will throw via http a pdu having 'message_payload' instead of 'short_message' parameter
        """
        self.AckServerResource.render_GET = mock.Mock(
            wraps=self.AckServerResource.render_GET)

        routedConnector = HttpConnector(
            'dst', 'http://127.0.0.1:%s/send' % self.AckServer.getHost().port)
        content = 'test_throwing_http_with_message_payload test content'
        del self.testDeliverSMPdu.params['short_message']
        self.testDeliverSMPdu.params['message_payload'] = content
        self.publishRoutedDeliverSmContent(self.routingKey,
                                           self.testDeliverSMPdu, '1', 'src',
                                           routedConnector)

        yield waitFor(1)

        # No message retries must be made since ACK was received
        self.assertEqual(self.AckServerResource.render_GET.call_count, 1)

        callArgs = self.AckServerResource.render_GET.call_args_list[0][0][
            0].args
        self.assertEqual(callArgs['content'][0], content)
        self.assertEqual(callArgs['from'][0],
                         self.testDeliverSMPdu.params['source_addr'])
        self.assertEqual(callArgs['to'][0],
                         self.testDeliverSMPdu.params['destination_addr'])
Пример #3
0
    def parse_args_and_call_with_instance(self, *args, **kwargs):
        cmd = args[0]
        arg = args[1]

        # Empty line
        if cmd is None:
            return self.protocol.sendData()
        # Initiate jasmin.routing.jasminApi.Group with sessBuffer content
        if cmd == 'ok':
            if len(self.sessBuffer) < len(self.protocol.sessionCompletitions):
                return self.protocol.sendData(
                    'You must set these options before saving: %s' %
                    ', '.join(self.protocol.sessionCompletitions))

            httpcc = {}
            for key, value in self.sessBuffer.items():
                httpcc[key] = value
            try:
                HttpccInstance = HttpConnector(**httpcc)
                # Hand the instance to fCallback
                return fCallback(self, httpcc['cid'], HttpccInstance)
            except Exception as e:
                return self.protocol.sendData('Error: %s' % str(e))
        else:
            # Unknown key
            if cmd not in HttpccKeyMap:
                return self.protocol.sendData('Unknown Httpcc key: %s' % cmd)

            # Buffer key for later SMPPClientConfig initiating
            HttpccKey = HttpccKeyMap[cmd]
            self.sessBuffer[HttpccKey] = arg

            return self.protocol.sendData()
    def test_throwing_http_connector_without_ack(self):
        self.NoAckServerResource.render_GET = mock.Mock(
            wraps=self.NoAckServerResource.render_GET)

        routedConnector = HttpConnector(
            'dst',
            'http://127.0.0.1:%s/send' % self.NoAckServer.getHost().port)
        content = 'test_throwing_http_connector test content'
        self.testDeliverSMPdu.params['short_message'] = content
        self.publishRoutedDeliverSmContent(self.routingKey,
                                           self.testDeliverSMPdu, '1', 'src',
                                           routedConnector)

        yield waitFor(4)

        # Retries must be made when ACK is not received
        self.assertTrue(self.NoAckServerResource.render_GET.call_count > 1)

        callArgs = self.NoAckServerResource.render_GET.call_args_list[0][0][
            0].args
        self.assertEqual(callArgs['content'][0],
                         self.testDeliverSMPdu.params['short_message'])
        self.assertEqual(callArgs['from'][0],
                         self.testDeliverSMPdu.params['source_addr'])
        self.assertEqual(callArgs['to'][0],
                         self.testDeliverSMPdu.params['destination_addr'])
Пример #5
0
    def test_throwing_http_utf8(self):
        """Related to #320
        Send utf8 content and check it was throwed while preserving the content as is"""
        self.AckServerResource.render_POST = Mock(
            wraps=self.AckServerResource.render_POST)

        routedConnector = HttpConnector(
            'dst', 'http://127.0.0.1:%s/send' % self.AckServer.getHost().port,
            'POST')
        content = b"\xd8\xaa\xd8\xb3\xd8\xaa"
        self.testDeliverSMPdu.params['short_message'] = content
        self.testDeliverSMPdu.params['data_coding'] = DataCoding(
            schemeData=DataCodingDefault.UCS2)
        self.publishRoutedDeliverSmContent(self.routingKey,
                                           self.testDeliverSMPdu, '1', 'src',
                                           routedConnector)

        yield waitFor(1)

        # Assert throwed content is equal to original content
        callArgs = self.AckServerResource.render_POST.call_args_list[0][0][
            0].args
        self.assertEqual(callArgs[b'content'][0], content)
        self.assertEqual(callArgs[b'coding'][0], b'\x08')
        self.assertEqual(callArgs[b'binary'][0], binascii.hexlify(content))
Пример #6
0
    def test_throwing_http_connector_with_ack(self):
        self.AckServerResource.render_POST = Mock(
            wraps=self.AckServerResource.render_POST)

        routedConnector = HttpConnector(
            'dst', 'http://127.0.0.1:%s/send' % self.AckServer.getHost().port,
            'POST')
        content = b'test_throwing_http_connector test content'
        self.testDeliverSMPdu.params['short_message'] = content
        self.publishRoutedDeliverSmContent(self.routingKey,
                                           self.testDeliverSMPdu, '1', 'src',
                                           routedConnector)

        yield waitFor(1)

        # No message retries must be made since ACK was received
        self.assertEqual(self.AckServerResource.render_POST.call_count, 1)

        callArgs = self.AckServerResource.render_POST.call_args_list[0][0][
            0].args
        self.assertEqual(callArgs[b'content'][0],
                         self.testDeliverSMPdu.params['short_message'])
        self.assertEqual(callArgs[b'from'][0],
                         self.testDeliverSMPdu.params['source_addr'])
        self.assertEqual(callArgs[b'to'][0],
                         self.testDeliverSMPdu.params['destination_addr'])
Пример #7
0
    def test_using_HttpConnector_dc(self):
        dc = HttpConnector('def', 'http://127.0.0.1')
        c = RoutedDeliverSmContent(self.body, self.msgid, self.scid, dc)

        self.assertEquals(pickle.loads(c.body), self.body)
        self.assertEquals(c['message-id'], self.msgid)
        self.assertEquals(c['headers']['src-connector-id'], self.scid)
        self.assertEquals(c['headers']['dst-connector-id'], dc.cid)

        dc = pickle.loads(c['headers']['dst-connector'])
        self.assertEquals(dc.cid, dc.cid)
Пример #8
0
    def test_using_HttpConnector_dc(self):
        dcs = [HttpConnector('def', 'http://127.0.0.1')]
        c = RoutedDeliverSmContent(self.body, self.msgid, self.scid, dcs)

        self.assertEquals(pickle.loads(c.body), self.body)
        self.assertEquals(c['message-id'], self.msgid)
        self.assertEquals(c['headers']['src-connector-id'], self.scid)
        self.assertEquals(c['headers']['route-type'], 'simple')

        _dcs = pickle.loads(c['headers']['dst-connectors'])
        self.assertEquals(_dcs[0].cid, dcs[0].cid)
    def test_throwing_http_connector_timeout_retry(self):
        self.TimeoutLeafServerResource.render_GET = mock.Mock(
            wraps=self.TimeoutLeafServerResource.render_GET)

        routedConnector = HttpConnector(
            'dst',
            'http://127.0.0.1:%s/send' % self.TimeoutLeafServer.getHost().port)

        self.publishRoutedDeliverSmContent(self.routingKey,
                                           self.testDeliverSMPdu, '1', 'src',
                                           routedConnector)

        # Wait 12 seconds (timeout is set to 2 seconds in deliverSmThrowerTestCase.setUp(self)
        yield waitFor(12)

        self.assertEqual(self.TimeoutLeafServerResource.render_GET.call_count,
                         2)
Пример #10
0
    def test_throwing_http_connector_404_error_noretry(self):
        """When receiving a 404 error, no further retries shall be made
        """
        self.Error404ServerResource.render_GET = mock.Mock(
            wraps=self.Error404ServerResource.render_GET)

        routedConnector = HttpConnector(
            'dst',
            'http://127.0.0.1:%s/send' % self.Error404Server.getHost().port)

        self.publishRoutedDeliverSmContent(self.routingKey,
                                           self.testDeliverSMPdu, '1', 'src',
                                           routedConnector)

        # Wait 1 second
        yield waitFor(1)

        self.assertEqual(self.Error404ServerResource.render_GET.call_count, 1)
Пример #11
0
    def test_throwing_http_connector_timeout_retry(self):
        self.TimeoutLeafServerResource.render_POST = Mock(
            wraps=self.TimeoutLeafServerResource.render_POST)

        routedConnector = HttpConnector(
            'dst',
            'http://127.0.0.1:%s/send' % self.TimeoutLeafServer.getHost().port,
            'POST')

        self.publishRoutedDeliverSmContent(self.routingKey,
                                           self.testDeliverSMPdu, '1', 'src',
                                           routedConnector)

        # Wait 12 seconds (timeout is set to 2 seconds in deliverSmThrowerTestCase.setUp(self)
        yield waitFor(15)

        # We shoould have 2 to 4 calls (depends on the resource availability)
        self.assertApproximates(
            self.TimeoutLeafServerResource.render_POST.call_count, 3, 1)
Пример #12
0
    def test_throwing_http_without_validity(self):
        """Related to #380
        Will throw via http a pdu having no validity_period parameter
        """
        self.AckServerResource.render_GET = mock.Mock(
            wraps=self.AckServerResource.render_GET)

        routedConnector = HttpConnector(
            'dst', 'http://127.0.0.1:%s/send' % self.AckServer.getHost().port)
        content = 'test_throwing_http_without_priority test content'
        del self.testDeliverSMPdu.params['validity_period']
        self.testDeliverSMPdu.params['short_message'] = content
        self.publishRoutedDeliverSmContent(self.routingKey,
                                           self.testDeliverSMPdu, '1', 'src',
                                           routedConnector)

        yield waitFor(1)

        # No message retries must be made since ACK was received
        self.assertEqual(self.AckServerResource.render_GET.call_count, 1)