flake8 tweaks to tests.queryset.transform
This commit is contained in:
parent
3985bd3e53
commit
43adba115b
@ -1,11 +1,7 @@
|
|||||||
import sys
|
|
||||||
sys.path[0:0] = [""]
|
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from mongoengine import *
|
from mongoengine import *
|
||||||
from mongoengine.queryset import Q
|
from mongoengine.queryset import Q, transform
|
||||||
from mongoengine.queryset import transform
|
|
||||||
|
|
||||||
__all__ = ("TransformTest",)
|
__all__ = ("TransformTest",)
|
||||||
|
|
||||||
@ -41,8 +37,8 @@ class TransformTest(unittest.TestCase):
|
|||||||
DicDoc.drop_collection()
|
DicDoc.drop_collection()
|
||||||
Doc.drop_collection()
|
Doc.drop_collection()
|
||||||
|
|
||||||
|
DicDoc().save()
|
||||||
doc = Doc().save()
|
doc = Doc().save()
|
||||||
dic_doc = DicDoc().save()
|
|
||||||
|
|
||||||
for k, v in (("set", "$set"), ("set_on_insert", "$setOnInsert"), ("push", "$push")):
|
for k, v in (("set", "$set"), ("set_on_insert", "$setOnInsert"), ("push", "$push")):
|
||||||
update = transform.update(DicDoc, **{"%s__dictField__test" % k: doc})
|
update = transform.update(DicDoc, **{"%s__dictField__test" % k: doc})
|
||||||
@ -55,7 +51,6 @@ class TransformTest(unittest.TestCase):
|
|||||||
update = transform.update(DicDoc, pull__dictField__test=doc)
|
update = transform.update(DicDoc, pull__dictField__test=doc)
|
||||||
self.assertTrue(isinstance(update["$pull"]["dictField"]["test"], dict))
|
self.assertTrue(isinstance(update["$pull"]["dictField"]["test"], dict))
|
||||||
|
|
||||||
|
|
||||||
def test_query_field_name(self):
|
def test_query_field_name(self):
|
||||||
"""Ensure that the correct field name is used when querying.
|
"""Ensure that the correct field name is used when querying.
|
||||||
"""
|
"""
|
||||||
@ -156,26 +151,33 @@ class TransformTest(unittest.TestCase):
|
|||||||
class Doc(Document):
|
class Doc(Document):
|
||||||
meta = {'allow_inheritance': False}
|
meta = {'allow_inheritance': False}
|
||||||
|
|
||||||
raw_query = Doc.objects(__raw__={'deleted': False,
|
raw_query = Doc.objects(__raw__={
|
||||||
|
'deleted': False,
|
||||||
'scraped': 'yes',
|
'scraped': 'yes',
|
||||||
'$nor': [{'views.extracted': 'no'},
|
'$nor': [
|
||||||
{'attachments.views.extracted':'no'}]
|
{'views.extracted': 'no'},
|
||||||
|
{'attachments.views.extracted': 'no'}
|
||||||
|
]
|
||||||
})._query
|
})._query
|
||||||
|
|
||||||
expected = {'deleted': False, 'scraped': 'yes',
|
self.assertEqual(raw_query, {
|
||||||
'$nor': [{'views.extracted': 'no'},
|
'deleted': False,
|
||||||
{'attachments.views.extracted': 'no'}]}
|
'scraped': 'yes',
|
||||||
self.assertEqual(expected, raw_query)
|
'$nor': [
|
||||||
|
{'views.extracted': 'no'},
|
||||||
|
{'attachments.views.extracted': 'no'}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
def test_geojson_PointField(self):
|
def test_geojson_PointField(self):
|
||||||
class Location(Document):
|
class Location(Document):
|
||||||
loc = PointField()
|
loc = PointField()
|
||||||
|
|
||||||
update = transform.update(Location, set__loc=[1, 2])
|
update = transform.update(Location, set__loc=[1, 2])
|
||||||
self.assertEqual(update, {'$set': {'loc': {"type": "Point", "coordinates": [1,2]}}})
|
self.assertEqual(update, {'$set': {'loc': {"type": "Point", "coordinates": [1, 2]}}})
|
||||||
|
|
||||||
update = transform.update(Location, set__loc={"type": "Point", "coordinates": [1,2]})
|
update = transform.update(Location, set__loc={"type": "Point", "coordinates": [1, 2]})
|
||||||
self.assertEqual(update, {'$set': {'loc': {"type": "Point", "coordinates": [1,2]}}})
|
self.assertEqual(update, {'$set': {'loc': {"type": "Point", "coordinates": [1, 2]}}})
|
||||||
|
|
||||||
def test_geojson_LineStringField(self):
|
def test_geojson_LineStringField(self):
|
||||||
class Location(Document):
|
class Location(Document):
|
||||||
@ -238,5 +240,6 @@ class TransformTest(unittest.TestCase):
|
|||||||
events = Event.objects(location__within=box)
|
events = Event.objects(location__within=box)
|
||||||
self.assertRaises(InvalidQueryError, lambda: events.count())
|
self.assertRaises(InvalidQueryError, lambda: events.count())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user