Skip to content

Commit

Permalink
Merge pull request #151 from zoufou/v0.6-beta
Browse files Browse the repository at this point in the history
0.6b14
  • Loading branch information
farirat committed May 15, 2015
2 parents cdf5fd1 + eca4329 commit 0bf6b92
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ python:
# Command to install dependencies
install:
- python setup.py sdist
- sudo pip install dist/jasmin-0.6b13.tar.gz
- sudo pip install dist/jasmin-0.6b14.tar.gz
# Commands to run tests:
script:
# Add jasmind to system autostartup:
Expand Down
2 changes: 1 addition & 1 deletion jasmin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

MAJOR = 0
MINOR = 6
PATCH = 13
PATCH = 14
META = 'b'

def get_version():
Expand Down
31 changes: 26 additions & 5 deletions jasmin/protocols/smpp/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,28 @@ def __init__( self ):
twistedSMPPClientProtocol.__init__(self)

self.longSubmitSmTxns = {}

def PDUReceived(self, pdu):
self.log.debug("SMPP Client received PDU [command: %s, sequence_number: %s, command_status: %s]" % (pdu.id, pdu.seqNum, pdu.status))
self.log.debug("Complete PDU dump: %s" % pdu)

"""A better version than vendor's PDUReceived method:
- Dont re-encode pdu !
if self.log.isEnabledFor(logging.DEBUG):
encoded = self.encoder.encode(pdu)
self.log.debug("Receiving data [%s]" % _safelylogOutPdu(encoded))
"""

#Signal SMPP operation
self.onSMPPOperation()

if isinstance(pdu, PDURequest):
self.PDURequestReceived(pdu)
elif isinstance(pdu, PDUResponse):
self.PDUResponseReceived(pdu)
else:
getattr(self, "onPDU_%s" % str(pdu.id))(pdu)

def connectionMade(self):
twistedSMPPClientProtocol.connectionMade(self)
self.log.info("Connection made to %s:%s" % (self.factory.config.host, self.factory.config.port))
Expand Down Expand Up @@ -238,15 +259,15 @@ def __init__( self ):
self.log = logging.getLogger(LOG_CATEGORY)

def PDUReceived(self, pdu):
"""A better version than vendor's PDUReceived method:
- Encode pdu only when in debug mode
"""
if self.log.isEnabledFor(logging.DEBUG):
self.log.debug("Received PDU: %s" % pdu)
self.log.debug("SMPP Server received PDU from system '%s' [command: %s, sequence_number: %s, command_status: %s]" % (self.system_id, pdu.id, pdu.seqNum, pdu.status))
self.log.debug("Complete PDU dump: %s" % pdu)

"""A better version than vendor's PDUReceived method:
- Dont re-encode pdu !
if self.log.isEnabledFor(logging.DEBUG):
encoded = self.encoder.encode(pdu)
self.log.debug("Receiving data [%s]" % _safelylogOutPdu(encoded))
"""

#Signal SMPP operation
self.onSMPPOperation()
Expand Down
10 changes: 10 additions & 0 deletions jasmin/protocols/smpp/test/test_pdu_decoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ def test_any_network_type(self):
self.assertEquals('GSM', str(pdu.params['source_network_type']))
self.assertEquals('GSM', str(pdu.params['dest_network_type']))

def test_any_network_error_code(self):
"Related to #117"

pduHex = '000000f3000000050000000000000001000101343931353235363739343838370001013034303531333036393939000400000000000000008569643a62633539623861612d326664322d343033352d383131332d313933303165303530303739207375623a30303120646c7672643a303031207375626d697420646174653a31353035303831343430353820646f6e6520646174653a31353035303831343430353820737461743a44454c49565244206572723a30303020746578743a2d042300030300000427000102001e002562633539623861612d326664322d343033352d383131332d31393330316530353030373900'
pdu = self.getPDU(pduHex)
SMStringEncoder().decodeSM(pdu)

# Asserts
self.assertEquals('\x03\x00\x00', str(pdu.params['network_error_code']))

def test_deliver_sm_with_message_payload(self):
pduHex = '0000009200000005000000000001693c00000032313635333532303730330000003737383800040000000001000000000424004f69643a30303030343336393439207375626d697420646174653a3135303432313135303820646f6e6520646174653a3135303432313135303820737461743a44454c49565244206572723a30303000001e00063661616435000427000102'
pdu = self.getPDU(pduHex)
Expand Down
25 changes: 25 additions & 0 deletions jasmin/protocols/smpp/test/test_pdu_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,31 @@ def test_DeliverSM_with_subaddress(self):
)
self.do_conversion_test(PDUEncoder(), pdu, '00000066000000050000000000000001424d38000101343631323334353637383900010131343034363635333431300000000000000000f2001b48656c6c6f2049276d206120626967672066616e206f6620796f7502020004a037343202030005a034313331')

def test_DeliverSM_with_networ_error_code(self):
"Related to #117"

pdu = DeliverSM(1,
service_type = '',
source_addr_ton=AddrTon.INTERNATIONAL,
source_addr_npi=AddrNpi.ISDN,
source_addr='4915256794887',
dest_addr_ton=AddrTon.INTERNATIONAL,
dest_addr_npi=AddrNpi.ISDN,
destination_addr='04051306999',
esm_class=EsmClass(EsmClassMode.DEFAULT, EsmClassType.DEFAULT),
protocol_id=0,
priority_flag=PriorityFlag.LEVEL_0,
registered_delivery=RegisteredDelivery(RegisteredDeliveryReceipt.NO_SMSC_DELIVERY_RECEIPT_REQUESTED),
replace_if_present_flag=ReplaceIfPresentFlag.DO_NOT_REPLACE,
data_coding=DataCoding(DataCodingScheme.GSM_MESSAGE_CLASS, DataCodingGsmMsg(DataCodingGsmMsgCoding.DEFAULT_ALPHABET, DataCodingGsmMsgClass.CLASS_2)),
short_message='id:bc59b8aa-2fd2-4035-8113-19301e050079 sub:001 dlvrd:001 submit date:150508144058 done date:150508144058 stat:DELIVRD err:000 text:-',
sm_default_msg_id=0,
message_state=MessageState.DELIVERED,
receipted_message_id='bc59b8aa-2fd2-4035-8113-19301e050079',
network_error_code='\x03\x00\x00',
)
self.do_conversion_test(PDUEncoder(), pdu, '000000f30000000500000000000000010001013439313532353637393438383700010130343035313330363939390000000000000000f2008569643a62633539623861612d326664322d343033352d383131332d313933303165303530303739207375623a30303120646c7672643a303031207375626d697420646174653a31353035303831343430353820646f6e6520646174653a31353035303831343430353820737461743a44454c49565244206572723a30303020746578743a2d042300030300000427000102001e002562633539623861612d326664322d343033352d383131332d31393330316530353030373900')

def test_EnquireLink_conversion(self):
pdu = EnquireLink(6, CommandStatus.ESME_ROK)
self.do_conversion_test(PDUEncoder(), pdu, '00000010000000150000000000000006')
Expand Down
28 changes: 28 additions & 0 deletions jasmin/routing/test/test_routing_deliver_sm.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,34 @@ def test_long_content_delivery_UDH_SmppsConnector(self):
self.assertEqual(received_pdu_3.params['esm_class'], basePdu.params['esm_class'])
self.assertEqual(received_pdu_3.params['short_message'][6:], pdu_part3.params['short_message'][6:])

# Unbind and disconnect
yield self.smppc_factory.smpp.unbindAndDisconnect()
yield self.stopSmppClientConnectors()

@defer.inlineCallbacks
def test_delivery_SmppClientConnector_with_network_error_code(self):
"Related to #117"
yield self.connect('127.0.0.1', self.pbPort)
yield self.prepareRoutingsAndStartConnector()

# Bind
yield self.smppc_factory.connectAndBind()

# Install mocks
self.smppc_factory.lastProto.PDUDataRequestReceived = mock.Mock(wraps=self.smppc_factory.lastProto.PDUDataRequestReceived)

# Send a deliver_sm from the SMSC
DeliverSmPDU = copy.deepcopy(self.DeliverSmPDU)
DeliverSmPDU.params['network_error_code'] = '\x03\x00\x00'
yield self.triggerDeliverSmFromSMSC([DeliverSmPDU])

# Run tests
self.assertEqual(self.smppc_factory.lastProto.PDUDataRequestReceived.call_count, 1)
# the received pdu must be our DeliverSmPDU
received_pdu_1 = self.smppc_factory.lastProto.PDUDataRequestReceived.call_args_list[0][0][0]
self.assertEqual(received_pdu_1.id, pdu_types.CommandId.deliver_sm)
self.assertEqual(received_pdu_1.params['network_error_code'], DeliverSmPDU.params['network_error_code'])

# Unbind and disconnect
yield self.smppc_factory.smpp.unbindAndDisconnect()
yield self.stopSmppClientConnectors()

0 comments on commit 0bf6b92

Please sign in to comment.