1
+ from graphql .core .language .location import SourceLocation
2
+ from graphql .core .validation .rules import UniqueArgumentNames
3
+ from utils import expect_passes_rule , expect_fails_rule
4
+
5
+
6
+ def duplicate_arg (arg_name , l1 , c1 , l2 , c2 ):
7
+ return {
8
+ 'message' : UniqueArgumentNames .duplicate_arg_message (arg_name ),
9
+ 'locations' : [SourceLocation (l1 , c1 ), SourceLocation (l2 , c2 )]
10
+ }
11
+
12
+
13
+ def test_no_arguments_on_field ():
14
+ expect_passes_rule (UniqueArgumentNames , '''
15
+ {
16
+ field
17
+ }
18
+ ''' )
19
+
20
+
21
+ def test_no_arguments_on_directive ():
22
+ expect_passes_rule (UniqueArgumentNames , '''
23
+ {
24
+ field
25
+ }
26
+ ''' )
27
+
28
+
29
+ def test_argument_on_field ():
30
+ expect_passes_rule (UniqueArgumentNames , '''
31
+ {
32
+ field(arg: "value")
33
+ }
34
+ ''' )
35
+
36
+
37
+ def test_argument_on_directive ():
38
+ expect_passes_rule (UniqueArgumentNames , '''
39
+ {
40
+ field @directive(arg: "value")
41
+ }
42
+ ''' )
43
+
44
+ def test_same_field_two_arguments ():
45
+ expect_passes_rule (UniqueArgumentNames , '''
46
+ {
47
+ one: field(arg: "value")
48
+ two: field(arg: "value")
49
+ }
50
+ ''' )
51
+
52
+ def test_same_argument_on_field_and_directive ():
53
+ expect_passes_rule (UniqueArgumentNames , '''
54
+ {
55
+ field(arg: "value") @directive(arg: "value")
56
+ }
57
+ ''' )
58
+ def test_same_argument_two_directives ():
59
+ expect_passes_rule (UniqueArgumentNames , '''
60
+ {
61
+ field @directive1(arg: "value") @directive2(arg: "value")
62
+ }
63
+ ''' )
64
+
65
+ def test_multiple_field_arguments ():
66
+ expect_passes_rule (UniqueArgumentNames , '''
67
+ {
68
+ field(arg1: "value", arg2: "value", arg3: "value")
69
+ }
70
+ ''' )
71
+
72
+ def test_multiple_directive_arguments ():
73
+ expect_passes_rule (UniqueArgumentNames , '''
74
+ {
75
+ field @directive(arg1: "value", arg2: "value", arg3: "value")
76
+ }
77
+ ''' )
78
+
79
+ def test_duplicate_field_arguments ():
80
+ expect_fails_rule (UniqueArgumentNames , '''
81
+ {
82
+ field(arg1: "value", arg1: "value")
83
+ }
84
+ ''' , [duplicate_arg ('arg1' , 3 , 13 , 3 , 28 )]
85
+ )
86
+
87
+ def test_many_duplicate_field_arguments ():
88
+ expect_fails_rule (UniqueArgumentNames , '''
89
+ {
90
+ field(arg1: "value", arg1: "value", arg1: "value")
91
+ }
92
+ ''' , [
93
+ duplicate_arg ('arg1' , 3 , 13 , 3 , 28 ),
94
+ duplicate_arg ('arg1' , 3 , 13 , 3 , 43 )
95
+ ])
96
+
97
+ def test_duplicate_directive_arguments ():
98
+ expect_fails_rule (UniqueArgumentNames , '''
99
+ {
100
+ field @directive(arg1: "value", arg1: "value")
101
+ }
102
+ ''' , [duplicate_arg ('arg1' , 3 , 24 , 3 , 39 )]
103
+ )
104
+
105
+ def test_many_duplicate_directive_arguments ():
106
+ expect_fails_rule (UniqueArgumentNames , '''
107
+ {
108
+ field @directive(arg1: "value", arg1: "value", arg1: "value")
109
+ }
110
+ ''' ,[
111
+ duplicate_arg ('arg1' , 3 , 24 , 3 , 39 ),
112
+ duplicate_arg ('arg1' , 3 , 24 , 3 , 54 )
113
+ ])
0 commit comments