From 8e884fd3ea85031bd5fa2a855a6eed0becd0730f Mon Sep 17 00:00:00 2001 From: Stefan Wojcik Date: Mon, 12 Dec 2016 23:30:38 -0500 Subject: [PATCH] make the __in=non_iterable_or_doc tests more concise --- tests/queryset/queryset.py | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/tests/queryset/queryset.py b/tests/queryset/queryset.py index 28b831cd..11ce0a27 100644 --- a/tests/queryset/queryset.py +++ b/tests/queryset/queryset.py @@ -4977,40 +4977,19 @@ class QuerySetTest(unittest.TestCase): 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() + author = User.objects.create(name='Test User') + post = BlogPost.objects.create(content='Had a good coffee today...', + authors=[author]) + # Make sure using `__in` with a list works blog_posts = BlogPost.objects(authors__in=[author]) self.assertEqual(list(blog_posts), [post]) - # Using the `__in`-operator with a non-iterable should raise a TypeError - self.assertRaises(TypeError, BlogPost.objects(authors__in=author.id).count) + # Using `__in` with a non-iterable should raise a TypeError + self.assertRaises(TypeError, BlogPost.objects(authors__in=author.pk).count) - def test_in_operator_on_document(self): - """Ensure that using the `__in` operator on a `Document` raises an - 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 + # Using `__in` with a `Document` (which is seemingly iterable but not + # in a way we'd expect) should raise a TypeError, too self.assertRaises(TypeError, BlogPost.objects(authors__in=author).count)