added tests for when bad input is passed into date/datetime/time fields

This commit is contained in:
Anis Jonischkeit 2018-03-14 13:06:10 +10:00
parent 2a67ffeb35
commit 9973fd314f

View File

@ -2,6 +2,8 @@ import datetime
import pytz
from graphql import GraphQLError
from ..datetime import DateTime, Date, Time
from ..objecttype import ObjectType
from ..schema import Schema
@ -53,6 +55,32 @@ def test_time_query():
assert not result.errors
assert result.data == {'time': isoformat}
def test_bad_datetime_query():
not_a_date = "Some string that's not a date"
result = schema.execute('''{ datetime(in: "%s") }''' % not_a_date)
assert len(result.errors) == 1
assert isinstance(result.errors[0], GraphQLError)
assert result.data == None
def test_bad_date_query():
not_a_date = "Some string that's not a date"
result = schema.execute('''{ date(in: "%s") }''' % not_a_date)
assert len(result.errors) == 1
assert isinstance(result.errors[0], GraphQLError)
assert result.data == None
def test_bad_time_query():
not_a_date = "Some string that's not a date"
result = schema.execute('''{ time(at: "%s") }''' % not_a_date)
assert len(result.errors) == 1
assert isinstance(result.errors[0], GraphQLError)
assert result.data == None
def test_datetime_query_variable():
now = datetime.datetime.now().replace(tzinfo=pytz.utc)