mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-22 09:36:44 +03:00
Added jsonstring tests
This commit is contained in:
parent
5dd92b7d6b
commit
88ccaec8fa
|
@ -22,7 +22,7 @@ before_install:
|
|||
install:
|
||||
- |
|
||||
if [ "$TEST_TYPE" = build ]; then
|
||||
pip install pytest pytest-cov pytest-benchmark coveralls six
|
||||
pip install pytest pytest-cov pytest-benchmark coveralls six pytz iso8601
|
||||
pip install -e .
|
||||
python setup.py develop
|
||||
elif [ "$TEST_TYPE" = lint ]; then
|
||||
|
|
39
graphene/types/tests/test_json.py
Normal file
39
graphene/types/tests/test_json.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
import json
|
||||
|
||||
from ..json import JSONString
|
||||
from ..objecttype import ObjectType
|
||||
from ..schema import Schema
|
||||
|
||||
|
||||
class Query(ObjectType):
|
||||
json = JSONString(input=JSONString())
|
||||
|
||||
def resolve_json(self, args, context, info):
|
||||
input = args.get('input')
|
||||
return input
|
||||
|
||||
schema = Schema(query=Query)
|
||||
|
||||
|
||||
def test_jsonstring_query():
|
||||
json_value = '{"key": "value"}'
|
||||
|
||||
json_value_quoted = json_value.replace('"', '\\"')
|
||||
result = schema.execute('''{ json(input: "%s") }'''%json_value_quoted)
|
||||
assert not result.errors
|
||||
assert result.data == {
|
||||
'json': json_value
|
||||
}
|
||||
|
||||
|
||||
def test_jsonstring_query_variable():
|
||||
json_value = '{"key": "value"}'
|
||||
|
||||
result = schema.execute(
|
||||
'''query Test($json: JSONString){ json(input: $json) }''',
|
||||
variable_values={'json': json_value}
|
||||
)
|
||||
assert not result.errors
|
||||
assert result.data == {
|
||||
'json': json_value
|
||||
}
|
Loading…
Reference in New Issue
Block a user