From 31680fcce7ff885f8c9a6a1becfe16137d43d2f3 Mon Sep 17 00:00:00 2001 From: Lauri Hintsala Date: Sat, 3 Apr 2021 22:45:35 +0300 Subject: [PATCH] WIP: add data validation tests --- tests/types/test_validators.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/types/test_validators.py b/tests/types/test_validators.py index ffa185577f..be85b7b128 100644 --- a/tests/types/test_validators.py +++ b/tests/types/test_validators.py @@ -2,6 +2,8 @@ def upper_validator(value, info): + if info.context and info.context in value: + raise ValueError("Invalid value") return value.upper() @@ -23,6 +25,11 @@ def type() -> Type: assert not result.errors assert result.data["type"]["string"] == "HELLO" + # error case + result = schema.execute_sync("{ type { string } }", context_value="hello") + + assert result.errors[0].message == "Invalid value" + def test_validator_decorator(): @strawberry.type @@ -68,3 +75,10 @@ def mutation(self, input: Input) -> str: assert not result.errors assert result.data["mutation"] == "HELLO" + + # error case + result = schema.execute_sync( + 'mutation { mutation(input: { string: "hello" }) }', context_value="hello" + ) + + assert result.errors[0].message == "Invalid value"