88
99import pytest
1010import sys
11+ from datetime import datetime
1112
1213sys .path .append ("." )
1314sys .path .append (".." )
@@ -33,6 +34,12 @@ def mock_close_serial_port(modem):
3334
3435def mock_detect_usable_serial_port (modem , stop_on_first = True ):
3536 return '/dev/ttyUSB0'
37+
38+ def mock_command_sms (modem , at_command ):
39+ return (ModemResult .OK , ['+CMGL: 2,1,,26' , '0791447779071413040C9144977304250500007160421062944008D4F29C0E8AC966' ])
40+
41+ def mock_set_sms (modem , at_command , val ):
42+ return None
3643
3744@pytest .fixture
3845def no_serial_port (monkeypatch ):
@@ -43,6 +50,10 @@ def no_serial_port(monkeypatch):
4350 monkeypatch .setattr (Modem , 'closeSerialPort' , mock_close_serial_port )
4451 monkeypatch .setattr (Modem , 'detect_usable_serial_port' , mock_detect_usable_serial_port )
4552
53+ @pytest .fixture
54+ def get_sms (monkeypatch ):
55+ monkeypatch .setattr (Modem , 'command' , mock_command_sms )
56+ monkeypatch .setattr (Modem , 'set' , mock_set_sms )
4657
4758# CONSTRUCTOR
4859
@@ -79,6 +90,14 @@ def test_get_location(no_serial_port):
7990 assert (modem .location == 'test location' )
8091 assert ('This modem does not support this property' in str (e ))
8192
93+ # SMS
94+
95+ def test_get_sms (no_serial_port , get_sms ):
96+ modem = Modem ()
97+ res = modem .popReceivedSMS ()
98+ assert (res .sender == '447937405250' )
99+ assert (res .timestamp == datetime .utcfromtimestamp (1498264009 ))
100+ assert (res .message == 'Test 123' )
82101
83102# DEBUGWRITE
84103
0 commit comments