1
1
from collections import OrderedDict
2
2
3
3
from rx import Observable
4
- from pytest import raises
5
4
6
5
from graphql import graphql
7
6
from graphql .type import (GraphQLArgument , GraphQLEnumType , GraphQLEnumValue ,
@@ -114,13 +113,28 @@ def test_does_not_accept_string_literals():
114
113
'Expected type "Color", found "GREEN".'
115
114
116
115
116
+ def test_does_not_accept_values_not_in_the_enum ():
117
+ result = graphql (Schema , '{ colorEnum(fromEnum: GREENISH) }' )
118
+ assert not result .data
119
+ assert result .errors [0 ].message == 'Argument "fromEnum" has invalid value GREENISH.\n ' \
120
+ 'Expected type "Color", found GREENISH.'
121
+
122
+
123
+ def test_does_not_accept_values_with_incorrect_casing ():
124
+ result = graphql (Schema , '{ colorEnum(fromEnum: green) }' )
125
+ assert not result .data
126
+ assert result .errors [0 ].message == 'Argument "fromEnum" has invalid value green.\n ' \
127
+ 'Expected type "Color", found green.'
128
+
129
+
130
+ # TODO
117
131
def test_does_not_accept_incorrect_internal_value ():
118
132
result = graphql (Schema , '{ colorEnum(fromString: "GREEN") }' )
119
133
assert result .data == {'colorEnum' : None }
120
- assert not result .errors
134
+ assert result .errors [ 0 ]. messages == ''
121
135
122
136
123
- def test_does_not_accept_internal_value_in_placeof_enum_literal ():
137
+ def test_does_not_accept_internal_value_in_place_of_enum_literal ():
124
138
result = graphql (Schema , '{ colorEnum(fromEnum: 1) }' )
125
139
assert not result .data
126
140
assert result .errors [0 ].message == 'Argument "fromEnum" has invalid value 1.\n ' \
@@ -135,8 +149,11 @@ def test_does_not_accept_enum_literal_in_place_of_int():
135
149
136
150
137
151
def test_accepts_json_string_as_enum_variable ():
138
- result = graphql (Schema , 'query test($color: Color!) { colorEnum(fromEnum: $color) }' , variable_values = {
139
- 'color' : 'BLUE' })
152
+ result = graphql (
153
+ Schema ,
154
+ 'query test($color: Color!) { colorEnum(fromEnum: $color) }' ,
155
+ variable_values = {'color' : 'BLUE' }
156
+ )
140
157
assert not result .errors
141
158
assert result .data == {'colorEnum' : 'BLUE' }
142
159
0 commit comments