def test_parse_with_no_cmn_yaml_ok(self): """ Valid project scenario.yml, there is not common scenario.yml """ os.makedirs(self._pj_dir) pj_yaml_dict = { "scenario": [{ "arguments": { "retry_count": 10 }, "class": "SftpFileExtract", "step": "sftp_file_extract", }] } with open(self._pj_scenario_file, "w") as f: f.write(yaml.dump(pj_yaml_dict, default_flow_style=False)) exists_step = True try: parser = YamlScenarioParser(self._pj_scenario_file, self._cmn_scenario_file) yaml_scenario = parser.parse() exists_step = any("step" in y for y in yaml_scenario) except Exception: exists_step = False else: shutil.rmtree(self._pj_dir) assert exists_step is True
def test_parse_with_pj_and_cmn_yaml_no_class_val_ng(self): """ project scenario.yml and common scenario.yml. There is no class value: in common scenario.yml """ os.makedirs(self._pj_dir) os.makedirs(self._cmn_scenario_dir) pj_yaml_dict = { "scenario": [ { "arguments": {"retry_count": 10}, "class": "SftpDownload", "step": "sftp_download", } ] } with open(self._pj_scenario_file, "w") as f: f.write(yaml.dump(pj_yaml_dict, default_flow_style=False)) cmn_yaml_dict = { "scenario": [ {"arguments": {"retry_count": 10}, "class": "", "step": "sftp_download"} ] } with open(self._cmn_scenario_file, "w") as f: f.write(yaml.dump(cmn_yaml_dict, default_flow_style=False)) with pytest.raises(ScenarioFileInvalid) as excinfo: parser = YamlScenarioParser(self._pj_scenario_file, self._cmn_scenario_file) yaml_scenario = parser.parse() any("step" in y for y in yaml_scenario) shutil.rmtree(self._pj_dir) shutil.rmtree(self._cmn_dir) assert "invalid" in str(excinfo.value)
def test_parse_with_pj_and_cmn_yaml_with_diff_cls_ok(self): """ Valid project scenario.yml and common scenario.yml. In common scenario.yml, There are not same classes. """ os.makedirs(self._pj_dir) os.makedirs(self._cmn_scenario_dir) pj_yaml_dict = { "scenario": [ { "arguments": {"retry_count": 10}, "class": "SampleStep", "step": "sample step", } ] } with open(self._pj_scenario_file, "w") as f: f.write(yaml.dump(pj_yaml_dict, default_flow_style=False)) cmn_yaml_dict = { "scenario": [{"class": "SftpDownload", "step": "sftp_download"}] } with open(self._cmn_scenario_file, "w") as f: f.write(yaml.dump(cmn_yaml_dict, default_flow_style=False)) exists_step = True try: parser = YamlScenarioParser(self._pj_scenario_file, self._cmn_scenario_file) yaml_scenario = parser.parse() exists_step = any("step" in y for y in yaml_scenario) except Exception: exists_step = False else: shutil.rmtree(self._pj_dir) shutil.rmtree(self._cmn_dir) assert exists_step is True
def test_parse_with_pj_and_cmn_yaml_parallel(self): """ Test for parallel operation """ os.makedirs(self._pj_dir) os.makedirs(self._cmn_scenario_dir) pj_yaml_dict = { "scenario": [{ "parallel": [ { "arguments": { "retry_count": 10 }, "class": "SftpDownload", "step": "sftp_download", }, { "arguments": { "retry_count": 10 }, "class": "SftpDownload", "step": "sftp_download", }, ] }] } with open(self._pj_scenario_file, "w") as f: f.write(yaml.dump(pj_yaml_dict, default_flow_style=False)) cmn_yaml_dict = { "scenario": [{ "arguments": { "host": "dummy_host" }, "class": "SftpDownload", "step": "sftp_download", }] } with open(self._cmn_scenario_file, "w") as f: f.write(yaml.dump(cmn_yaml_dict, default_flow_style=False)) try: parser = YamlScenarioParser(self._pj_scenario_file, self._cmn_scenario_file) yaml_scenario_list = parser.parse() for scenario in yaml_scenario_list: for dict in scenario.get("parallel"): assert "dummy_host" == dict.get("arguments")["host"] finally: shutil.rmtree(self._pj_dir) shutil.rmtree(self._cmn_dir)
def create_scenario_queue(self): self._logger.info("Start to create scenario queue") # validation self.__valid_essential_dir() self.__valid_essential_files() # parse scenario.yml parser = YamlScenarioParser(self._pj_scenario_file, self._cmn_scenario_file) yaml_scenario_list = parser.parse() if yaml_scenario_list and isinstance(yaml_scenario_list, list): self.__invoke_steps(yaml_scenario_list) else: raise ScenarioFileInvalid("scenario.yml is invalid.") self._logger.info("Finish to create scenario queue")
def test_parse_no_scenario_key_pj_yaml_ng(self): """ Invalid project scenario.yml """ os.makedirs(self._pj_dir) os.makedirs(self._cmn_scenario_dir) pj_yaml_dict = [{ "arguments": { "retry_count": 10 }, "class": "SftpFileExtract", "step": "sftp_file_extract", }] with open(self._pj_scenario_file, "w") as f: f.write(yaml.dump(pj_yaml_dict, default_flow_style=False)) cmn_yaml_dict = { "scenario": [{ "arguments": { "retry_count": 10 }, "class": "SftpFileExtract", "step": "sftp_file_extract", }] } with open(self._cmn_scenario_file, "w") as f: f.write(yaml.dump(cmn_yaml_dict, default_flow_style=False)) with pytest.raises(ScenarioFileInvalid) as excinfo: parser = YamlScenarioParser(self._pj_scenario_file, self._cmn_scenario_file) yaml_scenario = parser.parse() exists_step = any("step" in y for y in yaml_scenario) shutil.rmtree(self._pj_dir) shutil.rmtree(self._cmn_dir) assert "invalid" in str(excinfo.value)