Skip to content

Commit

Permalink
Extract test values to constants
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalp committed Sep 10, 2018
1 parent a457266 commit 21455d2
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions tests/test_custom_scalars.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

from ariadne import make_executable_schema

TEST_DATE = date(2005, 7, 29)
TEST_DATE_SERIALIZED = TEST_DATE.strftime('%Y-%m-%d')

type_defs = """
scalar DateReadOnly
scalar DateInput
Expand Down Expand Up @@ -41,11 +44,11 @@ def parse_value(formatted_date):


def resolve_test_serialize(*_):
return date.today()
return TEST_DATE


def resolve_test_input(*_, value):
assert value == date.today()
assert value == TEST_DATE
return True


Expand All @@ -61,11 +64,11 @@ def resolve_test_input(*_, value):
def test_serialize_date_obj_to_date_str():
result = graphql(schema, "{ testSerialize }")
assert result.errors is None
assert result.data == {"testSerialize": date.today().strftime("%Y-%m-%d")}
assert result.data == {"testSerialize": TEST_DATE_SERIALIZED}


def test_parse_literal_valid_str_ast_to_date_instance():
test_input = date.today().strftime("%Y-%m-%d")
test_input = TEST_DATE_SERIALIZED
result = graphql(schema, '{ testInput(value: "%s") }' % test_input)
assert result.errors is None
assert result.data == {"testInput": True}
Expand Down Expand Up @@ -99,7 +102,7 @@ def test_parse_literal_invalid_int_ast_errors():


def test_parse_value_valid_date_str_returns_date_instance():
variables = {"value": date.today().strftime("%Y-%m-%d")}
variables = {"value": TEST_DATE_SERIALIZED}
result = graphql(schema, parametrized_query, variables=variables)
assert result.errors is None
assert result.data == {"testInput": True}
Expand Down

0 comments on commit 21455d2

Please sign in to comment.