Added jsonstring tests

This commit is contained in:
Syrus Akbary 2016-10-03 20:58:57 -07:00
parent 5dd92b7d6b
commit 88ccaec8fa
2 changed files with 40 additions and 1 deletions

View File

@ -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

View 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
}