def test_extract_device_information_empty_mainfile(self, mock_log): js = SnapAdmin() js.main_file = None host_dict = {} js.extract_device_information(host_dict) mock_log.assert_called_with("\x1b[31m\nERROR occurred !! 'NoneType' object is not subscriptable", extra={'hostname': None})
def test_extract_device_information_from_arguments(self): js = SnapAdmin() self.set_hardcoded_value_for_device(js) host_dict = {} js.extract_device_information(host_dict) hosts = ['1.1.1.1'] self.assertEqual(js.host_list, hosts)
def test_extract_device_information_attribute_error(self, mock_log): js = SnapAdmin() conf_file = os.path.join(os.path.dirname(__file__), 'configs', 'main_false_keyError_device.yml') config_file = open(conf_file, 'r') js.main_file = yaml.load(config_file, Loader=yaml.FullLoader) host_dict = {} js.extract_device_information(host_dict) mock_log.assert_called_with("\x1b[31mERROR!! KeyError 'device' key not found", extra={'hostname': None})
def test_extract_device_information_keyerror(self, mock_log): js = SnapAdmin() conf_file = os.path.join(os.path.dirname(__file__), 'configs', 'main_false_keyError.yml') config_file = open(conf_file, 'r') js.main_file = yaml.load(config_file, Loader=yaml.FullLoader) host_dict = {} js.extract_device_information(host_dict) mock_log.assert_called_with("\x1b[31m\nERROR occurred !! Hostname not given properly 'hosts'", extra={'hostname': None})
def test_extract_device_information_from_file(self): js = SnapAdmin() js.args.file = os.path.join(os.path.dirname(__file__), 'configs', 'main_1.yml') config_file = open(js.args.file, 'r') js.main_file = yaml.load(config_file, Loader=yaml.FullLoader) host_dict = {} js.extract_device_information(host_dict) hosts = ['1.1.1.1'] self.assertEqual(js.host_list, hosts)