Skip to content

Commit 828c8ab

Browse files
committed
Bring enum tests up to spec
1 parent b3a6bd0 commit 828c8ab

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

graphql/type/tests/test_enum_type.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from collections import OrderedDict
22

33
from rx import Observable
4-
from pytest import raises
54

65
from graphql import graphql
76
from graphql.type import (GraphQLArgument, GraphQLEnumType, GraphQLEnumValue,
@@ -114,13 +113,28 @@ def test_does_not_accept_string_literals():
114113
'Expected type "Color", found "GREEN".'
115114

116115

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
117131
def test_does_not_accept_incorrect_internal_value():
118132
result = graphql(Schema, '{ colorEnum(fromString: "GREEN") }')
119133
assert result.data == {'colorEnum': None}
120-
assert not result.errors
134+
assert result.errors[0].messages == ''
121135

122136

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():
124138
result = graphql(Schema, '{ colorEnum(fromEnum: 1) }')
125139
assert not result.data
126140
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():
135149

136150

137151
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+
)
140157
assert not result.errors
141158
assert result.data == {'colorEnum': 'BLUE'}
142159

0 commit comments

Comments
 (0)