def test_create_scenario_queue_ok(self): """ Valid scenario.yml """ os.makedirs(self._pj_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)) is_completed_queue_creation = True try: manager = YamlScenarioManager(self._cmd_args) manager.create_scenario_queue() ScenarioQueue.step_queue.pop() except Exception: is_completed_queue_creation = False else: shutil.rmtree(self._pj_dir) assert is_completed_queue_creation is True
def test_create_scenario_queue_ok_with_di_and_diargs(self): """ Valid scenario.yml with dependency injection """ os.makedirs(self._pj_dir) pj_yaml = { "scenario": [{ "step": "spam", "class": "HttpDownload", "arguments": { "src_url": "https://spam/", "auth": { "class": "FormAuth", "form_id": "spam", "form_password": "******", "form_url": "http://spam/", }, }, }] } with open(self._pj_scenario_file, "w") as f: f.write(yaml.dump(pj_yaml, default_flow_style=False)) is_completed_queue_creation = True try: manager = YamlScenarioManager(self._cmd_args) manager.create_scenario_queue() ScenarioQueue.step_queue.pop() except Exception: is_completed_queue_creation = False else: shutil.rmtree(self._pj_dir) assert is_completed_queue_creation is True
def test_create_scenario_queue_ok_with_vars(self): """ Valid scenario.yml with {{ vars }} """ os.makedirs(self._pj_dir) pj_yaml_dict = { "scenario": [{ "arguments": { "src_pattern": "foo_{{ today }}.csv", "with_vars": { "today": "date '+%Y%m%d'" }, }, "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)) is_completed_queue_creation = True try: manager = YamlScenarioManager(self._cmd_args) manager.create_scenario_queue() ScenarioQueue.step_queue.pop() except Exception: is_completed_queue_creation = False else: shutil.rmtree(self._pj_dir) assert is_completed_queue_creation is True
def test_create_scenario_queue_ng_with_di_and_invalid_diargs(self): """ scenario.yml with dependency injection with invalid arguments """ os.makedirs(self._pj_dir) pj_yaml = { "scenario": [{ "step": "spam", "class": "HttpDownload", "arguments": { "auth": { "form_id": "spam" }, "src_url": "https://spam/", }, }] } with open(self._pj_scenario_file, "w") as f: f.write(yaml.dump(pj_yaml, default_flow_style=False)) with pytest.raises(ScenarioFileInvalid) as excinfo: manager = YamlScenarioManager(self._cmd_args) manager.create_scenario_queue() shutil.rmtree(self._pj_dir) assert "class: is not specified" in str(excinfo.value)
def test_create_scenario_queue_with_no_list_ng(self): """ Invalid scenario.yml """ os.makedirs(self._pj_dir) pj_yaml_dict = {"scenario": {"arguments", "spam"}} with open(self._pj_scenario_file, "w") as f: f.write(yaml.dump(pj_yaml_dict, default_flow_style=False)) with pytest.raises(ScenarioFileInvalid) as excinfo: manager = YamlScenarioManager(self._cmd_args) manager.create_scenario_queue() shutil.rmtree(self._pj_dir) assert "invalid" in str(excinfo.value)
def test_create_scenario_queue_ng(self): """ Invalid scenario.yml """ os.makedirs(self._pj_dir) pj_yaml_dict = {"scenario": ["arguments", "spam"]} with open(self._pj_scenario_file, "w") as f: f.write(yaml.dump(pj_yaml_dict, default_flow_style=False)) with pytest.raises(AttributeError) as excinfo: manager = YamlScenarioManager(self._cmd_args) manager.create_scenario_queue() shutil.rmtree(self._pj_dir) assert "object has no attribute" in str(excinfo.value)
def test_create_scenario_queue_ng_with_no_step(self): """ Invalid scenario.yml. There is no 'step: '. """ os.makedirs(self._pj_dir) pj_yaml_dict = { "scenario": [{ "arguments": { "retry_count": 10 }, "class": "SftpFileExtract" }] } with open(self._pj_scenario_file, "w") as f: f.write(yaml.dump(pj_yaml_dict, default_flow_style=False)) with pytest.raises(ScenarioFileInvalid) as excinfo: manager = YamlScenarioManager(self._cmd_args) manager.create_scenario_queue() shutil.rmtree(self._pj_dir) assert "invalid" in str(excinfo.value)