Skip to content

Commit

Permalink
Merge pull request #995 from seglberg/PR/952-squash
Browse files Browse the repository at this point in the history
Unit Test - Unique Multikey Index
  • Loading branch information
mmellison committed May 7, 2015
2 parents d6b2d8d + 73f0867 commit a443144
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/fields/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -3675,6 +3675,31 @@ def test_delete(self):
# deleted from the database
self.assertEqual(number, 2)

def test_empty_list_embedded_documents_with_unique_field(self):
"""
Tests that only one document with an empty list of embedded documents
that have a unique field can be saved, but if the unique field is
also sparse than multiple documents with an empty list can be saved.
"""
class EmbeddedWithUnique(EmbeddedDocument):
number = IntField(unique=True)

class A(Document):
my_list = ListField(EmbeddedDocumentField(EmbeddedWithUnique))

a1 = A(my_list=[]).save()
self.assertRaises(NotUniqueError, lambda: A(my_list=[]).save())

class EmbeddedWithSparseUnique(EmbeddedDocument):
number = IntField(unique=True, sparse=True)

class B(Document):
my_list = ListField(EmbeddedDocumentField(EmbeddedWithSparseUnique))

b1 = B(my_list=[]).save()
b2 = B(my_list=[]).save()


def test_filtered_delete(self):
"""
Tests the delete method of a List of Embedded Documents
Expand Down

0 comments on commit a443144

Please sign in to comment.