MCPcopy Create free account
hub / github.com/MongoEngine/mongoengine / _test_embedded

Method _test_embedded

tests/queryset/test_geo.py:278–308  ·  view source on GitHub ↗

Helper test method ensuring given point field class works well in an embedded document.

(self, point_field_class)

Source from the content-addressed store, hash-verified

276 assert event3 in events
277
278 def _test_embedded(self, point_field_class):
279 """Helper test method ensuring given point field class works
280 well in an embedded document.
281 """
282
283 class Venue(EmbeddedDocument):
284 location = point_field_class()
285 name = StringField()
286
287 class Event(Document):
288 title = StringField()
289 venue = EmbeddedDocumentField(Venue)
290
291 Event.drop_collection()
292
293 venue1 = Venue(name="The Rock", location=[-87.677137, 41.909889])
294 venue2 = Venue(name="The Bridge", location=[-122.4194155, 37.7749295])
295
296 event1 = Event(title="Coltrane Motion @ Double Door", venue=venue1).save()
297 event2 = Event(
298 title="Coltrane Motion @ Bottom of the Hill", venue=venue2
299 ).save()
300 event3 = Event(title="Coltrane Motion @ Empty Bottle", venue=venue1).save()
301
302 # find all events "near" pitchfork office, chicago.
303 # note that "near" will show the san francisco event, too,
304 # although it sorts to last.
305 events = Event.objects(venue__location__near=[-87.67892, 41.9120459])
306 if PYMONGO_VERSION < (4,):
307 assert events.count() == 3
308 assert list(events) == [event1, event3, event2]
309
310 def test_geo_spatial_embedded(self):
311 """Make sure GeoPointField works properly in an embedded document."""

Callers 2

Calls 6

drop_collectionMethod · 0.80
VenueClass · 0.70
EventClass · 0.70
saveMethod · 0.45
objectsMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected