|
9 | 9 |
|
10 | 10 |
|
11 | 11 | class TestModem(unittest.TestCase):
|
| 12 | + |
| 13 | + def testMaxMessageArgs(self): |
| 14 | + # this device is much more complicated than |
| 15 | + # most, so is tucked away in mock.device |
| 16 | + device = MockSenderDevice() |
| 17 | + gsm = pygsm.GsmModem(device=device, mode="PDU") |
| 18 | + |
| 19 | + # test with no max_message arg |
| 20 | + gsm.send_sms("1234", "Test Message") |
| 21 | + self.assertEqual(device.sent_messages[0]["recipient"], "21") |
| 22 | + self.assertEqual(device.sent_messages[0]["text"], "00110004A821430000AA0CD4F29C0E6A96E7F3F0B90C") |
| 23 | + |
| 24 | + # test with reasonable max_message arg, should have no impact |
| 25 | + gsm.send_sms("1234", "Test Message", max_messages = 20) |
| 26 | + self.assertEqual(device.sent_messages[0]["recipient"], "21") |
| 27 | + self.assertEqual(device.sent_messages[0]["text"], "00110004A821430000AA0CD4F29C0E6A96E7F3F0B90C") |
| 28 | + |
| 29 | + # test with max_message = 0, should internally set to 1 with no problems |
| 30 | + gsm.send_sms("1234", "Test Message", -1) |
| 31 | + self.assertEqual(device.sent_messages[0]["recipient"], "21") |
| 32 | + self.assertEqual(device.sent_messages[0]["text"], "00110004A821430000AA0CD4F29C0E6A96E7F3F0B90C") |
| 33 | + |
| 34 | + # test with max_message > 255, should internally force to 255 |
| 35 | + gsm.send_sms("1234", "Test Message", 1024) |
| 36 | + self.assertEqual(device.sent_messages[0]["recipient"], "21") |
| 37 | + self.assertEqual(device.sent_messages[0]["text"], "00110004A821430000AA0CD4F29C0E6A96E7F3F0B90C") |
| 38 | + |
| 39 | + # test with max_message = 1 and message too long to fit |
| 40 | + # should throw a value exception |
| 41 | + msg=""" |
| 42 | + 0123456789012345678901234567890123456789012345678901234567890123456789 |
| 43 | + 0123456789012345678901234567890123456789012345678901234567890123456789 |
| 44 | + 0123456789012345678901234567890123456789012345678901234567890123456789 |
| 45 | + 0123456789012345678901234567890123456789012345678901234567890123456789 |
| 46 | + 0123456789012345678901234567890123456789012345678901234567890123456789 |
| 47 | + 0123456789012345678901234567890123456789012345678901234567890123456789 |
| 48 | + 0123456789012345678901234567890123456789012345678901234567890123456789 |
| 49 | + """ |
| 50 | + try: |
| 51 | + gsm.send_sms("1234", msg, max_messages=1) |
| 52 | + except ValueError: |
| 53 | + print "ValueError caught" |
| 54 | + else: |
| 55 | + # Should have thrown an error! |
| 56 | + self.assertTrue(False) |
12 | 57 |
|
13 | 58 | def testSendSmsPDUMode(self):
|
14 | 59 | """Checks that the GsmModem in PDU mode accepts outgoing SMS,
|
|
0 commit comments