From 323b414441e13681c2a4117dc7043926f938f48a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anssi=20K=C3=A4=C3=A4ri=C3=A4inen?= Date: Fri, 25 May 2012 14:00:42 +0300 Subject: [PATCH] Added tests for nested exclude/negate queries --- tests/regressiontests/queries/tests.py | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/regressiontests/queries/tests.py b/tests/regressiontests/queries/tests.py index 28aa63328e..1035a38840 100644 --- a/tests/regressiontests/queries/tests.py +++ b/tests/regressiontests/queries/tests.py @@ -844,6 +844,39 @@ class Queries1Tests(BaseQuerysetTest): ) Tag._meta.ordering = original_ordering + def test_exclude(self): + self.assertQuerysetEqual( + Item.objects.exclude(tags__name='t4'), + [repr(i) for i in Item.objects.filter(~Q(tags__name='t4'))]) + self.assertQuerysetEqual( + Item.objects.exclude(Q(tags__name='t4')|Q(tags__name='t3')), + [repr(i) for i in Item.objects.filter(~(Q(tags__name='t4')|Q(tags__name='t3')))]) + self.assertQuerysetEqual( + Item.objects.exclude(Q(tags__name='t4')|~Q(tags__name='t3')), + [repr(i) for i in Item.objects.filter(~(Q(tags__name='t4')|~Q(tags__name='t3')))]) + + def test_nested_exclude(self): + self.assertQuerysetEqual( + Item.objects.exclude(~Q(tags__name='t4')), + [repr(i) for i in Item.objects.filter(~~Q(tags__name='t4'))]) + + def test_double_exclude(self): + self.assertQuerysetEqual( + Item.objects.filter(Q(tags__name='t4')), + [repr(i) for i in Item.objects.filter(~~Q(tags__name='t4'))]) + self.assertQuerysetEqual( + Item.objects.filter(Q(tags__name='t4')), + [repr(i) for i in Item.objects.filter(~Q(~Q(tags__name='t4')))]) + + @unittest.expectedFailure + def test_exclude_in(self): + self.assertQuerysetEqual( + Item.objects.exclude(Q(tags__name__in=['t4', 't3'])), + [repr(i) for i in Item.objects.filter(~Q(tags__name__in=['t4', 't3']))]) + self.assertQuerysetEqual( + Item.objects.filter(Q(tags__name__in=['t4', 't3'])), + [repr(i) for i in Item.objects.filter(~~Q(tags__name__in=['t4', 't3']))]) + class Queries2Tests(TestCase): def setUp(self): Number.objects.create(num=4)