Skip to content

Commit 2f87916

Browse files
committed
wip: migrate hub
1 parent 694fd43 commit 2f87916

5 files changed

Lines changed: 59 additions & 29 deletions

File tree

openpod/modules/rec_lan.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def monitor_network(last_network_status=5, thread_delay=30.0):
7171
network_watch_thread.setName('network_watch_thread')
7272
network_watch_thread.start()
7373

74+
return True
7475

7576
def test_network():
7677
'''

tests/modules/test_lan.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ def test_monitor_network(self):
2121
mocked_test_network.return_value = 0
2222

2323
with patch('modules.rec_lan.threading') as mocked_threading:
24-
rec_lan.monitor_network()
25-
24+
self.assertTrue(rec_lan.monitor_network())
2625
mocked_threading.Timer.assert_called()
2726

2827
def test_test_network(self):
28+
'''
29+
Confirms all tests are called properly.
30+
'''
2931
with patch('modules.rec_lan.networked') as mocked_networked:
3032
mocked_networked.return_value = False
3133
self.assertEqual(rec_lan.test_network(), 0)
@@ -91,11 +93,11 @@ def test_get_ip(self):
9193

9294
with patch('modules.rec_lan.requests.get') as mocked_requests:
9395
mocked_requests.return_value.text = "0.0.0.0"
94-
PubIP, LocalIP = rec_lan.get_ip()
96+
public_ip, local_ip = rec_lan.get_ip()
9597

9698
self.assertEqual((rec_lan.get_ip())[0], '0.0.0.0')
97-
self.assertEqual(PubIP, '0.0.0.0')
98-
self.assertEqual(LocalIP, '0.0.0.0')
99+
self.assertEqual(public_ip, '0.0.0.0')
100+
self.assertNotEqual(local_ip, '127.0.0.1')
99101

100102
mocked_internet_on.return_value = False
101103
self.assertNotEqual((rec_lan.get_ip())[0], '0.0.0.0')

tests/modules/test_log.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
''' Tests for rec_log.py '''
22

3-
import sys
4-
import logging
5-
import unittest
3+
# import sys
4+
# import logging
5+
# import unittest
66

7-
#from modules import rec_lan, rec_api, rec_xbee, rec_log
7+
# #from modules import rec_lan, rec_api, rec_xbee, rec_log
88

9-
sys.path.insert(0, "openpod/")
9+
# sys.path.insert(0, "openpod/")
1010

11-
class Testlog(unittest.TestCase):
12-
''' Tests for the log module '''
11+
# class Testlog(unittest.TestCase):
12+
# ''' Tests for the log module '''
1313

14-
def __init__(self, *args, **kwargs):
15-
self.reset()
16-
logging.Handler.__init__(self, *args, **kwargs)
14+
# def __init__(self, *args, **kwargs):
15+
# self.reset()
16+
# logging.Handler.__init__(self, *args, **kwargs)
1717

18-
def emit(self, record):
19-
self.messages[record.levelname.lower()].append(record.getMessage())
18+
# def emit(self, record):
19+
# self.messages[record.levelname.lower()].append(record.getMessage())
2020

21-
def reset(self):
22-
self.messages = {
23-
'debug': [],
24-
'info': [],
25-
'warning': [],
26-
'error': [],
27-
'critical': [],
28-
}
21+
# def reset(self):
22+
# self.messages = {
23+
# 'debug': [],
24+
# 'info': [],
25+
# 'warning': [],
26+
# 'error': [],
27+
# 'critical': [],
28+
# }
2929

30-
if __name__ == '__main__':
31-
unittest.main()
30+
# if __name__ == '__main__':
31+
# unittest.main()

tests/modules/test_lookup.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ def setUp(self):
5252
self.nodes_empty_json = StringIO('')
5353

5454
def test_count_matching_mac(self):
55+
'''
56+
Confirms MAC conflection is counted correctly.
57+
'''
5558
count_result = rec_lookup.count_matching_mac("12345678")
5659
self.assertEqual(count_result, 0)
5760

@@ -86,10 +89,13 @@ def test_count_matching_mac(self):
8689

8790
mock_open.assert_called()
8891

89-
class Test_LookUp_AccessRequest(unittest.TestCase):
92+
class TestLookUpAccessRequest(unittest.TestCase):
9093
'''Access Request Tests'''
9194

9295
def setUp(self):
96+
'''
97+
Collection of JSON used for testing.
98+
'''
9399
self.system_json = StringIO(
94100
'''{
95101
"serial": "536780dfe639468e8e23fc568006950d",
@@ -265,6 +271,9 @@ def setUp(self):
265271
)
266272

267273
def test_files_opened(self):
274+
'''
275+
Confirms that all the files are correctly opened and read.
276+
'''
268277
with patch('modules.rec_lookup.open') as mock_open:
269278
mock_open.side_effect = [
270279
self.system_json,
@@ -274,10 +283,13 @@ def test_files_opened(self):
274283
self.permissions_json, # Opened from get_group_details function.
275284
]
276285

277-
rec_lookup.access_request(313131, '0011223344556677')
286+
self.assertAlmostEqual(rec_lookup.access_request(313131, '0011223344556677'), 2)
278287
mock_open.assert_called()
279288

280289
def test_mac_to_id(self):
290+
'''
291+
Confirms that the mac address is converted to the node id.
292+
'''
281293
with patch('modules.rec_lookup.open') as mock_open:
282294
mock_open.return_value = self.nodes_json
283295

@@ -293,6 +305,9 @@ def test_mac_to_id(self):
293305
self.assertEqual(node_id, '9911223344556677')
294306

295307
def test_is_owner(self):
308+
'''
309+
Confirms that the owner check function returns the correct value.
310+
'''
296311
with patch('modules.rec_lookup.open') as mock_open:
297312
mock_open.return_value = self.owners_json
298313

@@ -308,6 +323,9 @@ def test_is_owner(self):
308323
self.assertFalse(owner)
309324

310325
def test_get_details(self):
326+
'''
327+
Verifies that the correct details are returned.
328+
'''
311329
with patch('modules.rec_lookup.open') as mock_open:
312330
mock_open.return_value = self.members_json
313331

@@ -323,6 +341,9 @@ def test_get_details(self):
323341
self.assertFalse(user['found'])
324342

325343
def test_get_group_details(self):
344+
'''
345+
Verifies that the correct details are returned.
346+
'''
326347
with patch('modules.rec_lookup.open') as mock_open:
327348
mock_open.return_value = self.permissions_json
328349

@@ -338,6 +359,9 @@ def test_get_group_details(self):
338359
self.assertFalse(group['found'])
339360

340361
def test_access_request_combinations(self):
362+
'''
363+
Checks that the access request function returns the correct values.
364+
'''
341365
with patch('modules.rec_lookup.open') as mock_open:
342366
mock_open.side_effect = [
343367
self.system_json,

tests/modules/test_mqtt.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class TestOnMessage(unittest.TestCase):
1717
'''unit tests for the MQTT module'''
1818

1919
def test_function_calls(self):
20+
'''
21+
Checks that the function calls are correct.
22+
'''
2023
with patch('modules.rec_mqtt.rec_api.link_hub') as mock_link:
2124
rec_mqtt.on_message('test_client', None, DummyMessage('170'))
2225
mock_link.assert_called()

0 commit comments

Comments
 (0)