Skip to content

Commit d8e817c

Browse files
committed
test_star_wars_introspection: cleanup + add explanation comment
Replicates graphql/graphql-js@d9f959e
1 parent ee84825 commit d8e817c

File tree

1 file changed

+57
-46
lines changed

1 file changed

+57
-46
lines changed

tests/test_star_wars_introspection.py

Lines changed: 57 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,30 @@
33
from .star_wars_schema import star_wars_schema
44

55

6+
def query_star_wars(source):
7+
result = graphql_sync(star_wars_schema, source)
8+
assert result.errors is None
9+
return result.data
10+
11+
612
def describe_star_wars_introspection_tests():
713
def describe_basic_introspection():
814
def allows_querying_the_schema_for_types():
9-
query = """
10-
query IntrospectionTypeQuery {
15+
data = query_star_wars(
16+
"""
17+
{
1118
__schema {
1219
types {
1320
name
1421
}
1522
}
1623
}
1724
"""
18-
expected = {
25+
)
26+
# Include all types used by StarWars schema, introspection types and
27+
# standard directives. For example, `Boolean` is used in `@skip`,
28+
# `@include` and also inside introspection types.
29+
assert data == {
1930
"__schema": {
2031
"types": [
2132
{"name": "Query"},
@@ -37,64 +48,63 @@ def allows_querying_the_schema_for_types():
3748
}
3849
}
3950

40-
result = graphql_sync(star_wars_schema, query)
41-
assert result == (expected, None)
42-
4351
def allows_querying_the_schema_for_query_type():
44-
query = """
45-
query IntrospectionQueryTypeQuery {
52+
data = query_star_wars(
53+
"""
54+
{
4655
__schema {
4756
queryType {
4857
name
4958
}
5059
}
5160
}
5261
"""
53-
expected = {"__schema": {"queryType": {"name": "Query"}}}
54-
result = graphql_sync(star_wars_schema, query)
55-
assert result == (expected, None)
62+
)
63+
64+
assert data == {"__schema": {"queryType": {"name": "Query"}}}
5665

5766
def allows_querying_the_schema_for_a_specific_type():
58-
query = """
59-
query IntrospectionDroidTypeQuery {
67+
data = query_star_wars(
68+
"""
69+
{
6070
__type(name: "Droid") {
6171
name
6272
}
6373
}
6474
"""
65-
expected = {"__type": {"name": "Droid"}}
66-
result = graphql_sync(star_wars_schema, query)
67-
assert result == (expected, None)
75+
)
76+
assert data == {"__type": {"name": "Droid"}}
6877

6978
def allows_querying_the_schema_for_an_object_kind():
70-
query = """
71-
query IntrospectionDroidKindQuery {
79+
data = query_star_wars(
80+
"""
81+
{
7282
__type(name: "Droid") {
7383
name
7484
kind
7585
}
7686
}
7787
"""
78-
expected = {"__type": {"name": "Droid", "kind": "OBJECT"}}
79-
result = graphql_sync(star_wars_schema, query)
80-
assert result == (expected, None)
88+
)
89+
assert data == {"__type": {"name": "Droid", "kind": "OBJECT"}}
8190

8291
def allows_querying_the_schema_for_an_interface_kind():
83-
query = """
84-
query IntrospectionCharacterKindQuery {
92+
data = query_star_wars(
93+
"""
94+
{
8595
__type(name: "Character") {
8696
name
8797
kind
8898
}
8999
}
90100
"""
91-
expected = {"__type": {"name": "Character", "kind": "INTERFACE"}}
92-
result = graphql_sync(star_wars_schema, query)
93-
assert result == (expected, None)
101+
)
102+
assert data == {"__type": {"name": "Character", "kind": "INTERFACE"}}
94103

95104
def allows_querying_the_schema_for_object_fields():
96-
query = """
97-
query IntrospectionDroidFieldsQuery {
105+
data = query_star_wars(
106+
"""
107+
{
98108
__type(name: "Droid") {
99109
name
100110
fields {
@@ -107,7 +117,8 @@ def allows_querying_the_schema_for_object_fields():
107117
}
108118
}
109119
"""
110-
expected = {
120+
)
121+
assert data == {
111122
"__type": {
112123
"name": "Droid",
113124
"fields": [
@@ -126,12 +137,11 @@ def allows_querying_the_schema_for_object_fields():
126137
],
127138
}
128139
}
129-
result = graphql_sync(star_wars_schema, query)
130-
assert result == (expected, None)
131140

132141
def allows_querying_the_schema_for_nested_object_fields():
133-
query = """
134-
query IntrospectionDroidNestedFieldsQuery {
142+
data = query_star_wars(
143+
"""
144+
{
135145
__type(name: "Droid") {
136146
name
137147
fields {
@@ -148,7 +158,8 @@ def allows_querying_the_schema_for_nested_object_fields():
148158
}
149159
}
150160
"""
151-
expected = {
161+
)
162+
assert data == {
152163
"__type": {
153164
"name": "Droid",
154165
"fields": [
@@ -203,12 +214,11 @@ def allows_querying_the_schema_for_nested_object_fields():
203214
],
204215
}
205216
}
206-
result = graphql_sync(star_wars_schema, query)
207-
assert result == (expected, None)
208217

209218
def allows_querying_the_schema_for_field_args():
210-
query = """
211-
query IntrospectionQueryTypeQuery {
219+
data = query_star_wars(
220+
"""
221+
{
212222
__schema {
213223
queryType {
214224
fields {
@@ -231,7 +241,9 @@ def allows_querying_the_schema_for_field_args():
231241
}
232242
}
233243
"""
234-
expected = {
244+
)
245+
246+
assert data == {
235247
"__schema": {
236248
"queryType": {
237249
"fields": [
@@ -292,23 +304,22 @@ def allows_querying_the_schema_for_field_args():
292304
}
293305
}
294306
}
295-
result = graphql_sync(star_wars_schema, query)
296-
assert result == (expected, None)
297307

298308
def allows_querying_the_schema_for_documentation():
299-
query = """
300-
query IntrospectionDroidDescriptionQuery {
309+
data = query_star_wars(
310+
"""
311+
{
301312
__type(name: "Droid") {
302313
name
303314
description
304315
}
305316
}
306317
"""
307-
expected = {
318+
)
319+
320+
assert data == {
308321
"__type": {
309322
"name": "Droid",
310323
"description": "A mechanical creature in the Star Wars universe.",
311324
}
312325
}
313-
result = graphql_sync(star_wars_schema, query)
314-
assert result == (expected, None)

0 commit comments

Comments
 (0)