Skip to content

Commit

Permalink
handle ussd message
Browse files Browse the repository at this point in the history
  • Loading branch information
smn committed Jan 18, 2014
1 parent e9367a6 commit e9dde9c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions txssmi/commands.py
Expand Up @@ -30,3 +30,4 @@
PremiumMoMessage = SSMIResponse.create('PREMIUM_MO')
PremiumBMoMessage = SSMIResponse.create('PREMIUM_BINARY_MO')
IMSILookupReply = SSMIResponse.create('IMSI_LOOKUP_REPLY')
USSDMessage = SSMIResponse.create('USSD_MESSAGE')
6 changes: 6 additions & 0 deletions txssmi/constants.py
Expand Up @@ -31,6 +31,7 @@
'107': ('PREMIUM_MO', ['msisdn', 'sequence', 'destination', 'message']),
'108': ('PREMIUM_BINARY_MO', ['msisdn', 'sequence', 'pid', 'coding',
'destination', 'hex_msg']),
'110': ('USSD_MESSAGE', ['msisdn', 'type', 'phase', 'message']),
'600': ('IMSI_LOOKUP_REPLY', ['sequence', 'msisdn', 'imsi', 'spid']),
}

Expand All @@ -50,9 +51,14 @@
USSD_NEW = '1'
USSD_RESPONSE = '2'
USSD_END = '3'
USSD_TIMEOUT = '4'
USSD_REDIRECT = '5'
USSD_INITIATE = '6'

USSD_PHASE_UNKNOWN = '0'
USSD_PHASE_1 = '1'
USSD_PHASE_2 = '2'

ACK_LOGIN_OK = '1'
ACK_LINK_CHECK_RESPONSE = '2'

Expand Down
3 changes: 3 additions & 0 deletions txssmi/protocol.py
Expand Up @@ -167,3 +167,6 @@ def handle_PREMIUM_MO(self, pmo):

def handle_PREMIUM_BINARY_MO(self, bmo):
log.msg('Received PREMIUM_BINARY_MO: %r' % (bmo,))

def handle_USSD_MESSAGE(self, um):
log.msg('Received USSD_MESSAGE: %r' % (um,))
20 changes: 15 additions & 5 deletions txssmi/tests/test_protocol.py
Expand Up @@ -9,10 +9,11 @@
from txssmi.builder import SSMIRequest
from txssmi.commands import (
Login, Ack, IMSILookupReply, Seq, MoMessage, DrMessage, FFMessage,
BMoMessage, PremiumMoMessage, PremiumBMoMessage)
BMoMessage, PremiumMoMessage, PremiumBMoMessage, USSDMessage)
from txssmi.protocol import SSMIProtocol
from txssmi.constants import (
CODING_8BIT, PROTOCOL_ENHANCED, USSD_INITIATE, USSD_NEW, DR_SUCCESS)
CODING_8BIT, PROTOCOL_ENHANCED, USSD_INITIATE, USSD_NEW, DR_SUCCESS,
USSD_PHASE_2, USSD_TIMEOUT)


class ProtocolTestCase(TestCase):
Expand Down Expand Up @@ -225,8 +226,17 @@ def test_premium_binary_mo(self):
self.patch(self.protocol_class, 'handle_PREMIUM_BINARY_MO',
calls.append)
cmd = PremiumBMoMessage(msisdn='2700000000', sequence='1',
coding=CODING_8BIT, pid=PROTOCOL_ENHANCED,
hex_msg=binascii.hexlify('hello'),
destination='foo')
coding=CODING_8BIT, pid=PROTOCOL_ENHANCED,
hex_msg=binascii.hexlify('hello'),
destination='foo')
yield self.send(cmd)
self.assertEqual([cmd], calls)

@inlineCallbacks
def test_ussd_message(self):
calls = []
self.patch(self.protocol_class, 'handle_USSD_MESSAGE', calls.append)
cmd = USSDMessage(msisdn='2700000000', type=USSD_TIMEOUT,
phase=USSD_PHASE_2, message='foo')
yield self.send(cmd)
self.assertEqual([cmd], calls)

0 comments on commit e9dde9c

Please sign in to comment.