예제 #1
0
def test_trigger_node_in_subgraph(tmp_path: Path):
    dr = set_tmp_dir(tmp_path).parent / "graph"
    name = "sub/graph.yml"
    run_cli("create graph", f"{dr}\n")
    path = dr / name
    run_cli(f"create node", f"{path}\n")
    name = (dr / "sub/p.py").as_posix()
    run_cli(f"create node", f"{name}\n")

    with request_mocker() as m:
        m.post(
            API_BASE_URL + Endpoints.DEPLOYMENTS_TRIGGER_NODE,
            json={"uid": "1"},
        )
        m.get(
            API_BASE_URL + Endpoints.graph_by_slug("test-org-uid", "graph"),
            json={"uid": "2"},
        )
        m.get(
            API_BASE_URL + Endpoints.graphs_latest("2"),
            json={"active_graph_version": {
                "uid": "3"
            }},
        )
        result = run_cli(f"trigger {name}")
        assert "Triggered node" in result.output
예제 #2
0
파일: test_upload.py 프로젝트: kvh/snapflow
def test_upload_custom_yaml_name(tmp_path: Path):
    dr = set_tmp_dir(tmp_path).parent
    path = dr / "name"
    path.mkdir()
    graph_file = path / "custom.yml"
    graph_file.write_text("""
name: name
stores:
 - table: t
""".lstrip())

    with request_mocker() as m:
        m.post(
            API_BASE_URL + Endpoints.graph_version_create("test-org-uid"),
            json={
                "uid": "1",
                "ui_url": "url.com",
                "graph": {
                    "name": "g"
                },
                "manifest": {},
            },
        )
        result = run_cli(f"upload --no-deploy {graph_file.as_posix()}")
        assert "Uploaded new graph" in result.output
예제 #3
0
파일: test_list.py 프로젝트: kvh/snapflow
def test_list_data(tmp_path: Path):
    dr = set_tmp_dir(tmp_path).parent
    path = dr / "name"
    node = path / "node.py"
    run_cli(f"create graph {path}")
    run_cli(f"create node {node}")

    store_name = "test"

    with request_mocker() as m:
        m.get(
            API_BASE_URL + Endpoints.graph_by_slug("test-org-uid", "name"),
            json={"uid": "1"},
        )
        m.get(
            API_BASE_URL + Endpoints.OUTPUT_DATA,
            json={
                "results": [{
                    "name": "name"
                }],
                "next": None
            },
        )
        result = run_cli(f"list output {store_name} -g {path} --json")
    assert "name" in result.output
예제 #4
0
파일: test_delete.py 프로젝트: kvh/snapflow
def test_delete(tmp_path: Path):
    set_tmp_dir(tmp_path)

    with request_mocker() as m:
        m.delete(API_BASE_URL + Endpoints.graph_delete("uid"))

        result = run_cli(f"delete -f --graph-id uid")
        assert "Graph deleted" in result.output
예제 #5
0
파일: test_upload.py 프로젝트: kvh/snapflow
def test_upload(tmp_path: Path):
    dr = set_tmp_dir(tmp_path).parent
    path = dr / "name"
    path.mkdir()
    graph_file = path / "graph.yml"
    text_before = """
name: name
slug: test-graph
exposes:
  outputs:
    - output
functions:
  - node_file: p.py
""".lstrip()
    graph_file.write_text(text_before)
    (path / "p.py").write_text("""
from patterns import *
@node
def node_fn(output=OutputTable):
    pass
""")

    with request_mocker() as m:
        for e in [
                Endpoints.graph_version_create("test-org-uid"),
                Endpoints.DEPLOYMENTS_DEPLOY,
        ]:
            m.post(
                API_BASE_URL + e,
                json={
                    "uid": "1",
                    "ui_url": "url.com",
                    "graph": {
                        "name": "g"
                    },
                    "errors": [{
                        "node_id": "n1",
                        "message": "Test Error"
                    }]
                },
            )
        result = run_cli(f"upload {path}")
        assert "Uploaded new graph" in result.output
        assert "Test Error" in result.output
        assert "Graph deployed" in result.output
        assert "url.com" in result.output

        result = run_cli(f"upload --no-deploy {path}")
        assert "Uploaded new graph" in result.output
        assert "Graph deployed" not in result.output
        assert (b'{"slug": "test-graph", "root_yaml_path": "graph.yml"}'
                in m.last_request.body)

    text_after = graph_file.read_text()
    assert text_after[:len(text_before)] == text_before
    assert "id: " in text_after
예제 #6
0
def test_clone(tmp_path: Path):
    dr = set_tmp_dir(tmp_path).parent
    path = dr / "name"
    content = "nodes: []"

    with request_mocker() as m:
        b = io.BytesIO()
        with ZipFile(b, "w") as zf:
            zf.writestr("graph.yml", content)
        m.get(
            API_BASE_URL + Endpoints.graph_version_download("uid"),
            content=b.getvalue(),
        )

        result = run_cli(f"clone --version=uid {path}")
        assert "Cloned graph" in result.output
        assert (path / "graph.yml").read_text() == content
예제 #7
0
파일: test_config.py 프로젝트: kvh/snapflow
def test_config_org_and_env(tmp_path: Path):
    set_tmp_dir(tmp_path)
    old_cfg = read_devkit_config()
    assert old_cfg.environment_id == "test-env-uid"
    assert old_cfg.organization_id == "test-org-uid"

    with request_mocker() as m:
        m.get(
            API_BASE_URL + Endpoints.organization_by_slug("org"),
            json={"uid": "org-uid"},
        )
        m.get(
            API_BASE_URL + Endpoints.environment_by_slug("org-uid", "env"),
            json={"uid": "env-uid"},
        )
        run_cli("config -o org -e env")
    new_cfg = read_devkit_config()
    assert new_cfg.organization_id == "org-uid"
    assert new_cfg.environment_id == "env-uid"
예제 #8
0
파일: test_deploy.py 프로젝트: kvh/snapflow
def test_deploy(tmp_path: Path):
    dr = set_tmp_dir(tmp_path).parent
    path = dr / "name"

    with request_mocker() as m:
        for e in [
                Endpoints.graph_version_create("test-org-uid"),
                Endpoints.DEPLOYMENTS_DEPLOY,
        ]:
            m.post(
                API_BASE_URL + e,
                json={
                    "uid": "1",
                    "ui_url": "url.com",
                    "graph": {
                        "name": "g"
                    },
                    "manifest": {}
                },
            )
        for e in [
                Endpoints.graph_by_slug("test-org-uid", "name"),
                Endpoints.graphs_latest("1"),
        ]:
            m.get(
                API_BASE_URL + e,
                json={
                    "uid": "1",
                    "active_graph_version": {
                        "uid": "1"
                    }
                },
            )

        run_cli(f"create graph {path}")

        result = run_cli(f"upload --no-deploy {path}")
        assert "Uploaded new graph" in result.output
        assert "Graph deployed" not in result.output

        result = run_cli(f"deploy --graph={path}")
        assert "deployed" in result.output
예제 #9
0
파일: test_list.py 프로젝트: kvh/snapflow
def test_list(tmp_path: Path):
    set_tmp_dir(tmp_path)
    with request_mocker() as m:
        for e in [
                Endpoints.environments_list("test-org-uid"),
                Endpoints.graphs_list("test-org-uid"),
        ]:
            m.get(
                API_BASE_URL + e,
                json={
                    "results": [{
                        "name": "name"
                    }],
                    "next": None
                },
            )
        result = run_cli("list environments --json")
        assert "name" in result.output
        result = run_cli("list graphs --json")
        assert "name" in result.output
예제 #10
0
파일: test_list.py 프로젝트: kvh/snapflow
def test_list_components(tmp_path: Path):
    set_tmp_dir(tmp_path)
    with request_mocker() as m:
        m.get(
            API_BASE_URL + Endpoints.COMPONENTS_LIST,
            json={
                "results": [{
                    "uid": "uid1",
                    "latest_version": {
                        "uid": "uid2",
                        "version_names": ["gvuid"],
                        "graph_version_uid": "gvuid",
                    },
                }],
                "next":
                None,
            },
        )
        result = run_cli("list components --json")
        assert "uid1" in result.output
예제 #11
0
파일: test_upload.py 프로젝트: kvh/snapflow
def test_upload_component(tmp_path: Path):
    dr = set_tmp_dir(tmp_path).parent
    path = "/".join((dr / "name").parts)
    run_cli(f"create graph {path}")
    run_cli(f"create node {path}/node.py")

    with request_mocker() as m:
        for e in [
                Endpoints.graph_version_create("test-org-uid"),
                Endpoints.DEPLOYMENTS_DEPLOY,
        ]:
            m.post(
                API_BASE_URL + e,
                json={
                    "uid": "1",
                    "ui_url": "url.com",
                    "graph": {
                        "name": "g"
                    },
                    "errors": []
                },
            )
        m.post(
            API_BASE_URL + Endpoints.COMPONENTS_CREATE,
            json={
                "uid": "2",
                "version_name": "1.1.1",
                "component": {
                    "uid": "3",
                    "slug": "c"
                },
                "organization": {
                    "uid": "4",
                    "slug": "o"
                },
            },
        )
        result = run_cli(f"upload --publish-component {path}")
        assert "Uploaded new graph" in result.output
        assert "Published graph component" in result.output
예제 #12
0
파일: test_list.py 프로젝트: kvh/snapflow
def test_list_webhooks(tmp_path: Path):
    dr = set_tmp_dir(tmp_path).parent
    path = dr / "name"
    name = "deployed_webhook"
    run_cli(f"create graph {path}")
    run_cli(f"create webhook --graph='{path}' undeployed_webhook")
    with request_mocker() as m:
        m.get(
            API_BASE_URL + Endpoints.graph_by_slug("test-org-uid", "name"),
            json={"uid": "1"},
        )
        m.get(
            API_BASE_URL + Endpoints.WEBHOOKS,
            json={
                "results": [{
                    "name": name
                }],
                "next": None
            },
        )
        result = run_cli(f"list webhooks --json {path}")
    assert name in result.output
예제 #13
0
파일: test_list.py 프로젝트: kvh/snapflow
def test_list_logs(tmp_path: Path):
    dr = set_tmp_dir(tmp_path).parent
    path = dr / "name"
    node = path / "node.py"
    run_cli(f"create graph {path}")
    run_cli(f"create node {node}")
    with request_mocker() as m:
        m.get(
            API_BASE_URL + Endpoints.graph_by_slug("test-org-uid", "name"),
            json={"uid": "1"},
        )
        m.get(
            API_BASE_URL + Endpoints.EXECUTION_EVENTS,
            json={
                "results": [{
                    "name": "name"
                }],
                "next": None
            },
        )
        result = run_cli(f"list logs {node} --json")
    assert "name" in result.output