8
8
9
9
import pytest
10
10
import sys
11
+ from datetime import datetime
11
12
12
13
sys .path .append ("." )
13
14
sys .path .append (".." )
@@ -33,6 +34,12 @@ def mock_close_serial_port(modem):
33
34
34
35
def mock_detect_usable_serial_port (modem , stop_on_first = True ):
35
36
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
36
43
37
44
@pytest .fixture
38
45
def no_serial_port (monkeypatch ):
@@ -43,6 +50,10 @@ def no_serial_port(monkeypatch):
43
50
monkeypatch .setattr (Modem , 'closeSerialPort' , mock_close_serial_port )
44
51
monkeypatch .setattr (Modem , 'detect_usable_serial_port' , mock_detect_usable_serial_port )
45
52
53
+ @pytest .fixture
54
+ def get_sms (monkeypatch ):
55
+ monkeypatch .setattr (Modem , 'command' , mock_command_sms )
56
+ monkeypatch .setattr (Modem , 'set' , mock_set_sms )
46
57
47
58
# CONSTRUCTOR
48
59
@@ -79,6 +90,14 @@ def test_get_location(no_serial_port):
79
90
assert (modem .location == 'test location' )
80
91
assert ('This modem does not support this property' in str (e ))
81
92
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' )
82
101
83
102
# DEBUGWRITE
84
103
0 commit comments