Skip to content

Commit 5603eb9

Browse files
committed
TST: Ported tests from KnownArgumentNames.js
Ported from graphql/graphql-js/src/validation/__tests__/KnownArgumentNames.js, these tests are currently failing as of this commit. Tests are currently failing because the ``message`` method has not yet been implemented in :class:`KnownArgumentNames` and :class:`KnownDirectives`. Partial to #6
1 parent f1cd056 commit 5603eb9

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
from graphql.core.language.location import SourceLocation
2+
from graphql.core.validation.rules import KnownArgumentNames, KnownDirectives
3+
from utils import expect_passes_rule, expect_fails_rule
4+
5+
6+
def unknown_arg(arg_name, field_name, type_name, line, column):
7+
return {
8+
'message': KnownArgumentNames.message(arg_name, field_name, type_name),
9+
'locations': [SourceLocation(line, column)]
10+
}
11+
12+
13+
def unknown_directive_arg(arg_name, directive_name, line, column):
14+
return {
15+
'message': KnownDirectives.message(arg_name, directive_name),
16+
'locations': [SourceLocation(line, column)]
17+
}
18+
19+
20+
def test_single_arg_is_known():
21+
expect_passes_rule(KnownArgumentNames, '''
22+
fragment argOnRequiredArg on Dog {
23+
doesKnowCommand(dogCommand: SIT)
24+
}
25+
''')
26+
27+
28+
def test_multiple_args_are_known():
29+
expect_passes_rule(KnownArgumentNames, '''
30+
fragment multipleArgs on ComplicatedArgs {
31+
multipleReqs(req1: 1, req2: 2)
32+
}
33+
''')
34+
35+
36+
def test_ignore_args_of_unknown_fields():
37+
expect_passes_rule(KnownArgumentNames, '''
38+
fragment argOnUnknownField on Dog {
39+
unknownField(unknownArg: SIT)
40+
}
41+
''')
42+
43+
44+
def test_multiple_args_in_reverse_order_are_known():
45+
expect_passes_rule(KnownArgumentNames, '''
46+
fragment multipleArgsReverseOrder on ComplicatedArgs {
47+
multipleReqs(req2: 2, req1: 1)
48+
}
49+
''')
50+
51+
52+
def test_no_args_on_optional_arg():
53+
expect_passes_rule(KnownArgumentNames, '''
54+
fragment noArgOnOptionalArg on Dog {
55+
isHousetrained
56+
}
57+
''')
58+
59+
60+
def test_args_are_known_deeply():
61+
expect_passes_rule(KnownArgumentNames, '''
62+
{
63+
dog {
64+
doesKnowCommand(dogCommand: SIT)
65+
}
66+
human {
67+
pet {
68+
... on Dog {
69+
doesKnowCommand(dogCommand: SIT)
70+
}
71+
}
72+
}
73+
}
74+
''')
75+
76+
77+
def test_directive_args_are_known():
78+
expect_passes_rule(KnownArgumentNames, '''
79+
{
80+
dog @skip(if: true)
81+
}
82+
''')
83+
84+
85+
def test_undirective_args_are_invalid():
86+
expect_fails_rule(KnownArgumentNames, '''
87+
{
88+
dog @skip(unless: true)
89+
}
90+
''', [unknown_directive_arg('unless', 'skip', 3, 19)])
91+
92+
93+
def test_invalid_arg_name():
94+
expect_fails_rule(KnownArgumentNames, '''
95+
fragment invalidArgName on Dog {
96+
doesKnowCommand(unknown: true)
97+
}
98+
''', [unknown_arg('unknown', 'doesKnowCommand', 'Dog', 3, 25)])
99+
100+
101+
def test_unknown_args_amongst_known_args():
102+
expect_fails_rule(KnownArgumentNames, '''
103+
fragment oneGoodArgOneInvalidArg on Dog {
104+
doesKnowCommand(whoknows: 1, dogCommand: SIT, unknown: true)
105+
}
106+
''', [unknown_arg('whoknows', 'doesKnowCommand', 'Dog', 3, 25),
107+
unknown_arg('unknown', 'doesKnowCommand', 'Dog', 3, 55)])
108+
109+
110+
def test_unknown_args_deeply():
111+
expect_fails_rule(KnownArgumentNames, '''
112+
{
113+
dog {
114+
doesKnowCommand(unknown: true)
115+
}
116+
human {
117+
pet {
118+
... on Dog {
119+
doesKnowCommand(unknown: true)
120+
}
121+
}
122+
}
123+
}
124+
''', [unknown_arg('unknown', 'doesKnowCommand', 'Dog', 4, 27),
125+
unknown_arg('unknown', 'doesKnowCommand', 'Dog', 9, 31)])

0 commit comments

Comments
 (0)