コード例 #1
0
def instantiate(tmpdir, ctlr=None, **kwargs):

    path_dir = str(tmpdir.mkdir("chain_out"))

    path_1 = os.path.join(path_dir, "test")

    echo_1_plugin = instantiate_test_plugin(
        "command",
        "echo_1",
        _ctl=ctlr,
        config={
            "command": [f"echo 'echo 1 ran' > {path_1}"],
            "shell": True
        },
    )
    assert echo_1_plugin

    path_2 = os.path.join(path_dir, "test2")

    echo_2_plugin = instantiate_test_plugin(
        "command",
        "echo_2",
        _ctl=ctlr,
        config={
            "command": ["echo '{{ kwargs.content }}' " + f" > {path_2}"],
            "shell": True,
        },
    )
    assert echo_2_plugin

    config = {
        "config": {
            "chain": [
                {
                    "stage": "first",
                    "plugin": "echo_1"
                },
                {
                    "stage": "second",
                    "plugin": "echo_2",
                    "action": {
                        "name": "execute",
                        "arguments": {
                            "content": "echo 2 ran"
                        },
                    },
                },
            ]
        }
    }
    config["config"].update(**kwargs)
    plugin = instantiate_test_plugin("chain",
                                     "test_chain",
                                     _ctl=ctlr,
                                     **config)
    return plugin, path_1, path_2
コード例 #2
0
ファイル: test_plugin_log_alert.py プロジェクト: 20c/ctl
def test_init_and_collect(logged, alerted, levels, output_levels):
    # create temp file to log messages to
    dummy_alert = ctl.plugin._instance["dummy_alert"] = DummyAlert({}, None)
    logger_name = "a_logger"

    # logger config as passed to the plugin
    logger_config = {"logger": logger_name, "format": "%(message)s"}
    config = {"config": {"loggers": [logger_config]}}

    # instantiate plugin
    plugin = instantiate_test_plugin("log_alert", "test_log", **config)

    log = Log(logger_name)

    for fn in logged:
        getattr(log, fn)(fn.upper())

    collected = [(level, f"[{logger_name}] {level.upper()}") for level in logged]
    alerted = [f"[{logger_name}] {level.upper()}" for level in alerted]

    assert plugin.messages == collected

    plugin.alert(plugin="dummy_alert", levels=levels, output_levels=output_levels)

    print(dummy_alert.alerts)

    assert dummy_alert.alerts == alerted
コード例 #3
0
def test_apply():
    username = pwd.getpwuid(os.getuid()).pw_name
    plugin = instantiate_test_plugin("log_user", "test_log_user")

    assert plugin.username == username

    assert plugin.apply("this is a test") == "{username} - this is a test".format(
        username=username
    )
コード例 #4
0
def test_apply():

    username = pwd.getpwuid(os.getuid()).pw_name

    config = {"config": {"git": "git_dummy"}}

    ctl.plugin._instance["git_dummy"] = GitDummy({}, None)

    plugin = instantiate_test_plugin("log_git", "test_log_git", **config)

    assert plugin.apply("test", "error") == f"deadbeef:123 {username} - test"
コード例 #5
0
def instantiate(tmpdir, ctlr=None, **kwargs):
    config = {
        "config": {
            "source": os.path.join(os.path.dirname(__file__), "data"),
            "output": str(tmpdir.mkdir("walk_dir_out")),
            "debug": True,
            "walk_dirs": ["walk_dir"],
        }
    }
    config["config"].update(**kwargs)
    plugin = instantiate_test_plugin("walk_dir", "test_walk_dir", _ctl=ctlr, **config)
    return plugin
コード例 #6
0
def instantiate(tmpdir, ctlr=None, **kwargs):
    base_dir = os.path.join(os.path.dirname(__file__), "data", "pypi")
    config = {"config": {"config_file": os.path.join(base_dir, "pypirc")}}
    config["config"].update(**kwargs)
    plugin = instantiate_test_plugin("pypi", "test_pypi", _ctl=ctlr, **config)

    package_path = os.path.join(base_dir, "package")

    git_plugin, repo_path = instantiate_git(tmpdir, ctlr)
    package_repo(package_path, git_plugin.checkout_path)

    return plugin, git_plugin
コード例 #7
0
def instantiate(tmpdir, ctlr=None, **kwargs):
    vi = sys.version_info
    config = {
        "config": {
            "pipfile": os.path.join(
                os.path.dirname(__file__), "data", "venv", "Pipfile"
            ),
            "python_version": "{}.{}".format(vi[0], vi[1]),
        }
    }
    print(config)
    config["config"].update(**kwargs)
    plugin = instantiate_test_plugin("venv", "test_venv", _ctl=ctlr, **config)
    return plugin
コード例 #8
0
def test_process(tmpdir, ctlr):
    process = [{"plugin": "echo", "action": "execute", "pattern": "file_1"}]
    echo_plugin = instantiate_test_plugin(
        "command",
        "echo",
        _ctl=ctlr,
        config={"command": ["echo 'processed' > {{ kwargs.output }}"], "shell": True},
    )
    plugin = instantiate(tmpdir, ctlr, process=process)
    plugin.execute()

    assert len(plugin.debug_info["processed"]) == 2
    for processed in plugin.debug_info["processed"]:
        with open(processed["output"]) as fh:
            assert fh.read() == "processed\n"
コード例 #9
0
def instantiate(tmpdir, ctlr=None, **kwargs):
    dirpath = f"{tmpdir}"
    md_file = os.path.join(dirpath, "CHANGELOG.md")
    data_file = os.path.join(dirpath, "CHANGELOG.yml")
    config = {
        "config": {
            "md_file": md_file,
            "data_file": data_file,
        }
    }
    config["config"].update(kwargs)
    plugin = instantiate_test_plugin("changelog",
                                     "test_changelog",
                                     _ctl=ctlr,
                                     **config)
    return plugin
コード例 #10
0
ファイル: test_plugin_git.py プロジェクト: 20c/ctl
def instantiate(tmpdir, ctlr=None, **kwargs):
    repo_path, repo_path_clone = init_tmp_repo(tmpdir)
    print((repo_path, repo_path_clone))
    config = {
        "config": {
            "repo_url": repo_path,
            "checkout_path": str(tmpdir.mkdir("git_repo_co")),
        }
    }
    config["config"].update(**kwargs)
    plugin = instantiate_test_plugin("git", "test_git", _ctl=ctlr, **config)

    subprocess.call(
        [
            "cd {path}; git config user.name pytest; git config user.email pytest@localhost"
            .format(path=plugin.checkout_path)
        ],
        shell=True,
    )

    return plugin, repo_path_clone
コード例 #11
0
ファイル: test_plugin_log.py プロジェクト: 20c/ctl
def test_logger(tmpdir):
    # create temp file to log messages to
    logfile = tmpdir.join("test.log")

    # logger config as passed to the plugin
    logger_config = {
        "logger": "a_logger",
        "file": str(logfile),
        "format": "%(message)s",
    }
    config = {"config": {"loggers": [logger_config]}}

    # instantiate plugin
    plugin = instantiate_test_plugin("log", "test_log", **config)

    # check that it was attached to the logger specified in config
    assert ATTACHED["a_logger"] == [plugin]

    # log a message to test that the logger was configured through
    # plugin
    logging.getLogger("a_logger").error("test")

    assert logfile.read() == "test\n"
コード例 #12
0
ファイル: test_plugin_log.py プロジェクト: 20c/ctl
def test_init():
    plugin = instantiate_test_plugin("log", "test_log")
    assert plugin.loggers == []