|
15 | 15 | from Hologram.CustomCloud import CustomCloud |
16 | 16 | from Hologram.Network import Network |
17 | 17 |
|
18 | | -class TestCustomCloud: |
| 18 | +def mock_scan(self): |
| 19 | + return ['MockModem'] |
19 | 20 |
|
20 | | - def mock_scan(self, network): |
21 | | - return ['MockModem'] |
| 21 | +@pytest.fixture |
| 22 | +def no_modem(monkeypatch): |
| 23 | + monkeypatch.setattr(Network, '_scan_for_modems', mock_scan) |
22 | 24 |
|
23 | | - @pytest.fixture |
24 | | - def no_modem(self, monkeypatch): |
25 | | - monkeypatch.setattr(Network, '_scan_for_modems', self.mock_scan) |
| 25 | +def test_create_send(no_modem): |
| 26 | + customCloud = CustomCloud(None, send_host='127.0.0.1', |
| 27 | + send_port=9999, enable_inbound=False) |
26 | 28 |
|
27 | | - def test_create_send(self, no_modem): |
28 | | - customCloud = CustomCloud(None, send_host='127.0.0.1', |
29 | | - send_port=9999, enable_inbound=False) |
| 29 | + assert customCloud.send_host == '127.0.0.1' |
| 30 | + assert customCloud.send_port == 9999 |
| 31 | + assert customCloud.receive_host == '' |
| 32 | + assert customCloud.receive_port == 0 |
30 | 33 |
|
31 | | - assert customCloud.send_host == '127.0.0.1' |
32 | | - assert customCloud.send_port == 9999 |
33 | | - assert customCloud.receive_host == '' |
34 | | - assert customCloud.receive_port == 0 |
| 34 | +def test_create_receive(no_modem): |
| 35 | + customCloud = CustomCloud(None, receive_host='127.0.0.1', |
| 36 | + receive_port=9999, enable_inbound=False) |
35 | 37 |
|
36 | | - def test_create_receive(self, no_modem): |
37 | | - customCloud = CustomCloud(None, receive_host='127.0.0.1', |
38 | | - receive_port=9999, enable_inbound=False) |
| 38 | + assert customCloud.send_host == '' |
| 39 | + assert customCloud.send_port == 0 |
| 40 | + assert customCloud.receive_host == '127.0.0.1' |
| 41 | + assert customCloud.receive_port == 9999 |
39 | 42 |
|
40 | | - assert customCloud.send_host == '' |
41 | | - assert customCloud.send_port == 0 |
42 | | - assert customCloud.receive_host == '127.0.0.1' |
43 | | - assert customCloud.receive_port == 9999 |
| 43 | +def test_enable_inbound(no_modem): |
44 | 44 |
|
45 | | - def test_enable_inbound(self, no_modem): |
| 45 | + with pytest.raises(Exception, match='Must set receive host and port for inbound connection'): |
| 46 | + customCloud = CustomCloud(None, send_host='receive.com', |
| 47 | + send_port=9999, enable_inbound=True) |
46 | 48 |
|
47 | | - with pytest.raises(Exception, match='Must set receive host and port for inbound connection'): |
48 | | - customCloud = CustomCloud(None, send_host='receive.com', |
49 | | - send_port=9999, enable_inbound=True) |
| 49 | +def test_invalid_send_host_and_port(no_modem): |
| 50 | + customCloud = CustomCloud(None, receive_host='receive.com', receive_port=9999) |
50 | 51 |
|
51 | | - def test_invalid_send_host_and_port(self, no_modem): |
52 | | - customCloud = CustomCloud(None, receive_host='receive.com', receive_port=9999) |
| 52 | + with pytest.raises(Exception, match = 'Send host and port must be set before making this operation'): |
| 53 | + customCloud.sendMessage("hello") |
53 | 54 |
|
54 | | - with pytest.raises(Exception, match = 'Send host and port must be set before making this operation'): |
55 | | - customCloud.sendMessage("hello") |
| 55 | +def test_invalid_send_sms(no_modem): |
| 56 | + customCloud = CustomCloud(None, 'test.com', 9999) |
56 | 57 |
|
57 | | - def test_invalid_send_sms(self, no_modem): |
58 | | - customCloud = CustomCloud(None, 'test.com', 9999) |
59 | | - |
60 | | - temp = "hello" |
61 | | - with pytest.raises(NotImplementedError, match='Cannot send SMS via custom cloud'): |
62 | | - customCloud.sendSMS('+1234567890', temp) |
| 58 | + temp = "hello" |
| 59 | + with pytest.raises(NotImplementedError, match='Cannot send SMS via custom cloud'): |
| 60 | + customCloud.sendSMS('+1234567890', temp) |
0 commit comments