Skip to content

Commit 19c46ab

Browse files
committed
work on tests
1 parent 83c5a17 commit 19c46ab

File tree

5 files changed

+92
-109
lines changed

5 files changed

+92
-109
lines changed

tests/Cloud/test_Cloud.py

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,45 +15,43 @@
1515
from Hologram.Cloud import Cloud
1616
from Hologram.Network import Network
1717

18-
class TestCloud:
18+
def mock_scan():
19+
return ['MockModem']
1920

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)
2224

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+
cloud = Cloud(None, send_host = '127.0.0.1', send_port = 9999)
2627

27-
def test_create_send(self, no_modem):
28-
cloud = Cloud(None, send_host = '127.0.0.1', send_port = 9999)
28+
assert cloud.send_host == '127.0.0.1'
29+
assert cloud.send_port == 9999
30+
assert cloud.receive_host == ''
31+
assert cloud.receive_port == 0
2932

30-
assert cloud.send_host == '127.0.0.1'
31-
assert cloud.send_port == 9999
32-
assert cloud.receive_host == ''
33-
assert cloud.receive_port == 0
33+
def test_create_receive(no_modem):
34+
cloud = Cloud(None, receive_host = '127.0.0.1', receive_port = 9999)
3435

35-
def test_create_receive(self, no_modem):
36-
cloud = Cloud(None, receive_host = '127.0.0.1', receive_port = 9999)
36+
assert cloud.send_host == ''
37+
assert cloud.send_port == 0
38+
assert cloud.receive_host == '127.0.0.1'
39+
assert cloud.receive_port == 9999
3740

38-
assert cloud.send_host == ''
39-
assert cloud.send_port == 0
40-
assert cloud.receive_host == '127.0.0.1'
41-
assert cloud.receive_port == 9999
41+
def test_invalid_send_message(no_modem):
42+
cloud = Cloud(None, receive_host = '127.0.0.1', receive_port = 9999)
4243

43-
def test_invalid_send_message(self, no_modem):
44-
cloud = Cloud(None, receive_host = '127.0.0.1', receive_port = 9999)
44+
with pytest.raises(Exception, match = 'Must instantiate a Cloud type'):
45+
cloud.sendMessage("hello SMS")
4546

46-
with pytest.raises(Exception, match = 'Must instantiate a Cloud type'):
47-
cloud.sendMessage("hello SMS")
47+
def test_invalid_send_sms(no_modem):
48+
cloud = Cloud(None, send_host = '127.0.0.1', send_port = 9999)
4849

49-
def test_invalid_send_sms(self, no_modem):
50-
cloud = Cloud(None, send_host = '127.0.0.1', send_port = 9999)
50+
with pytest.raises(Exception, match = 'Must instantiate a Cloud type'):
51+
cloud.sendSMS('+12345678900', 'hello SMS')
5152

52-
with pytest.raises(Exception, match = 'Must instantiate a Cloud type'):
53-
cloud.sendSMS('+12345678900', 'hello SMS')
53+
# This is good for testing if we updated the internal SDK version numbers before release.
54+
def test_sdk_version(no_modem):
55+
cloud = Cloud(None, send_host = '127.0.0.1', send_port = 9999)
5456

55-
# This is good for testing if we updated the internal SDK version numbers before release.
56-
def test_sdk_version(self, no_modem):
57-
cloud = Cloud(None, send_host = '127.0.0.1', send_port = 9999)
58-
59-
assert cloud.version == '0.9.0'
57+
assert cloud.version == '0.9.0'

tests/Cloud/test_CustomCloud.py

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,48 +15,46 @@
1515
from Hologram.CustomCloud import CustomCloud
1616
from Hologram.Network import Network
1717

18-
class TestCustomCloud:
18+
def mock_scan(self):
19+
return ['MockModem']
1920

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)
2224

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)
2628

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
3033

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)
3537

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
3942

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):
4444

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)
4648

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)
5051

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")
5354

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)
5657

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)

tests/Cloud/test_HologramCloud.py

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,42 +17,40 @@
1717

1818
credentials = {'devicekey':'12345678'}
1919

20-
class TestHologramCloud:
20+
def mock_scan(network):
21+
return ['MockModem']
2122

22-
def mock_scan(self, network):
23-
return ['MockModem']
23+
@pytest.fixture
24+
def no_modem(monkeypatch):
25+
monkeypatch.setattr(Network, '_scan_for_modems', mock_scan)
2426

25-
@pytest.fixture
26-
def no_modem(self, monkeypatch):
27-
monkeypatch.setattr(Network, '_scan_for_modems', self.mock_scan)
27+
def test_create(no_modem):
28+
hologram = HologramCloud(credentials, enable_inbound = False)
2829

29-
def test_create(self, no_modem):
30-
hologram = HologramCloud(credentials, enable_inbound = False)
30+
assert hologram.send_host == 'cloudsocket.hologram.io'
31+
assert hologram.send_port == 9999
32+
assert hologram.receive_host == '0.0.0.0'
33+
assert hologram.receive_port == 4010
3134

32-
assert hologram.send_host == 'cloudsocket.hologram.io'
33-
assert hologram.send_port == 9999
34-
assert hologram.receive_host == '0.0.0.0'
35-
assert hologram.receive_port == 4010
35+
def test_invalid_sms_length(no_modem):
3636

37-
def test_invalid_sms_length(self, no_modem):
37+
hologram = HologramCloud(credentials, authentication_type='csrpsk', enable_inbound = False)
3838

39-
hologram = HologramCloud(credentials, authentication_type='csrpsk', enable_inbound = False)
39+
temp = '111111111234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'
40+
with pytest.raises(Exception, match = 'SMS cannot be more than 160 characters long'):
41+
hologram.sendSMS('+1234567890', temp)
4042

41-
temp = '111111111234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'
42-
with pytest.raises(Exception, match = 'SMS cannot be more than 160 characters long'):
43-
hologram.sendSMS('+1234567890', temp)
43+
def test_get_result_string(no_modem):
4444

45-
def test_get_result_string(self, no_modem):
45+
hologram = HologramCloud(credentials, enable_inbound = False)
4646

47-
hologram = HologramCloud(credentials, enable_inbound = False)
48-
49-
assert hologram.getResultString(-1) == 'Unknown error'
50-
assert hologram.getResultString(0) == 'Message sent successfully'
51-
assert hologram.getResultString(1) == 'Connection was closed so we couldn\'t read the whole message'
52-
assert hologram.getResultString(2) == 'Failed to parse the message'
53-
assert hologram.getResultString(3) == 'Auth section of the message was invalid'
54-
assert hologram.getResultString(4) == 'Payload type was invalid'
55-
assert hologram.getResultString(5) == 'Protocol type was invalid'
56-
assert hologram.getResultString(6) == 'Internal error in Hologram Cloud'
57-
assert hologram.getResultString(7) == 'Metadata was formatted incorrectly'
58-
assert hologram.getResultString(8) == 'Topic was formatted incorrectly'
47+
assert hologram.getResultString(-1) == 'Unknown error'
48+
assert hologram.getResultString(0) == 'Message sent successfully'
49+
assert hologram.getResultString(1) == 'Connection was closed so we couldn\'t read the whole message'
50+
assert hologram.getResultString(2) == 'Failed to parse the message'
51+
assert hologram.getResultString(3) == 'Auth section of the message was invalid'
52+
assert hologram.getResultString(4) == 'Payload type was invalid'
53+
assert hologram.getResultString(5) == 'Protocol type was invalid'
54+
assert hologram.getResultString(6) == 'Internal error in Hologram Cloud'
55+
assert hologram.getResultString(7) == 'Metadata was formatted incorrectly'
56+
assert hologram.getResultString(8) == 'Topic was formatted incorrectly'

tests/Network/test_Network.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,6 @@
1414
sys.path.append("../..")
1515
from Hologram.Network import Network
1616

17-
class TestNetwork:
1817

19-
def test_create_network(self):
20-
network = Network()
21-
22-
def test_get_invalid_connection_status(self):
23-
network = Network()
24-
with pytest.raises(Exception, match = 'Must instantiate a defined Network type'):
25-
connectionStatus = network.getConnectionStatus()
26-
27-
def test_get_invalid_signal_strength(self):
28-
network = Network()
29-
with pytest.raises(Exception, match = 'Must instantiate a defined Network type'):
30-
connectionStatus = network.getSignalStrength()
18+
def test_create_network(self):
19+
network = Network()

tests/PPP/test_IPPP.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
class TestIPPP:
1616

1717
def test_modem_mode_create(self):
18-
modem_mode = IPPP(device_name='/dev/ttyUSB0', baud_rate='9600')
18+
modem_mode = IPPP(device_name='/dev/ttyUSB0', baud_rate='9600',chatscript_file='test')
1919

2020
assert modem_mode.device_name == '/dev/ttyUSB0'
2121
assert modem_mode.baud_rate == '9600'

0 commit comments

Comments
 (0)