Exemple #1
0
class TestCmgDAll(unittest.TestCase):
	def setUp(self):
		self.port = MockPort(self)
		self.gsm = GSM(self.port)
		self.sms = GSM0705(self.gsm)
		
	def test_delete(self):
		self.port.mock_put_read('AT+CMGD=1,4\r\n')
		self.port.mock_put_read('OK\r\n')
		self.assertTrue(self.sms.delete_all())
		self.assertEqual('AT+CMGD=1,4\r\n', self.port.mock_get_write())
		
	def test_delete_fail(self):
		self.port.mock_put_read('AT+CMGD=1,4\r\n')
		self.port.mock_put_read('ERROR\r\n')
		self.assertFalse(self.sms.delete_all())
		self.assertEqual('AT+CMGD=1,4\r\n', self.port.mock_get_write())
Exemple #2
0
class TestCmgD(unittest.TestCase):
	def setUp(self):
		self.port = MockPort(self)
		self.gsm = GSM(self.port)
		self.sms = GSM0705(self.gsm)
		
	def test_delete(self):
		self.port.mock_put_read_multi(CMG_DELETE_1)
		self.assertTrue(self.sms.delete(1))
		self.assertEqual('AT+CMGD=1\r\n', self.port.mock_get_write())
Exemple #3
0
class TestCmgR(unittest.TestCase):
	def setUp(self):
		self.port = MockPort(self)
		self.gsm = GSM(self.port)
		self.sms = GSM0705(self.gsm)
		
	def test_read(self):
		self.port.mock_put_read_multi(CMG_CFG_0)
		self.port.mock_put_read_multi(CMG_READ_1)
		sms = self.sms.read(1)
		who, when, what = sms
		self.assertEqual(who, '106581541003')
		self.assertEqual(str(when), '2014-10-22 12:02:48+08:00')
		self.assertEqual(what, u'\x06\x05\x04\x0b\x84#\xf0@\x06$application/vnd.wap.mms-message\x00\xb4\x87\xaf\x84\x8c\x82\x98VOxaBQFKO4FC\x00\x8d\x90\x83http://221.131.128.129/VOxaBQFKO4FC\x00\x88\x05\x81\x03\x02\xca\r\x89\x07\x8012371\x00\x8a\x80\x8e\x02\xcd~')
		self.assertEqual('AT+CMGF=0\r\nAT+CMGR=1\r\n', self.port.mock_get_write())
		
	def test_read_simple(self):
		read = (
				'AT+CMGR=4\r\n',
				'\r\n',
				'+CMGR: 4,"",28\r\n',
				'0891683108200505F0040D91683118140276F800004111502164332309F0BA7B8C66C55832\r\n',
				'\r\n',
				'OK\r\n')
		self.port.mock_put_read_multi(CMG_CFG_0)
		self.port.mock_put_read_multi(read)
		sms = self.sms.read(4)
		who, when, what = sms
		self.assertEqual(who, '+8613814120678')
		self.assertEqual(str(when), '2014-11-05 12:46:33+08:00')
		self.assertEqual(what, u'punch,1,2')
		self.assertEqual('AT+CMGF=0\r\nAT+CMGR=4\r\n', self.port.mock_get_write())

	def test_noexist(self):
		self.port.mock_put_read_multi(CMG_CFG_0)
		self.port.mock_put_read('AT+CMGR=1\r\n')
		self.port.mock_put_read('\r\n')
		self.port.mock_put_read('OK\r\n')
		self.assertEqual(None, self.sms.read(1))
		self.assertEqual('AT+CMGF=0\r\nAT+CMGR=1\r\n', self.port.mock_get_write())
Exemple #4
0
class TestAtOk(unittest.TestCase):
	def setUp(self):
		self.port = MockPort(self)
		self.gsm = GSM(self.port)

	def test_ok(self):
		self.port.mock_put_read('AT\r\n\r\nOK\r\n')
		self.port.mock_put_read('+CMTI: "SM",1,"MMS PUSH"\r\n')
		self.assertTrue(self.gsm.test())
		self.assertEqual('AT\r\n', self.port.mock_get_write())

	def test_no_echo(self):
		self.assertFalse(self.gsm.test())

	def test_error(self):
		self.port.mock_put_read('AT\r\n\r\nERROR\r\n')
		self.assertFalse(self.gsm.test())
Exemple #5
0
class TestSendAndCheckEcho(unittest.TestCase):
	def setUp(self):
		self.port = MockPort(self)
		self.gsm = GSM(self.port)

	def test_match(self):
		self.port.mock_put_read('AT')
		self.assertTrue(self.gsm.send_and_check_echo('AT'))
		self.assertEqual(self.port.mock_get_write(), 'AT')

	def test_read_more(self):
		self.port.mock_put_read('AT\r\n\r\nOK\r\n')
		self.assertTrue(self.gsm.send_and_check_echo('AT\r\n'))

	def test_unmatch(self):
		self.port.mock_put_read('AT\r')
		self.assertFalse(self.gsm.send_and_check_echo('AT\r\n'))
Exemple #6
0
class TestSendCmd(unittest.TestCase):
	def setUp(self):
		self.port = MockPort(self)
		self.gsm = GSM(self.port)

	def test_match(self):
		self.port.mock_put_read('AT+CMGS=15\r\n> ')
		self.port.mock_put_read('')
		self.assertEqual('> ', self.gsm.send_cmd('AT+CMGS=15\r\n'))
		self.assertEqual('AT+CMGS=15\r\n', self.port.mock_get_write())

	def test_multiline(self):
		self.port.mock_put_read('AT\r\n\r\nOK\r\n')
		self.port.mock_put_read('+CMTI: "SM",1,"MMS PUSH"\r\n')
		self.port.mock_put_read('')
		self.assertEqual('\r\nOK\r\n+CMTI: "SM",1,"MMS PUSH"\r\n', self.gsm.send_cmd('AT\r\n'))

	def test_with_end(self):
		self.port.mock_put_read('AT\r\n\r\nOK\r\n')
		self.port.mock_put_read('+CMTI: "SM",1,"MMS PUSH"\r\n')
		self.port.mock_put_read('')
		self.assertEqual('\r\nOK\r\n', self.gsm.send_cmd('AT\r\n', ['OK', 'ERROR']))
Exemple #7
0
class TestCmgS(unittest.TestCase):
	def setUp(self):
		self.port = MockPort(self)
		self.gsm = GSM(self.port)
		self.sms = GSM0705(self.gsm)
		
	def test_send(self):
		self.port.mock_put_read_multi(CMG_CFG_0)
		self.port.mock_put_read_multi(CMG_SEND)
		self.assertTrue(self.sms.send(u'+8613814120678', u'hello'))
		self.assertEqual('AT+CMGF=0\r\nAT+CMGS=25\r\n0011000D91683118140276F80008A70A00680065006C006C006F\x1a', self.port.mock_get_write())