Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support PointField #58

Merged
merged 2 commits into from Nov 16, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions graphene_mongo/converter.py
Expand Up @@ -60,6 +60,7 @@ def convert_field_to_float(field, registry=None):

@convert_mongoengine_field.register(mongoengine.DictField)
@convert_mongoengine_field.register(mongoengine.MapField)
@convert_mongoengine_field.register(mongoengine.PointField)
def convert_dict_to_jsonstring(field, registry=None):
return JSONString(description=field.db_field, required=field.required)

Expand Down
10 changes: 2 additions & 8 deletions graphene_mongo/tests/models.py
Expand Up @@ -5,7 +5,7 @@
from mongoengine.fields import (
DateTimeField, EmailField, EmbeddedDocumentField,
FloatField, EmbeddedDocumentListField, ListField,
MapField, ReferenceField, StringField
MapField, PointField, ReferenceField, StringField
)

connect('graphene-mongo-test', host='mongomock://localhost', alias='default')
Expand All @@ -20,13 +20,6 @@ class Editor(Document):
metadata = MapField(field=StringField())


class Pet(Document):

meta = {'collection': 'test_pet'}
name = StringField(max_length=16, required=True)
reporter_id = StringField()


class Article(Document):

meta = {'collection': 'test_article'}
Expand Down Expand Up @@ -82,6 +75,7 @@ class Child(Parent):

meta = {'collection': 'test_child'}
baz = StringField()
loc = PointField()


class ProfessorMetadata(EmbeddedDocument):
Expand Down
4 changes: 2 additions & 2 deletions graphene_mongo/tests/setup.py
Expand Up @@ -5,7 +5,7 @@
Article, Editor, EmbeddedArticle, Player,
Reporter, Child, ProfessorMetadata, ProfessorVector,
ChildRegisteredBefore, ChildRegisteredAfter,
ParentWithRelationship
ParentWithRelationship,
)


Expand Down Expand Up @@ -95,7 +95,7 @@ def fixtures():
child1 = Child(bar='BAR', baz='BAZ')
child1.save()

child2 = Child(bar='bar', baz='baz')
child2 = Child(bar='bar', baz='baz', loc=[10, 20])
child2.save()

ProfessorVector.drop_collection()
Expand Down
6 changes: 5 additions & 1 deletion graphene_mongo/tests/test_converter.py
Expand Up @@ -78,10 +78,14 @@ def test_should_dict_convert_json():
assert_conversion(mongoengine.DictField, graphene.JSONString)


def test_should_convert_map_to_json():
def test_should_map_convertjson():
assert_conversion(mongoengine.MapField, graphene.JSONString, field=mongoengine.StringField())


def test_should_point_convert_json():
assert_conversion(mongoengine.PointField, graphene.JSONString)


def test_should_field_convert_list():
assert_conversion(mongoengine.ListField, graphene.List, field=mongoengine.StringField())

Expand Down
11 changes: 10 additions & 1 deletion graphene_mongo/tests/test_relay_query.py
Expand Up @@ -300,7 +300,8 @@ class Query(graphene.ObjectType):
edges {
node {
bar,
baz
baz,
loc
}
}
}
Expand All @@ -318,11 +319,19 @@ class Query(graphene.ObjectType):
]
}
}
loc = {
'type': 'Point',
'coordinates': [10, 20]
}
loc_json_string = json.dumps(loc, sort_keys=True)
schema = graphene.Schema(query=Query)

result = schema.execute(query)
result_loc = json.loads(result.data['children']['edges'][0]['node'].pop('loc'))
assert not result.errors
assert json.dumps(result.data, sort_keys=True) == json.dumps(
expected, sort_keys=True)
assert json.dumps(result_loc, sort_keys=True) == loc_json_string


def test_should_get_node_by_id(fixtures):
Expand Down