Skip to content

Commit

Permalink
WIP: add data validation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
la4de committed Apr 3, 2021
1 parent 46d3975 commit 31680fc
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/types/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@


def upper_validator(value, info):
if info.context and info.context in value:
raise ValueError("Invalid value")
return value.upper()


Expand All @@ -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
Expand Down Expand Up @@ -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"

0 comments on commit 31680fc

Please sign in to comment.