Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 64 additions & 2 deletions graphene_mongo/tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from graphene.relay import Node

from .models import Article, Editor, EmbeddedArticle, Reporter
from .utils import with_local_registry
from ..fields import MongoengineConnectionField
from ..types import MongoengineObjectType

Expand All @@ -27,6 +28,7 @@ def setup_fixtures():
setup_fixtures()


@with_local_registry
def test_should_query_editor_well():
class EditorType(MongoengineObjectType):
class Meta:
Expand Down Expand Up @@ -73,6 +75,7 @@ def resolve_editors(self, *args, **kwargs):
assert all(item in result.data['editors'] for item in expected['editors'])


@with_local_registry
def test_should_query_reporter_well():
class ArticleType(MongoengineObjectType):
class Meta:
Expand Down Expand Up @@ -119,13 +122,17 @@ def resolve_reporter(self, *args, **kwargs):
assert not result.errors
assert dict(result.data['reporter']) == expected['reporter']


@with_local_registry
def test_should_node():
class ArticleNode(MongoengineObjectType):

class Meta:
model = Article
interfaces = (Node,)

class ReporterNode(MongoengineObjectType):

class Meta:
model = Reporter
interfaces = (Node,)
Expand Down Expand Up @@ -180,6 +187,8 @@ def resolve_reporter(self, *args, **kwargs):
assert not result.errors
assert dict(result.data['reporter']) == expected['reporter']


@with_local_registry
def test_should_connection_field():
class EditorNode(MongoengineObjectType):

Expand Down Expand Up @@ -226,9 +235,62 @@ class Query(graphene.ObjectType):
assert not result.errors
assert dict(result.data['allEditors']) == expected['allEditors']

# TODO:

@with_local_registry
def test_should_mutate_well():
pass
class ArticleNode(MongoengineObjectType):

class Meta:
model = Article
interfaces = (Node,)


class CreateArticle(graphene.Mutation):

class Arguments:
headline = graphene.String()

article = graphene.Field(ArticleNode)

def mutate(self, info, headline):
article = Article(
headline=headline
)
article.save()

return CreateArticle(article=article)


class Query(graphene.ObjectType):
node = Node.Field()


class Mutation(graphene.ObjectType):

create_article = CreateArticle.Field()

query = '''
mutation ArticleCreator {
createArticle(
headline: "My Article"
) {
article {
headline
}
}
}
'''
expected = {
'createArticle': {
'article': {
'headline': 'My Article'
}
}
}
schema = graphene.Schema(query=Query, mutation=Mutation)
result = schema.execute(query)
assert not result.errors
assert result.data == expected

# TODO:
def test_should_filter():
Expand Down
16 changes: 1 addition & 15 deletions graphene_mongo/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from ..types import MongoengineObjectType
from .models import Article
from .models import Reporter
from .utils import with_local_registry

registry.reset_global_registry()

Expand Down Expand Up @@ -80,21 +81,6 @@ class Meta:
assert 'valid Mongoengine Model' in str(excinfo.value)


def with_local_registry(func):
def inner(*args, **kwargs):
old = registry.get_global_registry()
registry.reset_global_registry()
try:
retval = func(*args, **kwargs)
except Exception as e:
registry.registry = old
raise e
else:
registry.registry = old
return retval
return inner


@with_local_registry
def test_mongoengine_objecttype_only_fields():
class A(MongoengineObjectType):
Expand Down
17 changes: 17 additions & 0 deletions graphene_mongo/tests/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from .. import registry


def with_local_registry(func):
def inner(*args, **kwargs):
old = registry.get_global_registry()
registry.reset_global_registry()
try:
retval = func(*args, **kwargs)
except Exception as e:
registry.registry = old
raise e
else:
registry.registry = old
return retval
return inner