Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Outbound character set handling in SMPP #332

Merged
merged 2 commits into from
Oct 10, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions vumi/transports/smpp/tests/test_smpp.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
import binascii

from twisted.internet.defer import Deferred, inlineCallbacks, succeed
Expand Down Expand Up @@ -506,6 +507,34 @@ def test_submit_and_deliver(self):
dispatched_failures = self.get_dispatched_failures()
self.assertEqual(dispatched_failures, [])

@inlineCallbacks
def test_submit_sm_encoding(self):
# Startup
yield self.startTransport()
self.transport.submit_sm_encoding = 'latin-1'
yield self.transport._block_till_bind
yield self.clear_link_pdus()

msg = TransportUserMessage(
to_addr="2772222222",
from_addr="2772000000",
content=u'Zoë destroyer of Ascii!',
transport_name=self.transport_name,
transport_type='ussd',
transport_metadata={},
rkey='%s.outbound' % self.transport_name,
timestamp='0',
)
yield self.dispatch(msg)

pdu_queue = self.service.factory.smsc.pdu_queue

submit_sm_pdu = yield pdu_queue.get()
sms = submit_sm_pdu['pdu']['body']['mandatory_parameters']
self.assertEqual(
sms['short_message'],
u'Zoë destroyer of Ascii!'.encode('latin-1'))

@inlineCallbacks
def test_submit_and_deliver_ussd_continue(self):
# Startup
Expand Down
6 changes: 5 additions & 1 deletion vumi/transports/smpp/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ class SmppTransportConfig(Transport.CONFIG_CLASS):
delivery_report_regex = ConfigRegex(
'What regex to use for matching delivery reports',
default=DELIVERY_REPORT_REGEX, static=True)
submit_sm_encoding = ConfigText(
'How to encode the SMS before putting on the wire', static=True,
default='utf-8')
data_coding_overrides = ConfigDict(
"Overrides for data_coding character set mapping. This is useful for "
"setting the default encoding (0), adding additional undefined "
Expand Down Expand Up @@ -153,6 +156,7 @@ def setup_transport(self):
log.msg("Starting the SmppTransport for %s" % (
config.twisted_endpoint))

self.submit_sm_encoding = config.submit_sm_encoding
default_prefix = "%s@%s" % (config.system_id, config.transport_name)

r_config = config.redis_manager
Expand Down Expand Up @@ -431,7 +435,7 @@ def send_smpp(self, message):
config.OPERATOR_PREFIX,
config.OPERATOR_NUMBER)
return self.esme_client.submit_sm(
short_message=text.encode('utf-8'),
short_message=text.encode(self.submit_sm_encoding),
destination_addr=str(to_addr),
source_addr=route or from_addr,
message_type=message['transport_type'],
Expand Down