def testTRXServerUnbindRequestAfterSubmit(self):
        deferreds = []
        def _serviceHandler(system_id, smpp, pdu):
            d = defer.Deferred()
            deferreds.append(d)
            logging.debug("%s, %s, %s", system_id, smpp, pdu)
            return d
        self.proto.dataRequestHandler = lambda *args, **kwargs: _serviceHandler(self.proto.system_id, *args, **kwargs)
        self._bind()

        pdu = operations.SubmitSM(source_addr='t1', destination_addr='1208230', short_message='HELLO', seqNum=1)
        self.proto.dataReceived(self.encoder.encode(pdu))
        unbind_d = self.proto.unbind()
        print(self.tr.value())

        pdu2 = operations.SubmitSM(source_addr='t1', destination_addr='1208230', short_message='HELLO2', seqNum=2)
        self.proto.dataReceived(self.encoder.encode(pdu))

        self.assertEqual(1, len(deferreds))
        self.assertEqual(self.tr.value(), b'')
        self.tr.clear()
        deferreds[-1].callback(pdu_types.CommandStatus.ESME_ROK)
        deferreds = deferreds[:-1]
        submit_resp_pdu = operations.SubmitSMResp(seqNum=1)

        unbind_pdu = operations.Unbind(seqNum=1)
        # We should have a reply here as our service handler should not be called
        self.assertEqual(self.tr.value(), b'%s%s' % (self.encoder.encode(submit_resp_pdu), self.encoder.encode(unbind_pdu)))
        self.tr.clear()
        pdu = operations.UnbindResp(seqNum=1)
        self.proto.dataReceived(self.encoder.encode(pdu))
    def testTRXClientUnbindRequestAfterSubmit(self):
        d = defer.Deferred()
        def _serviceHandler(system_id, smpp, pdu):
            logging.debug("%s, %s, %s", system_id, smpp, pdu)
            return d
        self.proto.dataRequestHandler = lambda *args, **kwargs: _serviceHandler(self.proto.system_id, *args, **kwargs)
        self._bind()

        pdu = operations.SubmitSM(source_addr='t1', destination_addr='1208230', short_message='HELLO', seqNum=1)
        self.proto.dataReceived(self.encoder.encode(pdu))
        pdu = operations.Unbind(seqNum = 52)
        self.proto.dataReceived(self.encoder.encode(pdu))

        #All PDU requests should fail now.
        #Once we fire this we should get our Submit Resp and the unbind Resp
        pdu = operations.SubmitSM(source_addr='t1', destination_addr='1208230', short_message='goodbye', seqNum=5)
        self.proto.dataReceived(self.encoder.encode(pdu))

        unbind_resp_pdu = operations.UnbindResp(seqNum=52)
        submit_fail_pdu = operations.SubmitSMResp(status=pdu_types.CommandStatus.ESME_RINVBNDSTS, seqNum=5)
        # We should have a reply here as our service handler should not be called
        self.assertEqual(self.tr.value(), self.encoder.encode(submit_fail_pdu))
        self.tr.clear()

        d.callback(pdu_types.CommandStatus.ESME_ROK)
        #Then we should get our initial message response and the unbind response
        expected_pdu = operations.SubmitSMResp(seqNum=1)
        self.assertEqual(self.tr.value(), b'%s%s' % (self.encoder.encode(expected_pdu), self.encoder.encode(unbind_resp_pdu)))
 def testReceiverBindRequest(self):
     system_id = 'userA'
     pdu = operations.BindReceiver(system_id=system_id,
                                   password='******',
                                   seqNum=1)
     self.proto.dataReceived(self.encoder.encode(pdu))
     expected_pdu = operations.BindReceiverResp(system_id='userA', seqNum=1)
     self.assertEqual(self.tr.value(), self.encoder.encode(expected_pdu))
     self.tr.clear()
     connection = self.factory.getBoundConnections(system_id)
     self.assertEqual(connection.system_id, system_id)
     self.assertEqual(
         connection._binds[pdu_types.CommandId.bind_receiver][0],
         self.proto)
     bind_manager = self.factory.getBoundConnections(system_id)
     delivery_binding = bind_manager.getNextBindingForDelivery()
     self.assertTrue(delivery_binding is not None)
     # TODO Identify what should be returned here
     pdu = operations.SubmitSM(source_addr='t1',
                               destination_addr='1208230',
                               short_message='HELLO',
                               seqNum=6)
     self.proto.dataReceived(self.encoder.encode(pdu))
     expected_pdu = operations.SubmitSMResp(seqNum=6)
     self.assertEqual(self.tr.value(), self.encoder.encode(expected_pdu))
 def testUnboundSubmitRequest(self):
     pdu = operations.SubmitSM(source_addr='t1',
                               destination_addr='1208230',
                               short_message='HELLO',
                               seqNum=1)
     self.proto.dataReceived(self.encoder.encode(pdu))
     expected_pdu = operations.SubmitSMResp(
         status=pdu_types.CommandStatus.ESME_RINVBNDSTS, seqNum=1)
     self.assertEqual(self.tr.value(), self.encoder.encode(expected_pdu))
 def testEnquireTimeout(self):
     self._bind()
     pdu = operations.SubmitSM(source_addr='t1', destination_addr='1208230', short_message='HELLO', seqNum=6)
     self.proto.dataReceived(self.encoder.encode(pdu))
     expected_pdu = operations.SubmitSMResp(seqNum=6)
     self.assertEqual(self.tr.value(), self.encoder.encode(expected_pdu))
     self.service_calls.pop()
     self.tr.clear()
     self.clock.advance(0.1)
     self.clock.advance(0.1)
     self.assertEqual(self.proto.sessionState, SMPPSessionStates.UNBIND_PENDING)
 def testTRXSubmitSM(self):
     self._bind()
     pdu = operations.SubmitSM(source_addr='t1', destination_addr='1208230', short_message='HELLO', seqNum=6)
     self.proto.dataReceived(self.encoder.encode(pdu))
     expected_pdu = operations.SubmitSMResp(seqNum=6)
     self.assertEqual(self.tr.value(), self.encoder.encode(expected_pdu))
     system_id, smpp, pdu_notified = self.service_calls.pop()
     self.assertEqual(system_id, self.proto.system_id)
     self.assertEqual(pdu.params['short_message'], pdu_notified.params['short_message'])
     self.assertEqual(pdu.params['source_addr'], pdu_notified.params['source_addr'])
     self.assertEqual(pdu.params['destination_addr'], pdu_notified.params['destination_addr'])
 def testRecievePduWhileUnbindPending(self):
     self._bind()
     self.proto.unbind()
     expected_pdu = operations.Unbind(seqNum=1)
     self.assertEqual(self.tr.value(), self.encoder.encode(expected_pdu))
     self.tr.clear()
     pdu = operations.SubmitSM(source_addr='t1', destination_addr='1208230', short_message='HELLO', seqNum=6)
     self.proto.dataReceived(self.encoder.encode(pdu))
     expected_pdu = operations.SubmitSMResp(seqNum=6)
     self.assertEqual(self.tr.value(), b'')
     pdu = operations.UnbindResp(seqNum=1)
     self.proto.dataReceived(self.encoder.encode(pdu))
Beispiel #8
0
    def _submit_sm(self):
        # send submit_sm pdu
        message_text = 'This is message for sms'
        encoding = chardet.detect(message_text)['encoding']
        data_coding = pdu_types.DataCoding(pdu_types.DataCodingScheme.DEFAULT,
                                           pdu_types.DataCodingDefault.UCS2)
        message_text = message_text.decode(encoding).encode('UTF-16')

        sm_pdu = operations.SubmitSM(
            seqNum=1,
            short_message=message_text,
            destination_addr='380632588588',  # do not send messages to me :)
            source_addr_ton=pdu_types.AddrTon.ALPHANUMERIC,
            source_addr_npi=pdu_types.AddrNpi.UNKNOWN,
            source_addr='380632588588',
            dest_addr_ton=pdu_types.AddrTon.INTERNATIONAL,
            dest_addr_npi=pdu_types.AddrNpi.ISDN,
            data_coding=data_coding,
            registered_delivery=pdu_types.RegisteredDelivery(
                pdu_types.RegisteredDeliveryReceipt.
                SMSC_DELIVERY_RECEIPT_REQUESTED))

        print 'Send submit sm request\n'
        self.transport.write(self._pdu2bin(sm_pdu))