Skip to content

Commit

Permalink
max_message test for BOTH pdu and text modes
Browse files Browse the repository at this point in the history
modified:   test/gsmmodem_test.py
  • Loading branch information
jwishnie committed Dec 21, 2009
1 parent 32c46bd commit 9b7a33b
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions test/gsmmodem_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,34 @@ def testMaxMessageArgs(self):
# this device is much more complicated than
# most, so is tucked away in mock.device
device = MockSenderDevice()
gsm = pygsm.GsmModem(device=device, mode="PDU")

# test with no max_message arg
gsm.send_sms("1234", "Test Message")
self.assertEqual(device.sent_messages[0]["recipient"], "21")
self.assertEqual(device.sent_messages[0]["text"], "00110004A821430000AA0CD4F29C0E6A96E7F3F0B90C")

# test with reasonable max_message arg, should have no impact
gsm.send_sms("1234", "Test Message", max_messages = 20)
self.assertEqual(device.sent_messages[0]["recipient"], "21")
self.assertEqual(device.sent_messages[0]["text"], "00110004A821430000AA0CD4F29C0E6A96E7F3F0B90C")

# test with max_message = 0, should internally set to 1 with no problems
gsm.send_sms("1234", "Test Message", -1)
self.assertEqual(device.sent_messages[0]["recipient"], "21")
self.assertEqual(device.sent_messages[0]["text"], "00110004A821430000AA0CD4F29C0E6A96E7F3F0B90C")

# test with max_message > 255, should internally force to 255
gsm.send_sms("1234", "Test Message", 1024)
self.assertEqual(device.sent_messages[0]["recipient"], "21")
self.assertEqual(device.sent_messages[0]["text"], "00110004A821430000AA0CD4F29C0E6A96E7F3F0B90C")

gsmPDU = pygsm.GsmModem(device=device, mode="PDU")
gsmTEXT = pygsm.GsmModem(device=device, mode="TEXT")

for gsm in (gsmPDU, gsmTEXT):
# test with no max_message arg
gsm.send_sms("1234", "Test Message")
self.assertEqual(device.sent_messages[0]["recipient"], "21")
self.assertEqual(device.sent_messages[0]["text"], "00110004A821430000AA0CD4F29C0E6A96E7F3F0B90C")

# test with reasonable max_message arg, should have no impact
gsm.send_sms("1234", "Test Message", max_messages = 20)
self.assertEqual(device.sent_messages[0]["recipient"], "21")
self.assertEqual(device.sent_messages[0]["text"], "00110004A821430000AA0CD4F29C0E6A96E7F3F0B90C")

# test with max_message = 0, should internally set to 1 with no problems
gsm.send_sms("1234", "Test Message", -1)
self.assertEqual(device.sent_messages[0]["recipient"], "21")
self.assertEqual(device.sent_messages[0]["text"], "00110004A821430000AA0CD4F29C0E6A96E7F3F0B90C")

# test with max_message > 255, should internally force to 255
gsm.send_sms("1234", "Test Message", 1024)
self.assertEqual(device.sent_messages[0]["recipient"], "21")
self.assertEqual(device.sent_messages[0]["text"], "00110004A821430000AA0CD4F29C0E6A96E7F3F0B90C")

# test with max_message = 1 and message too long to fit
# should throw a value exception
#
# ONLY SUPPORTED IN PDU MODE, so run on PDU configured gsmmodem only
msg="""
0123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789
Expand All @@ -48,12 +52,12 @@ def testMaxMessageArgs(self):
0123456789012345678901234567890123456789012345678901234567890123456789
"""
try:
gsm.send_sms("1234", msg, max_messages=1)
gsmPDU.send_sms("1234", msg, max_messages=1)
except ValueError:
print "ValueError caught"
else:
# Should have thrown an error!
self.assertTrue(False)
self.assertTrue(False) # SMS too big should throw ValueError

def testSendSmsPDUMode(self):
"""Checks that the GsmModem in PDU mode accepts outgoing SMS,
Expand Down

0 comments on commit 9b7a33b

Please sign in to comment.