Skip to content

Instantly share code, notes, and snippets.

@tudormunteanu
Created August 7, 2020 12:15
Show Gist options
  • Save tudormunteanu/2e33b78b34061fdb8b48336200190744 to your computer and use it in GitHub Desktop.
Save tudormunteanu/2e33b78b34061fdb8b48336200190744 to your computer and use it in GitHub Desktop.
Graphene Enums vs Python Enums
_________________________________________________________________________________ test_enum _________________________________________________________________________________
def test_enum():
client = Client(schema)
executed = client.execute(
"""
{
episode
}
"""
)
assert EpisodeSource.NEW_HOPE.value == "NEW HOPE"
> assert executed == {
"data": {
"episode": "NEW HOPE",
}
}
E AssertionError: assert {'data': {'ep...: 'NEW_HOPE'}} == {'data': {'ep...: 'NEW HOPE'}}
E Differing items:
E {'data': {'episode': 'NEW_HOPE'}} != {'data': {'episode': 'NEW HOPE'}}
E Use -v to get the full diff
test_graphene.py:40: AssertionError
aniso8601==7.0.0
attrs==19.3.0
graphene==2.1.8
graphql-core==2.3.2
graphql-relay==2.0.1
importlib-metadata==1.7.0
iniconfig==1.0.1
more-itertools==8.4.0
packaging==20.4
pluggy==0.13.1
promise==2.3
py==1.9.0
pyparsing==2.4.7
pytest==6.0.1
Rx==1.6.1
six==1.15.0
toml==0.10.1
zipp==3.1.0
import enum
import graphene
from graphene import ObjectType, Schema, Field
from graphene.test import Client
class EpisodeSource(enum.Enum):
NEW_HOPE = "NEW HOPE"
EMPIRE = "EMPIRE STRIKES BACK"
JEDI = "THE JEDI RETURNS"
Episode = graphene.Enum.from_enum(EpisodeSource)
class Query(ObjectType):
episode = Field(Episode)
def resolve_episode(root, info):
return Episode.NEW_HOPE
schema = Schema(query=Query)
def test_enum():
client = Client(schema)
executed = client.execute(
"""
{
episode
}
"""
)
assert EpisodeSource.NEW_HOPE.value == "NEW HOPE"
assert executed == {
"data": {
"episode": "NEW HOPE",
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment