def test_get_status_line(self, mock_urlopen): # pylint: disable=unused-argument ''' Test get_status_line(line_types = [1, 2, 3, 4], node = "", line_width = -1) ''' #status = mod_master_control.MasterStatus().get_status() line_types_list = [[2, 3], [1, 2, 3, 4], 2] line_type_keys = {4: 'line_os', 3: 'line_ip', 1: 'line_usage', 2: 'line_uptime'} # Test all passed in for line_types in line_types_list: # Test multiple nodes at various lengths [-1, 40, 20, 16] for node in CONFIG.API_HOSTS: # Test node at various lengths [-1, 40, 20, 16] for line_width in service_master_api_testdata.TEST_RESULTS['status_lines']: mod_master_status = mod_master_control.MasterStatus(line_width) result = mod_master_status.get_status_line(line_types, node, line_width) test_data = {} if isinstance(line_types, list): lines_types_for_loop = line_types else: lines_types_for_loop = [line_types] for line_type in lines_types_for_loop: lines = service_master_api_testdata.TEST_RESULTS['status_lines'] data = lines[line_width][line_type_keys[line_type]][node] node_data = data test_data[line_type] = {node : node_data} self.assertEqual(result, test_data) # Test no node passed for line_types in line_types_list: # Test multiple nodes at various lengths [-1, 40, 20, 16] for line_width in service_master_api_testdata.TEST_RESULTS['status_lines']: master_status = mod_master_control.MasterStatus(line_width) lines = master_status.get_status_line(line_types=line_types, line_width=line_width) result = lines test_data = {} if isinstance(line_types, list): lines_types_for_loop = line_types else: lines_types_for_loop = [line_types] for line_type in lines_types_for_loop: test_data[line_type] = {} for node in CONFIG.API_HOSTS: lines = service_master_api_testdata.TEST_RESULTS['status_lines'] data = lines[line_width][line_type_keys[line_type]][node] test_data[line_type][node] = data self.assertEqual(result, test_data)
def test_master_status_get_status(self, mock_urlopen): # pylint: disable=unused-argument ''' Test get_status(node = "", debug=False) ''' status = mod_master_control.MasterStatus().get_status() self.assertEqual(status, service_master_api_testdata.TEST_RESULTS['get_status']) status = mod_master_control.MasterStatus().get_status("rpi0") test_result = {'rpi0': service_master_api_testdata.TEST_RESULTS['get_status']['rpi0']} self.assertEqual(status, test_result) #with self.assertRaises(KeyError): status = mod_master_control.MasterStatus().get_status(1) self.assertEqual(status[1]['error'], "Error in host_method: Invalid Node (1)") #with self.assertRaises(KeyError): status = mod_master_control.MasterStatus().get_status("abc") self.assertEqual(status["abc"]['error'], "Error in host_method: Invalid Node (abc)")
def test_master_status__status_line(self, mock_urlopen): # pylint: disable=unused-argument ''' Test _status_line(line_type, status) ''' line_types = {4: 'line_os', 3: 'line_ip', 1: 'line_usage', 2: 'line_uptime'} status = mod_master_control.MasterStatus().get_status() for line_type in range(1, 4): # Test multiple nodes at various lengths [-1, 40, 20, 16] for node in CONFIG.API_HOSTS: # Test node at various lengths [-1, 40, 20, 16] for line_width in service_master_api_testdata.TEST_RESULTS['status_lines']: result = mod_master_control.MasterStatus(line_width)._status_line(line_type, status[node]) test_data = service_master_api_testdata.TEST_RESULTS['status_lines'][line_width][line_types[line_type]][node] self.assertEqual(result, test_data) result = mod_master_control.MasterStatus()._status_line(0, status['rpi0']) self.assertEqual(result, "Errror: Invalid line type")
def test_master_status_get_hosts(self): ''' Test Get Hosts ''' hosts = mod_master_control.MasterStatus().get_hosts() self.assertEqual(hosts, mod_master_control.CONFIG.API_HOSTS)