From 23782ecc9a12f055d95020cf07d391fab98b52ce Mon Sep 17 00:00:00 2001 From: j03-dev <24nomeniavo@gmail.com> Date: Wed, 18 Dec 2024 19:02:54 +0300 Subject: [PATCH] add test that should reject the bad code deploy --- tests/runtimes/python/python.py | 7 ------ tests/runtimes/python/python_test.ts | 17 +++++--------- tests/runtimes/python/python_validation.py | 26 ++++++++++++++++++++++ 3 files changed, 31 insertions(+), 19 deletions(-) create mode 100644 tests/runtimes/python/python_validation.py diff --git a/tests/runtimes/python/python.py b/tests/runtimes/python/python.py index 907d24161..1e00272ac 100644 --- a/tests/runtimes/python/python.py +++ b/tests/runtimes/python/python.py @@ -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), ) diff --git a/tests/runtimes/python/python_test.ts b/tests/runtimes/python/python_test.ts index 76f2bd146..15f2afa9f 100644 --- a/tests/runtimes/python/python_test.ts +++ b/tests/runtimes/python/python_test.ts @@ -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"; @@ -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", + ); }); }, ); diff --git a/tests/runtimes/python/python_validation.py b/tests/runtimes/python/python_validation.py new file mode 100644 index 000000000..a77b844bc --- /dev/null +++ b/tests/runtimes/python/python_validation.py @@ -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), + ) + )