parent
e3b4563c2b
commit
31521ccff5
@ -1692,6 +1692,35 @@ class QuerySetTest(unittest.TestCase):
|
|||||||
|
|
||||||
Number.drop_collection()
|
Number.drop_collection()
|
||||||
|
|
||||||
|
def test_clone(self):
|
||||||
|
"""Ensure that cloning clones complex querysets
|
||||||
|
"""
|
||||||
|
class Number(Document):
|
||||||
|
n = IntField()
|
||||||
|
|
||||||
|
Number.drop_collection()
|
||||||
|
|
||||||
|
for i in xrange(1, 101):
|
||||||
|
t = Number(n=i)
|
||||||
|
t.save()
|
||||||
|
|
||||||
|
test = Number.objects
|
||||||
|
test2 = test.clone()
|
||||||
|
self.assertFalse(test == test2)
|
||||||
|
self.assertEqual(test.count(), test2.count())
|
||||||
|
|
||||||
|
test = test.filter(n__gt=11)
|
||||||
|
test2 = test.clone()
|
||||||
|
self.assertFalse(test == test2)
|
||||||
|
self.assertEqual(test.count(), test2.count())
|
||||||
|
|
||||||
|
test = test.limit(10)
|
||||||
|
test2 = test.clone()
|
||||||
|
self.assertFalse(test == test2)
|
||||||
|
self.assertEqual(test.count(), test2.count())
|
||||||
|
|
||||||
|
Number.drop_collection()
|
||||||
|
|
||||||
def test_unset_reference(self):
|
def test_unset_reference(self):
|
||||||
class Comment(Document):
|
class Comment(Document):
|
||||||
text = StringField()
|
text = StringField()
|
||||||
@ -1850,6 +1879,30 @@ class QTest(unittest.TestCase):
|
|||||||
for condition in conditions:
|
for condition in conditions:
|
||||||
self.assertTrue(condition in query['$or'])
|
self.assertTrue(condition in query['$or'])
|
||||||
|
|
||||||
|
|
||||||
|
def test_q_clone(self):
|
||||||
|
|
||||||
|
class TestDoc(Document):
|
||||||
|
x = IntField()
|
||||||
|
|
||||||
|
TestDoc.drop_collection()
|
||||||
|
for i in xrange(1, 101):
|
||||||
|
t = TestDoc(x=i)
|
||||||
|
t.save()
|
||||||
|
|
||||||
|
# Check normal cases work without an error
|
||||||
|
test = TestDoc.objects(Q(x__lt=7) & Q(x__gt=3))
|
||||||
|
|
||||||
|
self.assertEqual(test.count(), 3)
|
||||||
|
|
||||||
|
test2 = test.clone()
|
||||||
|
self.assertEqual(test2.count(), 3)
|
||||||
|
self.assertFalse(test2 == test)
|
||||||
|
|
||||||
|
test2.filter(x=6)
|
||||||
|
self.assertEqual(test2.count(), 1)
|
||||||
|
self.assertEqual(test.count(), 3)
|
||||||
|
|
||||||
class QueryFieldListTest(unittest.TestCase):
|
class QueryFieldListTest(unittest.TestCase):
|
||||||
def test_empty(self):
|
def test_empty(self):
|
||||||
q = QueryFieldList()
|
q = QueryFieldList()
|
||||||
@ -1904,8 +1957,5 @@ class QueryFieldListTest(unittest.TestCase):
|
|||||||
self.assertEqual(q.as_dict(), {'x': True, 'y': True, 'b': True, 'c': True})
|
self.assertEqual(q.as_dict(), {'x': True, 'y': True, 'b': True, 'c': True})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user