Skip to content

Commit 9973fd3

Browse files
author
Anis Jonischkeit
committed
added tests for when bad input is passed into date/datetime/time fields
1 parent 2a67ffe commit 9973fd3

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

graphene/types/tests/test_datetime.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import pytz
44

5+
from graphql import GraphQLError
6+
57
from ..datetime import DateTime, Date, Time
68
from ..objecttype import ObjectType
79
from ..schema import Schema
@@ -53,6 +55,32 @@ def test_time_query():
5355
assert not result.errors
5456
assert result.data == {'time': isoformat}
5557

58+
def test_bad_datetime_query():
59+
not_a_date = "Some string that's not a date"
60+
61+
result = schema.execute('''{ datetime(in: "%s") }''' % not_a_date)
62+
63+
assert len(result.errors) == 1
64+
assert isinstance(result.errors[0], GraphQLError)
65+
assert result.data == None
66+
67+
def test_bad_date_query():
68+
not_a_date = "Some string that's not a date"
69+
70+
result = schema.execute('''{ date(in: "%s") }''' % not_a_date)
71+
72+
assert len(result.errors) == 1
73+
assert isinstance(result.errors[0], GraphQLError)
74+
assert result.data == None
75+
76+
def test_bad_time_query():
77+
not_a_date = "Some string that's not a date"
78+
79+
result = schema.execute('''{ time(at: "%s") }''' % not_a_date)
80+
81+
assert len(result.errors) == 1
82+
assert isinstance(result.errors[0], GraphQLError)
83+
assert result.data == None
5684

5785
def test_datetime_query_variable():
5886
now = datetime.datetime.now().replace(tzinfo=pytz.utc)

0 commit comments

Comments
 (0)