Skip to content

Commit 83c5a17

Browse files
committed
mock out modem scan
1 parent f7d63fb commit 83c5a17

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
lines changed

tests/MessageMode/test_Cloud.py renamed to tests/Cloud/test_Cloud.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,47 @@
1313
sys.path.append("../..")
1414
from Hologram.Authentication import *
1515
from Hologram.Cloud import Cloud
16+
from Hologram.Network import Network
1617

1718
class TestCloud:
1819

19-
def test_create_send(self):
20+
def mock_scan(self, network):
21+
return ['MockModem']
22+
23+
@pytest.fixture
24+
def no_modem(self, monkeypatch):
25+
monkeypatch.setattr(Network, '_scan_for_modems', self.mock_scan)
26+
27+
def test_create_send(self, no_modem):
2028
cloud = Cloud(None, send_host = '127.0.0.1', send_port = 9999)
2129

2230
assert cloud.send_host == '127.0.0.1'
2331
assert cloud.send_port == 9999
2432
assert cloud.receive_host == ''
2533
assert cloud.receive_port == 0
2634

27-
def test_create_receive(self):
35+
def test_create_receive(self, no_modem):
2836
cloud = Cloud(None, receive_host = '127.0.0.1', receive_port = 9999)
2937

3038
assert cloud.send_host == ''
3139
assert cloud.send_port == 0
3240
assert cloud.receive_host == '127.0.0.1'
3341
assert cloud.receive_port == 9999
3442

35-
def test_invalid_send_message(self):
43+
def test_invalid_send_message(self, no_modem):
3644
cloud = Cloud(None, receive_host = '127.0.0.1', receive_port = 9999)
3745

3846
with pytest.raises(Exception, match = 'Must instantiate a Cloud type'):
3947
cloud.sendMessage("hello SMS")
4048

41-
def test_invalid_send_sms(self):
49+
def test_invalid_send_sms(self, no_modem):
4250
cloud = Cloud(None, send_host = '127.0.0.1', send_port = 9999)
4351

4452
with pytest.raises(Exception, match = 'Must instantiate a Cloud type'):
4553
cloud.sendSMS('+12345678900', 'hello SMS')
4654

4755
# This is good for testing if we updated the internal SDK version numbers before release.
48-
def test_sdk_version(self):
56+
def test_sdk_version(self, no_modem):
4957
cloud = Cloud(None, send_host = '127.0.0.1', send_port = 9999)
5058

5159
assert cloud.version == '0.9.0'

tests/MessageMode/test_CustomCloud.py renamed to tests/Cloud/test_CustomCloud.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,18 @@
1313
sys.path.append("../..")
1414
from Hologram.Authentication import *
1515
from Hologram.CustomCloud import CustomCloud
16+
from Hologram.Network import Network
1617

1718
class TestCustomCloud:
1819

19-
def test_create_send(self):
20+
def mock_scan(self, network):
21+
return ['MockModem']
22+
23+
@pytest.fixture
24+
def no_modem(self, monkeypatch):
25+
monkeypatch.setattr(Network, '_scan_for_modems', self.mock_scan)
26+
27+
def test_create_send(self, no_modem):
2028
customCloud = CustomCloud(None, send_host='127.0.0.1',
2129
send_port=9999, enable_inbound=False)
2230

@@ -25,7 +33,7 @@ def test_create_send(self):
2533
assert customCloud.receive_host == ''
2634
assert customCloud.receive_port == 0
2735

28-
def test_create_receive(self):
36+
def test_create_receive(self, no_modem):
2937
customCloud = CustomCloud(None, receive_host='127.0.0.1',
3038
receive_port=9999, enable_inbound=False)
3139

@@ -34,19 +42,19 @@ def test_create_receive(self):
3442
assert customCloud.receive_host == '127.0.0.1'
3543
assert customCloud.receive_port == 9999
3644

37-
def test_enable_inbound(self):
45+
def test_enable_inbound(self, no_modem):
3846

3947
with pytest.raises(Exception, match='Must set receive host and port for inbound connection'):
4048
customCloud = CustomCloud(None, send_host='receive.com',
4149
send_port=9999, enable_inbound=True)
4250

43-
def test_invalid_send_host_and_port(self):
51+
def test_invalid_send_host_and_port(self, no_modem):
4452
customCloud = CustomCloud(None, receive_host='receive.com', receive_port=9999)
4553

4654
with pytest.raises(Exception, match = 'Send host and port must be set before making this operation'):
4755
customCloud.sendMessage("hello")
4856

49-
def test_invalid_send_sms(self):
57+
def test_invalid_send_sms(self, no_modem):
5058
customCloud = CustomCloud(None, 'test.com', 9999)
5159

5260
temp = "hello"

tests/MessageMode/test_HologramCloud.py renamed to tests/Cloud/test_HologramCloud.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,36 @@
1313
sys.path.append("../..")
1414
from Hologram.Authentication import *
1515
from Hologram.HologramCloud import HologramCloud
16+
from Hologram.Network import Network
1617

1718
credentials = {'devicekey':'12345678'}
1819

1920
class TestHologramCloud:
2021

21-
def test_create(self):
22+
def mock_scan(self, network):
23+
return ['MockModem']
24+
25+
@pytest.fixture
26+
def no_modem(self, monkeypatch):
27+
monkeypatch.setattr(Network, '_scan_for_modems', self.mock_scan)
28+
29+
def test_create(self, no_modem):
2230
hologram = HologramCloud(credentials, enable_inbound = False)
2331

2432
assert hologram.send_host == 'cloudsocket.hologram.io'
2533
assert hologram.send_port == 9999
2634
assert hologram.receive_host == '0.0.0.0'
2735
assert hologram.receive_port == 4010
2836

29-
def test_invalid_sms_length(self):
37+
def test_invalid_sms_length(self, no_modem):
3038

3139
hologram = HologramCloud(credentials, authentication_type='csrpsk', enable_inbound = False)
3240

3341
temp = '111111111234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'
3442
with pytest.raises(Exception, match = 'SMS cannot be more than 160 characters long'):
3543
hologram.sendSMS('+1234567890', temp)
3644

37-
def test_get_result_string(self):
45+
def test_get_result_string(self, no_modem):
3846

3947
hologram = HologramCloud(credentials, enable_inbound = False)
4048

0 commit comments

Comments
 (0)