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
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
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
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
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
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"
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
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
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
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
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
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
def download_component_zip(component_key: str) -> bytes: org, comp, v = COMPONENT_RE.fullmatch(component_key).groups() resp = get(Endpoints.component_download(org, comp, v)) resp.raise_for_status() return resp.content
def get_organization_by_id(organization_uid: str) -> dict: return get_json(Endpoints.organization_by_id(organization_uid))
def get_graph_by_uid(graph_uid: str) -> dict: return get_json(Endpoints.graphs_latest(graph_uid))
def get_graph_by_slug(organization_uid: str, slug: str) -> dict: return get_json(Endpoints.graph_by_slug(organization_uid, slug))
def get_graph_version_by_id(graph_version_uid) -> dict: return get_json(Endpoints.graph_version_by_id(graph_version_uid))
def get_organization_by_name(name: str) -> dict: return get_json(Endpoints.organization_by_slug(name))
def paginated_graphs(organization_uid: str): return get_json(Endpoints.graphs_list(organization_uid))
def delete_graph(graph_uid: str): delete(Endpoints.graph_delete(graph_uid))
def download_graph_zip(graph_version_uid: str) -> bytes: resp = get(Endpoints.graph_version_download(graph_version_uid)) resp.raise_for_status() return resp.content
def get_environment_by_id(environment_uid: str) -> dict: return get_json(Endpoints.environment_by_id(environment_uid))
def get_environment_by_name(organization_uid: str, name: str) -> dict: return get_json(Endpoints.environment_by_slug(organization_uid, name))
def paginated_environments(environment_uid: str): return get_json(Endpoints.environments_list(environment_uid))