Skip to content

Commit

Permalink
Merge pull request MongoEngine#1 from thedrow/patch-1
Browse files Browse the repository at this point in the history
Added a test that verifies distinct operations on nested embedded docume...
  • Loading branch information
MRigal committed Dec 3, 2014
2 parents 531fa30 + e5a636a commit d58f3b7
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions tests/queryset/queryset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2879,9 +2879,12 @@ class Book(Document):
self.assertEqual(authors, [mark_twain, john_tolkien])

def test_distinct_ListField_EmbeddedDocumentField_EmbeddedDocumentField(self):

class Continent(EmbeddedDocument):
continent_name = StringField()

class Country(EmbeddedDocument):
country_name = StringField()
continent = EmbeddedDocumentField(Continent)

class Author(EmbeddedDocument):
name = StringField()
Expand All @@ -2893,8 +2896,11 @@ class Book(Document):

Book.drop_collection()

scotland = Country(country_name="Scotland")
tibet = Country(country_name="Tibet")
europe = Continent(continent_name='europe')
asia = Continent(continent_name='asia')

scotland = Country(country_name="Scotland", continent=europe)
tibet = Country(country_name="Tibet", continent=asia)

mark_twain = Author(name="Mark Twain", country=scotland)
john_tolkien = Author(name="John Ronald Reuel Tolkien", country=tibet)
Expand All @@ -2907,6 +2913,10 @@ class Book(Document):
country_list = Book.objects.distinct("authors.country")

self.assertEqual(country_list, [scotland, tibet])

continent_list = Book.objects.distinct("authors.country.continent")

self.assertEqual(continent_list, [asia, europe])

def test_distinct_ListField_ReferenceField(self):
class Foo(Document):
Expand Down

0 comments on commit d58f3b7

Please sign in to comment.