test moved to another file, cosmetical fixes

This commit is contained in:
Eremeev Danil 2015-05-07 10:53:25 +05:00
parent dfa8eaf24e
commit aab0599280
4 changed files with 19 additions and 18 deletions

View File

@ -41,10 +41,10 @@ syntax::
.. note::
(version **0.9.0+**) if your field name is like mongodb operator name (for example
(version **0.9.1+**) if your field name is like mongodb operator name (for example
type, lte, lt...) and you want to place it at the end of lookup keyword
mongoengine automatically prepend $ to it. To avoid this use __ at the end of
your lookup keyword. For example if you field name is ``type`` and you want to
your lookup keyword. For example if your field name is ``type`` and you want to
query by this field you must use ``.objects(user__type__="admin")`` instead of
``.objects(user__type="admin")``

View File

@ -45,7 +45,7 @@ def query(_doc_cls=None, _field_operation=False, **query):
op = parts.pop()
#if user escape field name by __
if len(parts) > 1 and parts[-1]=="":
if len(parts) > 1 and parts[-1] == "":
parts.pop()
negate = False

View File

@ -4592,21 +4592,6 @@ class QuerySetTest(unittest.TestCase):
self.assertEquals(Animal.objects(folded_ears=True).count(), 1)
self.assertEquals(Animal.objects(whiskers_length=5.1).count(), 1)
def test_last_field_name_like_operator(self):
class EmbeddedItem(EmbeddedDocument):
type = StringField()
name = StringField()
class Doc(Document):
item = EmbeddedDocumentField(EmbeddedItem)
Doc.drop_collection()
doc = Doc(item=EmbeddedItem(type="axe", name="Heroic axe"))
doc.save()
self.assertEqual(1, Doc.objects(item__type__="axe").count())
self.assertEqual(1, Doc.objects(item__name__="Heroic axe").count())
if __name__ == '__main__':
unittest.main()

View File

@ -208,6 +208,22 @@ class TransformTest(unittest.TestCase):
self.assertEqual(Doc.objects(df__type=2).count(), 1) # str
self.assertEqual(Doc.objects(df__type=16).count(), 1) # int
def test_last_field_name_like_operator(self):
class EmbeddedItem(EmbeddedDocument):
type = StringField()
name = StringField()
class Doc(Document):
item = EmbeddedDocumentField(EmbeddedItem)
Doc.drop_collection()
doc = Doc(item=EmbeddedItem(type="axe", name="Heroic axe"))
doc.save()
self.assertEqual(1, Doc.objects(item__type__="axe").count())
self.assertEqual(1, Doc.objects(item__name__="Heroic axe").count())
if __name__ == '__main__':
unittest.main()