Skip to content

Commit

Permalink
add test that should reject the bad code deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
j03-dev committed Dec 18, 2024
1 parent 881e8e3 commit 23782ec
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
7 changes: 0 additions & 7 deletions tests/runtimes/python/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,4 @@ def python(g: Graph):
t.boolean(),
infinite_loop,
).with_policy(public),
testValidation=python.import_(
t.struct({"name": t.string()}),
t.string(),
module="py/hello_fail.py.py",
deps=["py/nested/dep_fail.py"],
name="sayHello",
).with_policy(public),
)
17 changes: 5 additions & 12 deletions tests/runtimes/python/python_test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0.
// SPDX-License-Identifier: MPL-2.0

import { assert, assertEquals } from "@std/assert";
import { assert, assertEquals, assertRejects } from "@std/assert";
import { gql, Meta } from "test-utils/mod.ts";
import { WitWireMessenger } from "@metatype/typegate/runtimes/wit_wire/mod.ts";
import { QueryEngine } from "@metatype/typegate/engine/query_engine.ts";
Expand Down Expand Up @@ -484,18 +484,11 @@ Meta.test(
name: "Python code validation on deploy",
},
async (t) => {
const e = await t.engine(
"runtimes/python/python.py",
);

await t.should("fail on validation", async () => {
await gql`
query {
testValidation(name: "Loyd")
}
`
.expectErrorContains("Python code validation error")
.on(e);
await assertRejects(
async () => await t.engine("runtimes/python/python_validation.py"),
"ValidationError",
);
});
},
);
26 changes: 26 additions & 0 deletions tests/runtimes/python/python_validation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0.
# SPDX-License-Identifier: MPL-2.0

from typegraph.graph.typegraph import Graph
from typegraph.policy import Policy
from typegraph.runtimes.python import PythonRuntime

from typegraph import t, typegraph


@typegraph()
def python(g: Graph):
public = Policy.public()
python = PythonRuntime()

g.expose(
testValidation=(
python.import_(
t.struct({"name": t.string()}),
t.string(),
module="py/hello_fail.py",
deps=["py/nested/dep_fail.py"],
name="sayHello",
).with_policy(public),
)
)

0 comments on commit 23782ec

Please sign in to comment.