예제 #1
0
    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
예제 #2
0
    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
예제 #3
0
    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
예제 #4
0
    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)
예제 #5
0
    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)
예제 #6
0
    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)
예제 #7
0
    def test_replace_vars_plural(self):
        manager = YamlScenarioManager(self._cmd_args)
        manager._dynamic_key_and_val["arg_f"] = "echo FROM"
        manager._dynamic_key_and_val["arg_t"] = "echo TO"

        yaml_v = "test-{{ arg_f }}-{{ arg_t }}"

        pattern = re.compile(r"{{(.*?)}}")
        matches = pattern.findall(yaml_v)
        for match in matches:
            var_name = match.strip()
            yaml_v = manager._YamlScenarioManager__replace_vars(yaml_v, var_name)

        assert yaml_v == "test-FROM-TO"
예제 #8
0
 def test_create_ok(self):
     """
     Succeeded to create instance with yml
     """
     manager = ScenarioManagerFactory.create(self._cmd_args)
     self.assertTrue(
         isinstance(manager, type(YamlScenarioManager(self._cmd_args))))
예제 #9
0
    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)
예제 #10
0
 def test_scenario_manager_factory_ok_yml(self):
     """
     Succeeded to create instance with yml
     """
     manager = ScenarioManagerFactory.create(self._cmd_args)
     assert isinstance(manager, type(YamlScenarioManager(self._cmd_args)))