def test_action_api_based_data_passed_in_string(self, mock_data): js = SnapAdmin() js.args.file = os.path.join(os.path.dirname(__file__), 'configs', 'main.yml') config_file = open(js.args.file, 'r') data = yaml.load(config_file, Loader=yaml.FullLoader) js.snapcheck(data, 'mock_file') mock_data.assert_called_with(data, 'mock_file', "snapcheck", None, local=False)
def test_extract_dev_data_invalid_config_data(self, mock_connect): with self.assertRaises(SystemExit): dev = Device(user='******', host='abc', passwd='xyz') dev.open() js = SnapAdmin() config_data = 1 # config_data no meaning js.snapcheck(config_data, 'mock_pre', dev)
def test_extract_dev_data_device_closed(self, mock_dev, mock_path): mock_path.return_value = os.path.join(os.path.dirname(__file__), 'configs') with self.assertRaises(Exception): dev = Device(user='******', host='abc', passwd='xyz') dev.open() dev.close() js = SnapAdmin() js.args.file = 'main_local.yml' js.snapcheck(js.args.file, 'mock_pre', dev)
def test_action_api_based_data_passed_in_string_with_device(self, mock_data, mock_dev_data, mock_connect): js = SnapAdmin() js.args.file = os.path.join(os.path.dirname(__file__), 'configs', 'main.yml') config_file = open(js.args.file, 'r') data = yaml.load(config_file, Loader=yaml.FullLoader) dev = Device(user='******', host='abc', passwd='xyz') dev.open() js.snapcheck(data, 'mock_file', dev) self.assertFalse(mock_data.called) self.assertTrue(mock_dev_data.called)
def test_extract_dev_data_dictionary_based_data(self, mock_gen_rpc, mock_dev, mock_path, mock_test): mock_path.return_value = os.path.join(os.path.dirname(__file__), 'configs') dev = Device(user='******', host='abc', passwd='xyz') dev.open() js = SnapAdmin() conf_file = os.path.join(os.path.dirname(__file__), 'configs', 'main_1.yml') config_file = open(conf_file, 'r') config_data = yaml.load(config_file) js.snapcheck(config_data, 'mock_pre', dev) mock_gen_rpc.assert_called_with(dev, 'mock_pre', 'abc', config_data) mock_test.assert_called()
def test_extract_dev_data_from_file_and_local(self, mock_gen_rpc, mock_dev, mock_path, mock_test): mock_path.return_value = os.path.join(os.path.dirname(__file__), 'configs') dev = Device(user='******', host='abc', passwd='xyz') dev.open() js = SnapAdmin() conf_file = os.path.join(os.path.dirname(__file__), 'configs', 'main_local.yml') config_file = open(conf_file, 'r') config_data = yaml.load(config_file, Loader=yaml.FullLoader) js.snapcheck(config_data, 'mock_pre', dev) self.assertFalse(mock_gen_rpc.called) mock_test.assert_called()
def test_extract_data_text_string(self, mock_connect): js = SnapAdmin() config_data = """ hosts: - device: 1.1.1.1 username : abc passwd: xyz tests: - test_anything.yml """ js.snapcheck(config_data, 'mock_pre') config_data = yaml.load(config_data, Loader=yaml.FullLoader) mock_connect.assert_called_with('1.1.1.1', 'abc', 'xyz', 'mock_pre', config_data, 'snapcheck', None)
def test_extract_data_check_database(self, mock_connect, mock_chkdb): js = SnapAdmin() config_data = """ hosts: - device: 1.1.1.1 username : abc passwd: xyz tests: - test_anything.yml sqlite: - store_in_sqlite: True database_name: jbb.db check_from_sqlite: True compare: 1,0 """ js.snapcheck(config_data, 'mock_pre') config_data = yaml.load(config_data, Loader=yaml.FullLoader) mock_chkdb.assert_called() mock_connect.assert_called_with('1.1.1.1', 'abc', 'xyz', 'mock_pre', config_data, 'snapcheck', None)
def test_action_api_based_error_file(self, mock_data, mock_exit): js = SnapAdmin() js.args.file = os.path.join(os.path.dirname(__file__), 'configs', 'main.yml') js.snapcheck(js.args.file, 'mock_file') mock_exit.assert_called()