mock.device.MockSenderDevice

Here are the examples of the python api mock.device.MockSenderDevice taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

3 Examples 7

Example 1

Project: pygsm Source File: gsmmodem_test.py
    def testSendSmsPDUMode(self):
        """Checks that the GsmModem in PDU mode accepts outgoing SMS,
           when the text is within ASCII chars 22 - 126."""

        # this device is much more complicated than
        # most, so is tucked away in mock.device
        device = MockSenderDevice()
        gsm = pygsm.GsmModem(device=device, mode="PDU")

        # send an sms, and check that it arrived safely
        gsm.send_sms("1234", "Test Message")
        self.assertEqual(device.sent_messages[0]["recipient"], "21")
        self.assertEqual(device.sent_messages[0]["text"], "00110004A821430000AA0CD4F29C0E6A96E7F3F0B90C")

Example 2

Project: pygsm Source File: gsmmodem_test.py
    def testSendSmsTextMode(self):
        """Checks that the GsmModem in TEXT mode accepts outgoing SMS,
           when the text is within ASCII chars 22 - 126."""

        # this device is much more complicated than
        # most, so is tucked away in mock.device
        device = MockSenderDevice()
        gsm = pygsm.GsmModem(device=device, mode="TEXT")

        # send an sms, and check that it arrived safely
        gsm.send_sms("1234", "Test Message")
        self.assertEqual(device.sent_messages[0]["recipient"], "1234")
        self.assertEqual(device.sent_messages[0]["text"], "Test Message")

Example 3

Project: pygsm Source File: gsmmodem_test.py
    def testMaxMessageArgs(self):
        # this device is much more complicated than
        # most, so is tucked away in mock.device
        device = MockSenderDevice()
        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
        0123456789012345678901234567890123456789012345678901234567890123456789
        0123456789012345678901234567890123456789012345678901234567890123456789
        0123456789012345678901234567890123456789012345678901234567890123456789
        0123456789012345678901234567890123456789012345678901234567890123456789
        0123456789012345678901234567890123456789012345678901234567890123456789
        """
        try:
            gsmPDU.send_sms("1234", msg, max_messages=1)
        except ValueError:
            print "ValueError caught"
        else:
            # Should have thrown an error!
            self.assertTrue(False) # SMS too big should throw ValueError