Skip to content

Commit

Permalink
Merge pull request #149 from zoufou/v0.6-beta
Browse files Browse the repository at this point in the history
v0.6b12
  • Loading branch information
farirat committed May 13, 2015
2 parents 9b23cfc + e098804 commit 2da1632
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 23 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.6b11.tar.gz
- sudo pip install dist/jasmin-0.6b12.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 = 11
PATCH = 12
META = 'b'

def get_version():
Expand Down
31 changes: 21 additions & 10 deletions jasmin/protocols/smpp/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import struct
import math
import re
from jasmin.vendor.smpp.pdu.operations import SubmitSM, DataSM
from jasmin.vendor.smpp.pdu.operations import SubmitSM, DataSM, DeliverSM
from jasmin.protocols.smpp.configs import SMPPClientConfig
from jasmin.vendor.smpp.pdu.pdu_types import (EsmClass,
EsmClassMode,
Expand Down Expand Up @@ -151,16 +151,27 @@ def SubmitSM(self, short_message, data_coding = 0, **kwargs):

return pdu

def getReceipt(self, msgid, source_addr, destination_addr, message_status):
"Will build a DataSm containing a receipt data"
def getReceipt(self, dlr_pdu, msgid, source_addr, destination_addr, message_status):
"Will build a DataSm or a DeliverSm (depending on dlr_pdu) containing a receipt data"

# Build pdu
pdu = DataSM(
source_addr = source_addr,
destination_addr = destination_addr,
esm_class = EsmClass(EsmClassMode.DEFAULT, EsmClassType.SMSC_DELIVERY_RECEIPT),
receipted_message_id = msgid,
)
if dlr_pdu == 'deliver_sm':
# Build DeliverSM pdu
# Note:
# message_payload is not set in pdu since it seems there's a bug in smpp.pdu
pdu = DeliverSM(
source_addr = destination_addr,
destination_addr = source_addr,
esm_class = EsmClass(EsmClassMode.DEFAULT, EsmClassType.SMSC_DELIVERY_RECEIPT),
receipted_message_id = msgid,
)
else:
# Build DataSM pdu
pdu = DataSM(
source_addr = destination_addr,
destination_addr = source_addr,
esm_class = EsmClass(EsmClassMode.DEFAULT, EsmClassType.SMSC_DELIVERY_RECEIPT),
receipted_message_id = msgid,
)

# Set pdu.message_state
if message_status[:5] == 'ESME_':
Expand Down
3 changes: 3 additions & 0 deletions jasmin/routing/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def __init__(self, config_file = None):
self.timeout = self._getint('dlr-thrower', 'http_timeout', 30)
self.retry_delay = self._getint('dlr-thrower', 'retry_delay', 30)
self.max_retries = self._getint('dlr-thrower', 'max_retries', 3)

#139: need configuration to send deliver_sm instead of data_sm for SMPP delivery receipt
self.dlr_pdu = self._get('dlr-thrower', 'dlr_pdu', 'data_sm')

# Logging
self.log_level = logging.getLevelName(self._get('dlr-thrower', 'log_level', 'INFO'))
Expand Down
8 changes: 4 additions & 4 deletions jasmin/routing/test/test_router_smpps.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,8 @@ def test_receive_ACCEPT_on_ESME_ROK(self):
self.assertEqual(response_pdu_2.id, pdu_types.CommandId.data_sm)
self.assertEqual(response_pdu_2.seqNum, 1)
self.assertEqual(response_pdu_2.status, pdu_types.CommandStatus.ESME_ROK)
self.assertEqual(response_pdu_2.params['source_addr'], SubmitSmPDU.params['source_addr'])
self.assertEqual(response_pdu_2.params['destination_addr'], SubmitSmPDU.params['destination_addr'])
self.assertEqual(response_pdu_2.params['source_addr'], SubmitSmPDU.params['destination_addr'])
self.assertEqual(response_pdu_2.params['destination_addr'], SubmitSmPDU.params['source_addr'])
self.assertEqual(response_pdu_2.params['receipted_message_id'], response_pdu_1.params['message_id'])
self.assertEqual(str(response_pdu_2.params['message_state']), 'ACCEPTED')
# smpps last response was a unbind_resp
Expand Down Expand Up @@ -568,8 +568,8 @@ def test_receive_NACK_deliver_sm_on_delivery_error(self):
self.assertEqual(response_pdu_2.id, pdu_types.CommandId.data_sm)
self.assertEqual(response_pdu_2.seqNum, 1)
self.assertEqual(response_pdu_2.status, pdu_types.CommandStatus.ESME_ROK)
self.assertEqual(response_pdu_2.params['source_addr'], SubmitSmPDU.params['source_addr'])
self.assertEqual(response_pdu_2.params['destination_addr'], SubmitSmPDU.params['destination_addr'])
self.assertEqual(response_pdu_2.params['source_addr'], SubmitSmPDU.params['destination_addr'])
self.assertEqual(response_pdu_2.params['destination_addr'], SubmitSmPDU.params['source_addr'])
self.assertEqual(response_pdu_2.params['receipted_message_id'], response_pdu_1.params['message_id'])
self.assertEqual(str(response_pdu_2.params['message_state']), 'UNDELIVERABLE')

Expand Down
8 changes: 4 additions & 4 deletions jasmin/routing/test/test_routing_submit_sm_and_dlr.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,8 +905,8 @@ def test_receipt_as_deliver_sm(self):
self.assertEqual(response_pdu_x.id, pdu_types.CommandId.data_sm)
self.assertEqual(response_pdu_x.seqNum, x - 1)
self.assertEqual(response_pdu_x.status, pdu_types.CommandStatus.ESME_ROK)
self.assertEqual(response_pdu_x.params['source_addr'], SubmitSmPDU.params['source_addr'])
self.assertEqual(response_pdu_x.params['destination_addr'], SubmitSmPDU.params['destination_addr'])
self.assertEqual(response_pdu_x.params['source_addr'], SubmitSmPDU.params['destination_addr'])
self.assertEqual(response_pdu_x.params['destination_addr'], SubmitSmPDU.params['source_addr'])
self.assertEqual(response_pdu_x.params['receipted_message_id'], response_pdu_1.params['message_id'])
self.assertEqual(str(response_pdu_x.params['message_state']), self.formatted_stats[stat])

Expand Down Expand Up @@ -935,8 +935,8 @@ def test_receipt_as_deliver_sm(self):
self.assertEqual(response_pdu_x.id, pdu_types.CommandId.data_sm)
self.assertEqual(response_pdu_x.seqNum, x - 1)
self.assertEqual(response_pdu_x.status, pdu_types.CommandStatus.ESME_ROK)
self.assertEqual(response_pdu_x.params['source_addr'], SubmitSmPDU.params['source_addr'])
self.assertEqual(response_pdu_x.params['destination_addr'], SubmitSmPDU.params['destination_addr'])
self.assertEqual(response_pdu_x.params['source_addr'], SubmitSmPDU.params['destination_addr'])
self.assertEqual(response_pdu_x.params['destination_addr'], SubmitSmPDU.params['source_addr'])
self.assertEqual(response_pdu_x.params['receipted_message_id'], response_pdu_1.params['message_id'])
self.assertEqual(str(response_pdu_x.params['message_state']), self.formatted_stats[stat])
final_state_triggered = True
Expand Down
71 changes: 69 additions & 2 deletions jasmin/routing/test/test_throwers_dlr.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from jasmin.queues.configs import AmqpConfig
from jasmin.routing.configs import DLRThrowerConfig
from jasmin.routing.throwers import DLRThrower
from jasmin.vendor.smpp.pdu import pdu_types
from jasmin.managers.content import DLRContentForHttpapi, DLRContentForSmpps
from jasmin.routing.test.http_server import LeafServer, TimeoutLeafServer, AckServer, NoAckServer, Error404Server
from jasmin.routing.test.test_router_smpps import SMPPClientTestCases
Expand Down Expand Up @@ -42,11 +43,11 @@ def setUp(self):
DLRThrowerConfigInstance.retry_delay = 1
DLRThrowerConfigInstance.max_retries = 2

# Launch the deliverSmThrower
# Launch the DLRThrower
self.DLRThrower = DLRThrower()
self.DLRThrower.setConfig(DLRThrowerConfigInstance)

# Add the broker to the deliverSmThrower
# Add the broker to the DLRThrower
yield self.DLRThrower.addAmqpBroker(self.amqpBroker)

@defer.inlineCallbacks
Expand Down Expand Up @@ -210,6 +211,72 @@ def publishDLRContentForSmppapi(self, message_status, msgid, system_id, source_a
content = DLRContentForSmpps(message_status, msgid, system_id, source_addr, destination_addr)
yield self.amqpBroker.publish(exchange='messaging', routing_key='dlr_thrower.smpps', content=content)

@defer.inlineCallbacks
def test_throwing_smpps_to_bound_connection_as_data_sm(self):
self.DLRThrower.ackMessage = mock.Mock(wraps=self.DLRThrower.ackMessage)
self.DLRThrower.rejectMessage = mock.Mock(wraps=self.DLRThrower.rejectMessage)
self.DLRThrower.smpp_dlr_callback = mock.Mock(wraps=self.DLRThrower.smpp_dlr_callback)

# Bind
yield self.connect('127.0.0.1', self.pbPort)
yield self.prepareRoutingsAndStartConnector()
yield self.smppc_factory.connectAndBind()

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

yield self.publishDLRContentForSmppapi('ESME_ROK', 'MSGID', 'username', '999', '000')

yield waitFor(1)

# Run tests
self.assertEqual(self.smppc_factory.lastProto.PDUDataRequestReceived.call_count, 1)
# the received pdu must be a DataSM
received_pdu_1 = self.smppc_factory.lastProto.PDUDataRequestReceived.call_args_list[0][0][0]
self.assertEqual(received_pdu_1.id, pdu_types.CommandId.data_sm)
self.assertEqual(received_pdu_1.params['source_addr'], '000')
self.assertEqual(received_pdu_1.params['destination_addr'], '999')
self.assertEqual(received_pdu_1.params['receipted_message_id'], 'MSGID')
self.assertEqual(str(received_pdu_1.params['message_state']), 'ACCEPTED')

# Unbind & Disconnect
yield self.smppc_factory.smpp.unbindAndDisconnect()
yield self.stopSmppClientConnectors()

@defer.inlineCallbacks
def test_throwing_smpps_to_bound_connection_as_deliver_sm(self):
self.DLRThrower.config.dlr_pdu = 'deliver_sm'

self.DLRThrower.ackMessage = mock.Mock(wraps=self.DLRThrower.ackMessage)
self.DLRThrower.rejectMessage = mock.Mock(wraps=self.DLRThrower.rejectMessage)
self.DLRThrower.smpp_dlr_callback = mock.Mock(wraps=self.DLRThrower.smpp_dlr_callback)

# Bind
yield self.connect('127.0.0.1', self.pbPort)
yield self.prepareRoutingsAndStartConnector()
yield self.smppc_factory.connectAndBind()

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

yield self.publishDLRContentForSmppapi('ESME_ROK', 'MSGID', 'username', '999', '000')

yield waitFor(1)

# Run tests
self.assertEqual(self.smppc_factory.lastProto.PDUDataRequestReceived.call_count, 1)
# the received pdu must be a DeliverSM
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['source_addr'], '000')
self.assertEqual(received_pdu_1.params['destination_addr'], '999')
self.assertEqual(received_pdu_1.params['receipted_message_id'], 'MSGID')
self.assertEqual(str(received_pdu_1.params['message_state']), 'ACCEPTED')

# Unbind & Disconnect
yield self.smppc_factory.smpp.unbindAndDisconnect()
yield self.stopSmppClientConnectors()

@defer.inlineCallbacks
def test_throwing_smpps_to_bound_connection(self):
self.DLRThrower.ackMessage = mock.Mock(wraps=self.DLRThrower.ackMessage)
Expand Down
3 changes: 2 additions & 1 deletion jasmin/routing/throwers.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,8 @@ def smpp_dlr_callback(self, message):
raise NoDelivererForSystemId(system_id)

# Build the Receipt PDU (data_sm)
pdu = self.opFactory.getReceipt(msgid = msgid,
pdu = self.opFactory.getReceipt(dlr_pdu = self.config.dlr_pdu,
msgid = msgid,
source_addr = source_addr,
destination_addr = destination_addr,
message_status = message_status,
Expand Down
5 changes: 5 additions & 0 deletions misc/config/jasmin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@
# Define how many retries should be performed for failing throws of DLR.
#max_retries = 3

# Specify the pdu type to consider when throwing a receipt through SMPPs, possible values:
# - data_sm (default pdu)
# - deliver_sm
#dlr_pdu = data_sm

# Specify the server verbosity level.
# This can be one of:
# NOTSET (disable logging)
Expand Down

0 comments on commit 2da1632

Please sign in to comment.