Skip to content

Commit d1c04e7

Browse files
committed
Merge pull request #40 from jhgg/master
More clean-ups
2 parents 006a76f + dd21198 commit d1c04e7

11 files changed

+155
-73
lines changed

tests/core_validation/test_fields_on_correct_type.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from utils import expect_passes_rule, expect_fails_rule
44

55

6-
def error(field, type, line, column):
6+
def undefined_field(field, type, line, column):
77
return {
88
'message': FieldsOnCorrectType.undefined_field_message(field, type),
99
'locations': [SourceLocation(line, column)]
@@ -66,7 +66,9 @@ def test_field_not_defined_on_fragment():
6666
fragment fieldNotDefined on Dog {
6767
meowVolume
6868
}
69-
''', [error('meowVolume', 'Dog', 3, 9)])
69+
''', [
70+
undefined_field('meowVolume', 'Dog', 3, 9)
71+
])
7072

7173

7274
def test_field_not_defined_deeply_only_reports_first():
@@ -76,7 +78,9 @@ def test_field_not_defined_deeply_only_reports_first():
7678
deeper_unknown_field
7779
}
7880
}
79-
''', [error('unknown_field', 'Dog', 3, 9)])
81+
''', [
82+
undefined_field('unknown_field', 'Dog', 3, 9)
83+
])
8084

8185

8286
def test_sub_field_not_defined():
@@ -86,7 +90,9 @@ def test_sub_field_not_defined():
8690
unknown_field
8791
}
8892
}
89-
''', [error('unknown_field', 'Pet', 4, 11)])
93+
''', [
94+
undefined_field('unknown_field', 'Pet', 4, 11)
95+
])
9096

9197

9298
def test_field_not_defined_on_inline_fragment():
@@ -96,39 +102,49 @@ def test_field_not_defined_on_inline_fragment():
96102
meowVolume
97103
}
98104
}
99-
''', [error('meowVolume', 'Dog', 4, 11)])
105+
''', [
106+
undefined_field('meowVolume', 'Dog', 4, 11)
107+
])
100108

101109

102110
def test_aliased_field_target_not_defined():
103111
expect_fails_rule(FieldsOnCorrectType, '''
104112
fragment aliasedFieldTargetNotDefined on Dog {
105113
volume : mooVolume
106114
}
107-
''', [error('mooVolume', 'Dog', 3, 9)])
115+
''', [
116+
undefined_field('mooVolume', 'Dog', 3, 9)
117+
])
108118

109119

110120
def test_aliased_lying_field_target_not_defined():
111121
expect_fails_rule(FieldsOnCorrectType, '''
112122
fragment aliasedLyingFieldTargetNotDefined on Dog {
113123
barkVolume : kawVolume
114124
}
115-
''', [error('kawVolume', 'Dog', 3, 9)])
125+
''', [
126+
undefined_field('kawVolume', 'Dog', 3, 9)
127+
])
116128

117129

118130
def test_not_defined_on_interface():
119131
expect_fails_rule(FieldsOnCorrectType, '''
120132
fragment notDefinedOnInterface on Pet {
121133
tailLength
122134
}
123-
''', [error('tailLength', 'Pet', 3, 9)])
135+
''', [
136+
undefined_field('tailLength', 'Pet', 3, 9)
137+
])
124138

125139

126140
def test_defined_on_implementors_but_not_on_interface():
127141
expect_fails_rule(FieldsOnCorrectType, '''
128142
fragment definedOnImplementorsButNotInterface on Pet {
129143
nickname
130144
}
131-
''', [error('nickname', 'Pet', 3, 9)])
145+
''', [
146+
undefined_field('nickname', 'Pet', 3, 9)
147+
])
132148

133149

134150
def test_meta_field_selection_on_union():
@@ -144,15 +160,19 @@ def test_direct_field_selection_on_union():
144160
fragment directFieldSelectionOnUnion on CatOrDog {
145161
directField
146162
}
147-
''', [error('directField', 'CatOrDog', 3, 9)])
163+
''', [
164+
undefined_field('directField', 'CatOrDog', 3, 9)
165+
])
148166

149167

150168
def test_defined_on_implementors_queried_on_union():
151169
expect_fails_rule(FieldsOnCorrectType, '''
152170
fragment definedOnImplementorsQueriedOnUnion on CatOrDog {
153171
name
154172
}
155-
''', [error('name', 'CatOrDog', 3, 9)])
173+
''', [
174+
undefined_field('name', 'CatOrDog', 3, 9)
175+
])
156176

157177

158178
def test_valid_field_in_inline_fragment():

tests/core_validation/test_fragments_on_composite_types.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@
33
from utils import expect_passes_rule, expect_fails_rule
44

55

6-
def error(frag_name, type_name, line, column):
6+
def fragment_on_non_composite_error(frag_name, type_name, line, column):
77
return {
88
'message': FragmentsOnCompositeTypes.fragment_on_non_composite_error_message(frag_name, type_name),
99
'locations': [SourceLocation(line, column)]
1010
}
1111

1212

13+
def inline_fragment_on_non_composite_error(type_name, line, column):
14+
return {
15+
'message': FragmentsOnCompositeTypes.inline_fragment_on_non_composite_error_message(type_name),
16+
'locations': [SourceLocation(line, column)]
17+
}
18+
19+
1320
def test_object_is_valid_fragment_type():
1421
expect_passes_rule(FragmentsOnCompositeTypes, '''
1522
fragment validFragment on Dog {
@@ -49,23 +56,29 @@ def test_scalar_is_invalid_fragment_type():
4956
fragment scalarFragment on Boolean {
5057
bad
5158
}
52-
''', [error('scalarFragment', 'Boolean', 2, 34)])
59+
''', [
60+
fragment_on_non_composite_error('scalarFragment', 'Boolean', 2, 34)
61+
])
5362

5463

5564
def test_enum_is_invalid_fragment_type():
5665
expect_fails_rule(FragmentsOnCompositeTypes, '''
5766
fragment scalarFragment on FurColor {
5867
bad
5968
}
60-
''', [error('scalarFragment', 'FurColor', 2, 34)])
69+
''', [
70+
fragment_on_non_composite_error('scalarFragment', 'FurColor', 2, 34)
71+
])
6172

6273

6374
def test_input_object_is_invalid_fragment_type():
6475
expect_fails_rule(FragmentsOnCompositeTypes, '''
6576
fragment inputFragment on ComplexInput {
6677
stringField
6778
}
68-
''', [error('inputFragment', 'ComplexInput', 2, 33)])
79+
''', [
80+
fragment_on_non_composite_error('inputFragment', 'ComplexInput', 2, 33)
81+
])
6982

7083

7184
def test_scalar_is_invalid_inline_fragment_type():
@@ -75,7 +88,6 @@ def test_scalar_is_invalid_inline_fragment_type():
7588
barks
7689
}
7790
}
78-
''', [{
79-
'message': FragmentsOnCompositeTypes.inline_fragment_on_non_composite_error_message('String'),
80-
'locations': [SourceLocation(3, 16)]
81-
}])
91+
''', [
92+
inline_fragment_on_non_composite_error('String', 3, 16)
93+
])

tests/core_validation/test_known_argument_names.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ def unknown_arg(arg_name, field_name, type_name, line, column):
1212

1313
def unknown_directive_arg(arg_name, directive_name, line, column):
1414
return {
15-
'message': KnownArgumentNames.unknown_directive_arg_message(
16-
arg_name, directive_name),
15+
'message': KnownArgumentNames.unknown_directive_arg_message(arg_name, directive_name),
1716
'locations': [SourceLocation(line, column)]
1817
}
1918

@@ -88,24 +87,30 @@ def test_undirective_args_are_invalid():
8887
{
8988
dog @skip(unless: true)
9089
}
91-
''', [unknown_directive_arg('unless', 'skip', 3, 19)])
90+
''', [
91+
unknown_directive_arg('unless', 'skip', 3, 19)
92+
])
9293

9394

9495
def test_invalid_arg_name():
9596
expect_fails_rule(KnownArgumentNames, '''
9697
fragment invalidArgName on Dog {
9798
doesKnowCommand(unknown: true)
9899
}
99-
''', [unknown_arg('unknown', 'doesKnowCommand', 'Dog', 3, 25)])
100+
''', [
101+
unknown_arg('unknown', 'doesKnowCommand', 'Dog', 3, 25)
102+
])
100103

101104

102105
def test_unknown_args_amongst_known_args():
103106
expect_fails_rule(KnownArgumentNames, '''
104107
fragment oneGoodArgOneInvalidArg on Dog {
105108
doesKnowCommand(whoknows: 1, dogCommand: SIT, unknown: true)
106109
}
107-
''', [unknown_arg('whoknows', 'doesKnowCommand', 'Dog', 3, 25),
108-
unknown_arg('unknown', 'doesKnowCommand', 'Dog', 3, 55)])
110+
''', [
111+
unknown_arg('whoknows', 'doesKnowCommand', 'Dog', 3, 25),
112+
unknown_arg('unknown', 'doesKnowCommand', 'Dog', 3, 55)
113+
])
109114

110115

111116
def test_unknown_args_deeply():
@@ -122,5 +127,7 @@ def test_unknown_args_deeply():
122127
}
123128
}
124129
}
125-
''', [unknown_arg('unknown', 'doesKnowCommand', 'Dog', 4, 27),
126-
unknown_arg('unknown', 'doesKnowCommand', 'Dog', 9, 31)])
130+
''', [
131+
unknown_arg('unknown', 'doesKnowCommand', 'Dog', 4, 27),
132+
unknown_arg('unknown', 'doesKnowCommand', 'Dog', 9, 31)
133+
])

tests/core_validation/test_known_directives.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ def unknown_directive(directive_name, line, column):
1212

1313
def misplaced_directive(directive_name, placement, line, column):
1414
return {
15-
'message': KnownDirectives.misplaced_directive_message(directive_name,
16-
placement),
15+
'message': KnownDirectives.misplaced_directive_message(directive_name, placement),
1716
'locations': [SourceLocation(line, column)]
1817
}
1918

@@ -51,7 +50,9 @@ def test_with_unknown_directive():
5150
name
5251
}
5352
}
54-
''', [unknown_directive('unknown', 3, 13)])
53+
''', [
54+
unknown_directive('unknown', 3, 13)
55+
])
5556

5657

5758
def test_with_many_unknown_directives():
@@ -67,9 +68,11 @@ def test_with_many_unknown_directives():
6768
}
6869
}
6970
}
70-
''', [unknown_directive('unknown', 3, 13),
71-
unknown_directive('unknown', 6, 15),
72-
unknown_directive('unknown', 8, 16)])
71+
''', [
72+
unknown_directive('unknown', 3, 13),
73+
unknown_directive('unknown', 6, 15),
74+
unknown_directive('unknown', 8, 16)
75+
])
7376

7477

7578
def test_with_well_placed_directives():
@@ -89,4 +92,6 @@ def test_with_misplaced_directives():
8992
name
9093
...Frag
9194
}
92-
''', [misplaced_directive('include', 'operation', 2, 17)])
95+
''', [
96+
misplaced_directive('include', 'operation', 2, 17)
97+
])

tests/core_validation/test_known_fragment_names.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,4 @@ def test_unknown_fragment_names_are_invalid():
5151
undefined_fragment('UnknownFragment1', 4, 16),
5252
undefined_fragment('UnknownFragment2', 6, 20),
5353
undefined_fragment('UnknownFragment3', 12, 12),
54-
5554
])

tests/core_validation/test_lone_anonymous_operation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,6 @@ def test_anon_operation_with_another_operation():
7171
mutation Foo {
7272
fieldB
7373
}
74-
''', [anon_not_alone(2, 7)])
74+
''', [
75+
anon_not_alone(2, 7)
76+
])

tests/core_validation/test_scalar_leafs.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,19 @@ def test_object_type_missing_selection():
3030
query directQueryOnObjectWithoutSubFields {
3131
human
3232
}
33-
''', [missing_obj_subselection('human', 'Human', 3, 9)])
33+
''', [
34+
missing_obj_subselection('human', 'Human', 3, 9)
35+
])
3436

3537

3638
def test_interface_type_missing_selection():
3739
expect_fails_rule(ScalarLeafs, '''
3840
{
3941
human { pets }
4042
}
41-
''', [missing_obj_subselection('pets', '[Pet]', 3, 17)])
43+
''', [
44+
missing_obj_subselection('pets', '[Pet]', 3, 17)
45+
])
4246

4347

4448
def test_valid_scalar_selection_with_args():
@@ -54,36 +58,46 @@ def test_scalar_selection_not_allowed_on_boolean():
5458
fragment scalarSelectionsNotAllowedOnBoolean on Dog {
5559
barks { sinceWhen }
5660
}
57-
''', [no_scalar_subselection('barks', 'Boolean', 3, 15)])
61+
''', [
62+
no_scalar_subselection('barks', 'Boolean', 3, 15)
63+
])
5864

5965

6066
def test_scalar_selection_not_allowed_on_enum():
6167
expect_fails_rule(ScalarLeafs, '''
6268
fragment scalarSelectionsNotAllowedOnEnum on Cat {
6369
furColor { inHexdec }
6470
}
65-
''', [no_scalar_subselection('furColor', 'FurColor', 3, 18)])
71+
''', [
72+
no_scalar_subselection('furColor', 'FurColor', 3, 18)
73+
])
6674

6775

6876
def test_scalar_selection_not_allowed_with_args():
6977
expect_fails_rule(ScalarLeafs, '''
7078
fragment scalarSelectionsNotAllowedWithArgs on Dog {
7179
doesKnowCommand(dogCommand: SIT) { sinceWhen }
7280
}
73-
''', [no_scalar_subselection('doesKnowCommand', 'Boolean', 3, 42)])
81+
''', [
82+
no_scalar_subselection('doesKnowCommand', 'Boolean', 3, 42)
83+
])
7484

7585

7686
def test_scalar_selection_not_allowed_with_directives():
7787
expect_fails_rule(ScalarLeafs, '''
7888
fragment scalarSelectionsNotAllowedWithDirectives on Dog {
7989
name @include(if: true) { isAlsoHumanName }
8090
}
81-
''', [no_scalar_subselection('name', 'String', 3, 33)])
91+
''', [
92+
no_scalar_subselection('name', 'String', 3, 33)
93+
])
8294

8395

8496
def test_scalar_selection_not_allowed_with_directives_and_args():
8597
expect_fails_rule(ScalarLeafs, '''
8698
fragment scalarSelectionsNotAllowedWithDirectivesAndArgs on Dog {
8799
doesKnowCommand(dogCommand: SIT) @include(if: true) { sinceWhen }
88100
}
89-
''', [no_scalar_subselection('doesKnowCommand', 'Boolean', 3, 61)])
101+
''', [
102+
no_scalar_subselection('doesKnowCommand', 'Boolean', 3, 61)
103+
])

0 commit comments

Comments
 (0)