Fix query transformation regarding special operators
This commit is contained in:
@@ -344,6 +344,36 @@ class TestTransform(unittest.TestCase):
|
||||
)
|
||||
assert update == {"$pull": {"content.text": {"word": {"$nin": ["foo", "bar"]}}}}
|
||||
|
||||
def test_transform_embedded_document_list_fields(self):
|
||||
"""
|
||||
Test added to check filtering
|
||||
EmbeddedDocumentListField which is inside a EmbeddedDocumentField
|
||||
"""
|
||||
|
||||
class Drink(EmbeddedDocument):
|
||||
id = StringField()
|
||||
meta = {
|
||||
'strict': False
|
||||
}
|
||||
|
||||
class Shop(Document):
|
||||
drinks = EmbeddedDocumentListField(Drink)
|
||||
|
||||
Shop.drop_collection()
|
||||
drinks = [Drink(id='drink_1'), Drink(id='drink_2')]
|
||||
Shop.objects.create(drinks=drinks)
|
||||
q_obj = transform.query(
|
||||
Shop,
|
||||
drinks__all=[{'$elemMatch': {'_id': x.id}} for x in drinks]
|
||||
)
|
||||
assert q_obj == {
|
||||
'drinks': {
|
||||
'$all': [{'$elemMatch': {'_id': x.id}} for x in drinks]
|
||||
}
|
||||
}
|
||||
|
||||
Shop.drop_collection()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user