def test_graceful_unbind(self): smpp = self.getProtocolObject() smpp.sendPDU = Mock() smpp.sessionState = SMPPSessionStates.BOUND_TRX #setup outbound txn outPdu = SubmitSM( seqNum=98790, source_addr='mobileway', destination_addr='1208230', short_message='HELLO1', ) outRespPdu = outPdu.requireAck(seqNum=outPdu.seqNum) outDeferred = smpp.startOutboundTransaction(outPdu, 1) #setup inbound txn inPdu = DeliverSM( seqNum=764765, source_addr='mobileway', destination_addr='1208230', short_message='HELLO1', ) inDeferred = smpp.startInboundTransaction(inPdu) #Call unbind unbindDeferred = smpp.unbind() #Assert unbind request not sent and deferred not fired self.assertEquals(0, smpp.sendPDU.call_count) self.assertFalse(unbindDeferred.called) #Simulate inbound txn finishing smpp.endInboundTransaction(inPdu) #Assert unbind request not sent and deferred not fired self.assertEquals(0, smpp.sendPDU.call_count) self.assertFalse(unbindDeferred.called) #Simulate outbound txn finishing smpp.endOutboundTransaction(outRespPdu) #Assert unbind request was sent but deferred not yet fired self.assertEquals(1, smpp.sendPDU.call_count) sentPdu = smpp.sendPDU.call_args[0][0] self.assertTrue(isinstance(sentPdu, Unbind)) self.assertFalse(unbindDeferred.called) bindResp = UnbindResp(seqNum=sentPdu.seqNum) #Simulate unbind_resp smpp.endOutboundTransaction(bindResp) #Assert unbind deferred fired self.assertTrue(unbindDeferred.called) self.assertTrue( isinstance(unbindDeferred.result, SMPPOutboundTxnResult)) expectedResult = SMPPOutboundTxnResult(smpp, sentPdu, bindResp) self.assertEquals(expectedResult, unbindDeferred.result)
def test_finish_txns(self): smpp = self.getProtocolObject() smpp.sendPDU = Mock() smpp.sessionState = SMPPSessionStates.BOUND_TRX #setup outbound txns outPdu1 = SubmitSM( seqNum=98790, source_addr='mobileway', destination_addr='1208230', short_message='HELLO1', ) outRespPdu1 = outPdu1.requireAck(seqNum=outPdu1.seqNum) outPdu2 = SubmitSM( seqNum=875, source_addr='mobileway', destination_addr='1208230', short_message='HELLO1', ) outRespPdu2 = outPdu2.requireAck(seqNum=outPdu2.seqNum, status=CommandStatus.ESME_RINVSRCTON) outDeferred1 = smpp.startOutboundTransaction(outPdu1, 1) outDeferred2 = smpp.startOutboundTransaction(outPdu2, 1) finishOutTxns = smpp.finishOutboundTxns() #Simulate second txn having error smpp.endOutboundTransactionErr(outRespPdu2, FakeClientError('test')) #Assert txns not done yet self.assertFalse(finishOutTxns.called) #Simulate first txn finishing smpp.endOutboundTransaction(outRespPdu1) #Assert txns are all done self.assertTrue(finishOutTxns.called) return defer.DeferredList([ outDeferred1, self.assertFailure(outDeferred2, FakeClientError), finishOutTxns, ])