make the __in=non_iterable_or_doc tests more concise
This commit is contained in:
parent
76524b7498
commit
8e884fd3ea
@ -4977,40 +4977,19 @@ class QuerySetTest(unittest.TestCase):
|
|||||||
User.drop_collection()
|
User.drop_collection()
|
||||||
BlogPost.drop_collection()
|
BlogPost.drop_collection()
|
||||||
|
|
||||||
author = User(name='Test User')
|
author = User.objects.create(name='Test User')
|
||||||
author.save()
|
post = BlogPost.objects.create(content='Had a good coffee today...',
|
||||||
post = BlogPost(content='Had a good coffee today...', authors=[author])
|
authors=[author])
|
||||||
post.save()
|
|
||||||
|
|
||||||
|
# Make sure using `__in` with a list works
|
||||||
blog_posts = BlogPost.objects(authors__in=[author])
|
blog_posts = BlogPost.objects(authors__in=[author])
|
||||||
self.assertEqual(list(blog_posts), [post])
|
self.assertEqual(list(blog_posts), [post])
|
||||||
|
|
||||||
# Using the `__in`-operator with a non-iterable should raise a TypeError
|
# Using `__in` with a non-iterable should raise a TypeError
|
||||||
self.assertRaises(TypeError, BlogPost.objects(authors__in=author.id).count)
|
self.assertRaises(TypeError, BlogPost.objects(authors__in=author.pk).count)
|
||||||
|
|
||||||
def test_in_operator_on_document(self):
|
# Using `__in` with a `Document` (which is seemingly iterable but not
|
||||||
"""Ensure that using the `__in` operator on a `Document` raises an
|
# in a way we'd expect) should raise a TypeError, too
|
||||||
error.
|
|
||||||
"""
|
|
||||||
class User(Document):
|
|
||||||
name = StringField()
|
|
||||||
|
|
||||||
class BlogPost(Document):
|
|
||||||
content = StringField()
|
|
||||||
authors = ListField(ReferenceField(User))
|
|
||||||
|
|
||||||
User.drop_collection()
|
|
||||||
BlogPost.drop_collection()
|
|
||||||
|
|
||||||
author = User(name='Test User')
|
|
||||||
author.save()
|
|
||||||
post = BlogPost(content='Had a good coffee today...', authors=[author])
|
|
||||||
post.save()
|
|
||||||
|
|
||||||
blog_posts = BlogPost.objects(authors__in=[author])
|
|
||||||
self.assertEqual(list(blog_posts), [post])
|
|
||||||
|
|
||||||
# Using the `__in`-operator with a `Document` should raise a TypeError
|
|
||||||
self.assertRaises(TypeError, BlogPost.objects(authors__in=author).count)
|
self.assertRaises(TypeError, BlogPost.objects(authors__in=author).count)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user