mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-09 08:00:39 +03:00
Added datetime tests
This commit is contained in:
parent
95280e4f7c
commit
5dd92b7d6b
41
graphene/types/tests/test_datetime.py
Normal file
41
graphene/types/tests/test_datetime.py
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
import datetime
|
||||||
|
import pytz
|
||||||
|
|
||||||
|
from ..datetime import DateTime
|
||||||
|
from ..objecttype import ObjectType
|
||||||
|
from ..schema import Schema
|
||||||
|
|
||||||
|
|
||||||
|
class Query(ObjectType):
|
||||||
|
datetime = DateTime(_in=DateTime(name='in'))
|
||||||
|
|
||||||
|
def resolve_datetime(self, args, context, info):
|
||||||
|
_in = args.get('in')
|
||||||
|
return _in
|
||||||
|
|
||||||
|
schema = Schema(query=Query)
|
||||||
|
|
||||||
|
|
||||||
|
def test_datetime_query():
|
||||||
|
now = datetime.datetime.now().replace(tzinfo=pytz.utc)
|
||||||
|
isoformat = now.isoformat()
|
||||||
|
|
||||||
|
result = schema.execute('''{ datetime(in: "%s") }'''%isoformat)
|
||||||
|
assert not result.errors
|
||||||
|
assert result.data == {
|
||||||
|
'datetime': isoformat
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test_datetime_query_variable():
|
||||||
|
now = datetime.datetime.now().replace(tzinfo=pytz.utc)
|
||||||
|
isoformat = now.isoformat()
|
||||||
|
|
||||||
|
result = schema.execute(
|
||||||
|
'''query Test($date: DateTime){ datetime(in: $date) }''',
|
||||||
|
variable_values={'date': isoformat}
|
||||||
|
)
|
||||||
|
assert not result.errors
|
||||||
|
assert result.data == {
|
||||||
|
'datetime': isoformat
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user