From e8fc3f3783744e4fcd3ff0ac43e3ce2572292f3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anssi=20K=C3=A4=C3=A4ri=C3=A4inen?= Date: Wed, 20 Feb 2013 21:09:27 +0200 Subject: [PATCH] Added a test for negated Q object querying The added test is from the patch in ticket #19672 (written by Ian Kelly). Fixed #19672, refs #19849. --- tests/regressiontests/queries/models.py | 1 + tests/regressiontests/queries/tests.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py index 91edf71aeb..28c858557b 100644 --- a/tests/regressiontests/queries/models.py +++ b/tests/regressiontests/queries/models.py @@ -64,6 +64,7 @@ class Annotation(models.Model): class ExtraInfo(models.Model): info = models.CharField(max_length=100) note = models.ForeignKey(Note) + value = models.IntegerField(null=True) class Meta: ordering = ['info'] diff --git a/tests/regressiontests/queries/tests.py b/tests/regressiontests/queries/tests.py index 34bfea0b94..82a8de08be 100644 --- a/tests/regressiontests/queries/tests.py +++ b/tests/regressiontests/queries/tests.py @@ -52,8 +52,8 @@ class Queries1Tests(BaseQuerysetTest): # Create these out of order so that sorting by 'id' will be different to sorting # by 'info'. Helps detect some problems later. - self.e2 = ExtraInfo.objects.create(info='e2', note=n2) - e1 = ExtraInfo.objects.create(info='e1', note=self.n1) + self.e2 = ExtraInfo.objects.create(info='e2', note=n2, value=41) + e1 = ExtraInfo.objects.create(info='e1', note=self.n1, value=42) self.a1 = Author.objects.create(name='a1', num=1001, extra=e1) self.a2 = Author.objects.create(name='a2', num=2002, extra=e1) @@ -1106,6 +1106,13 @@ class Queries1Tests(BaseQuerysetTest): self.assertTrue(str(q3.query).count('LEFT OUTER JOIN') == 1) self.assertTrue(str(q3.query).count('INNER JOIN') == 0) + def test_ticket19672(self): + self.assertQuerysetEqual( + Report.objects.filter(Q(creator__isnull=False) & + ~Q(creator__extra__value=41)), + [''] + ) + class Queries2Tests(TestCase): def setUp(self):