Merge remote branch 'iapain/master' into dev

This commit is contained in:
Harry Marr 2011-01-09 20:52:39 +00:00
commit 357dd0e7cc
2 changed files with 22 additions and 8 deletions

View File

@ -78,7 +78,7 @@ class SimplificationVisitor(QNodeVisitor):
# to a single field # to a single field
intersection = ops.intersection(query_ops) intersection = ops.intersection(query_ops)
if intersection: if intersection:
msg = 'Duplicate query contitions: ' msg = 'Duplicate query conditions: '
raise InvalidQueryError(msg + ', '.join(intersection)) raise InvalidQueryError(msg + ', '.join(intersection))
query_ops.update(ops) query_ops.update(ops)
@ -179,7 +179,7 @@ class QueryCompilerVisitor(QNodeVisitor):
# once to a single field # once to a single field
intersection = current_ops.intersection(new_ops) intersection = current_ops.intersection(new_ops)
if intersection: if intersection:
msg = 'Duplicate query contitions: ' msg = 'Duplicate query conditions: '
raise InvalidQueryError(msg + ', '.join(intersection)) raise InvalidQueryError(msg + ', '.join(intersection))
# Right! We've got two non-overlapping dicts of operations! # Right! We've got two non-overlapping dicts of operations!

View File

@ -539,33 +539,47 @@ class QuerySetTest(unittest.TestCase):
"""Ensure that Q objects may be used to query for documents. """Ensure that Q objects may be used to query for documents.
""" """
class BlogPost(Document): class BlogPost(Document):
title = StringField()
publish_date = DateTimeField() publish_date = DateTimeField()
published = BooleanField() published = BooleanField()
BlogPost.drop_collection() BlogPost.drop_collection()
post1 = BlogPost(publish_date=datetime(2010, 1, 8), published=False) post1 = BlogPost(title='Test 1', publish_date=datetime(2010, 1, 8), published=False)
post1.save() post1.save()
post2 = BlogPost(publish_date=datetime(2010, 1, 15), published=True) post2 = BlogPost(title='Test 2', publish_date=datetime(2010, 1, 15), published=True)
post2.save() post2.save()
post3 = BlogPost(published=True) post3 = BlogPost(title='Test 3', published=True)
post3.save() post3.save()
post4 = BlogPost(publish_date=datetime(2010, 1, 8)) post4 = BlogPost(title='Test 4', publish_date=datetime(2010, 1, 8))
post4.save() post4.save()
post5 = BlogPost(publish_date=datetime(2010, 1, 15)) post5 = BlogPost(title='Test 1', publish_date=datetime(2010, 1, 15))
post5.save() post5.save()
post6 = BlogPost(published=False) post6 = BlogPost(title='Test 1', published=False)
post6.save() post6.save()
# Check ObjectId lookup works # Check ObjectId lookup works
obj = BlogPost.objects(id=post1.id).first() obj = BlogPost.objects(id=post1.id).first()
self.assertEqual(obj, post1) self.assertEqual(obj, post1)
# Check Q object combination with one does not exist
q = BlogPost.objects(Q(title='Test 5') | Q(published=True))
posts = [post.id for post in q]
published_posts = (post2, post3)
self.assertTrue(all(obj.id in posts for obj in published_posts))
q = BlogPost.objects(Q(title='Test 1') | Q(published=True))
posts = [post.id for post in q]
published_posts = (post1, post2, post3, post5, post6)
self.assertTrue(all(obj.id in posts for obj in published_posts))
# Check Q object combination # Check Q object combination
date = datetime(2010, 1, 10) date = datetime(2010, 1, 10)
q = BlogPost.objects(Q(publish_date__lte=date) | Q(published=True)) q = BlogPost.objects(Q(publish_date__lte=date) | Q(published=True))