Skip to content

Commit 88ccaec

Browse files
committed
Added jsonstring tests
1 parent 5dd92b7 commit 88ccaec

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ before_install:
2222
install:
2323
- |
2424
if [ "$TEST_TYPE" = build ]; then
25-
pip install pytest pytest-cov pytest-benchmark coveralls six
25+
pip install pytest pytest-cov pytest-benchmark coveralls six pytz iso8601
2626
pip install -e .
2727
python setup.py develop
2828
elif [ "$TEST_TYPE" = lint ]; then

graphene/types/tests/test_json.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import json
2+
3+
from ..json import JSONString
4+
from ..objecttype import ObjectType
5+
from ..schema import Schema
6+
7+
8+
class Query(ObjectType):
9+
json = JSONString(input=JSONString())
10+
11+
def resolve_json(self, args, context, info):
12+
input = args.get('input')
13+
return input
14+
15+
schema = Schema(query=Query)
16+
17+
18+
def test_jsonstring_query():
19+
json_value = '{"key": "value"}'
20+
21+
json_value_quoted = json_value.replace('"', '\\"')
22+
result = schema.execute('''{ json(input: "%s") }'''%json_value_quoted)
23+
assert not result.errors
24+
assert result.data == {
25+
'json': json_value
26+
}
27+
28+
29+
def test_jsonstring_query_variable():
30+
json_value = '{"key": "value"}'
31+
32+
result = schema.execute(
33+
'''query Test($json: JSONString){ json(input: $json) }''',
34+
variable_values={'json': json_value}
35+
)
36+
assert not result.errors
37+
assert result.data == {
38+
'json': json_value
39+
}

0 commit comments

Comments
 (0)