-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathtest_runtime.py
More file actions
57 lines (41 loc) · 1.59 KB
/
test_runtime.py
File metadata and controls
57 lines (41 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import pytest
from graphql import (
ExecutionResult,
GraphQLField,
GraphQLObjectType,
GraphQLSchema,
GraphQLString,
GraphQLError,
parse,
)
import graphql_server.runtime as runtime
schema = GraphQLSchema(
query=GraphQLObjectType('Query', {'hello': GraphQLField(GraphQLString)})
)
def test_validate_document_with_rules():
from graphql.validation.rules.no_unused_fragments import NoUnusedFragmentsRule
doc = parse('query Test { hello }')
assert runtime.validate_document(schema, doc, (NoUnusedFragmentsRule,)) == []
def test_get_custom_context_kwargs(monkeypatch):
assert runtime._get_custom_context_kwargs({'a': 1}) == {'operation_extensions': {'a': 1}}
monkeypatch.setattr(runtime, 'IS_GQL_33', False)
try:
assert runtime._get_custom_context_kwargs({'a': 1}) == {}
finally:
monkeypatch.setattr(runtime, 'IS_GQL_33', True)
def test_get_operation_type_multiple_operations():
doc = parse('query A{hello} query B{hello}')
with pytest.raises(Exception):
runtime._get_operation_type(doc)
def test_parse_and_validate_document_node():
doc = parse('query Q { hello }')
res = runtime._parse_and_validate(schema, doc, None)
assert res == doc
def test_introspect_success_and_failure(monkeypatch):
data = runtime.introspect(schema)
assert '__schema' in data
def fake_execute_sync(schema, query):
return ExecutionResult(data=None, errors=[GraphQLError('boom')])
monkeypatch.setattr(runtime, 'execute_sync', fake_execute_sync)
with pytest.raises(ValueError):
runtime.introspect(schema)