|
1 | 1 | import pytest |
2 | 2 | from graphql import ( |
3 | 3 | ExecutionResult, |
| 4 | + GraphQLError, |
4 | 5 | GraphQLField, |
5 | 6 | GraphQLObjectType, |
6 | 7 | GraphQLSchema, |
7 | 8 | GraphQLString, |
8 | | - GraphQLError, |
9 | 9 | parse, |
10 | 10 | ) |
11 | 11 |
|
12 | | -import graphql_server.runtime as runtime |
13 | | - |
| 12 | +from graphql_server import runtime |
14 | 13 |
|
15 | 14 | schema = GraphQLSchema( |
16 | | - query=GraphQLObjectType('Query', {'hello': GraphQLField(GraphQLString)}) |
| 15 | + query=GraphQLObjectType("Query", {"hello": GraphQLField(GraphQLString)}) |
17 | 16 | ) |
18 | 17 |
|
19 | 18 |
|
20 | 19 | def test_validate_document_with_rules(): |
21 | 20 | from graphql.validation.rules.no_unused_fragments import NoUnusedFragmentsRule |
22 | 21 |
|
23 | | - doc = parse('query Test { hello }') |
| 22 | + doc = parse("query Test { hello }") |
24 | 23 | assert runtime.validate_document(schema, doc, (NoUnusedFragmentsRule,)) == [] |
25 | 24 |
|
26 | 25 |
|
27 | 26 | def test_get_custom_context_kwargs(monkeypatch): |
28 | | - assert runtime._get_custom_context_kwargs({'a': 1}) == {'operation_extensions': {'a': 1}} |
29 | | - monkeypatch.setattr(runtime, 'IS_GQL_33', False) |
| 27 | + assert runtime._get_custom_context_kwargs({"a": 1}) == { |
| 28 | + "operation_extensions": {"a": 1} |
| 29 | + } |
| 30 | + monkeypatch.setattr(runtime, "IS_GQL_33", False) |
30 | 31 | try: |
31 | | - assert runtime._get_custom_context_kwargs({'a': 1}) == {} |
| 32 | + assert runtime._get_custom_context_kwargs({"a": 1}) == {} |
32 | 33 | finally: |
33 | | - monkeypatch.setattr(runtime, 'IS_GQL_33', True) |
| 34 | + monkeypatch.setattr(runtime, "IS_GQL_33", True) |
34 | 35 |
|
35 | 36 |
|
36 | 37 | def test_get_operation_type_multiple_operations(): |
37 | | - doc = parse('query A{hello} query B{hello}') |
| 38 | + doc = parse("query A{hello} query B{hello}") |
38 | 39 | with pytest.raises(Exception): |
39 | 40 | runtime._get_operation_type(doc) |
40 | 41 |
|
41 | 42 |
|
42 | 43 | def test_parse_and_validate_document_node(): |
43 | | - doc = parse('query Q { hello }') |
| 44 | + doc = parse("query Q { hello }") |
44 | 45 | res = runtime._parse_and_validate(schema, doc, None) |
45 | 46 | assert res == doc |
46 | 47 |
|
47 | 48 |
|
48 | 49 | def test_introspect_success_and_failure(monkeypatch): |
49 | 50 | data = runtime.introspect(schema) |
50 | | - assert '__schema' in data |
| 51 | + assert "__schema" in data |
51 | 52 |
|
52 | 53 | def fake_execute_sync(schema, query): |
53 | | - return ExecutionResult(data=None, errors=[GraphQLError('boom')]) |
| 54 | + return ExecutionResult(data=None, errors=[GraphQLError("boom")]) |
54 | 55 |
|
55 | | - monkeypatch.setattr(runtime, 'execute_sync', fake_execute_sync) |
| 56 | + monkeypatch.setattr(runtime, "execute_sync", fake_execute_sync) |
56 | 57 | with pytest.raises(ValueError): |
57 | 58 | runtime.introspect(schema) |
0 commit comments