Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Point deserialize from string coordinates #10

Merged
merged 3 commits into from
Jun 17, 2016
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
2 changes: 1 addition & 1 deletion marshmallow_mongoengine/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def _deserialize(self, value, attr, data):
try:
return dict(
type='Point',
coordinates=[value['x'], value['y']]
coordinates=[float(value['x']), float(value['y'])]
)
except:
raise ValidationError('invalid Point `%s`' % value)
Expand Down
13 changes: 12 additions & 1 deletion tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,15 @@ class Meta:
dump = DocSchema().dump(doc)
assert not dump.errors
assert dump.data['point'] == { 'x': 10, 'y': 20 }

load = DocSchema().load(dump.data)
assert not load.errors
assert load.data.point == { 'type': 'Point', 'coordinates': [10, 20] }
# Deserialize Point with coordinates passed as string
data = {'point': { 'x': '10', 'y': '20' }}
load = DocSchema().load(data)
assert not load.errors
assert load.data.point == { 'type': 'Point', 'coordinates': [10, 20] }
# Try to load invalid coordinates
data = {'point': { 'x': '10', 'y': '20foo' }}
load = DocSchema().load(data)
assert 'point' in load.errors