From d1d39c224a09dd52c4831ebbc593c9ee33c94103 Mon Sep 17 00:00:00 2001
From: Simon Charette <charette.s@gmail.com>
Date: Sun, 29 Sep 2013 13:02:25 -0400
Subject: [PATCH] Fixed #15786 -- Added a regression test for o2o excludes
using F().
The issue was reported against 1.3.x but has been fixed since.
---
tests/queries/models.py | 4 ++++
tests/queries/tests.py | 19 +++++++++++++++++--
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/tests/queries/models.py b/tests/queries/models.py
index aa72493..afd2493 100644
a
|
b
|
class OneToOneCategory(models.Model):
|
390 | 390 | def __str__(self): |
391 | 391 | return "one2one " + self.new_name |
392 | 392 | |
| 393 | class CategoryRelationship(models.Model): |
| 394 | first = models.ForeignKey(SimpleCategory, related_name='first_rel') |
| 395 | second = models.ForeignKey(SimpleCategory, related_name='second_rel') |
| 396 | |
393 | 397 | class NullableName(models.Model): |
394 | 398 | name = models.CharField(max_length=20, null=True) |
395 | 399 | |
diff --git a/tests/queries/tests.py b/tests/queries/tests.py
index f3efc24..f0a5df5 100644
a
|
b
|
from collections import OrderedDict
|
4 | 4 | import datetime |
5 | 5 | from operator import attrgetter |
6 | 6 | import pickle |
7 | | import sys |
8 | 7 | import unittest |
9 | 8 | |
10 | 9 | from django.conf import settings |
… |
… |
from .models import (
|
26 | 25 | OneToOneCategory, NullableName, ProxyCategory, SingleObject, RelatedObject, |
27 | 26 | ModelA, ModelB, ModelC, ModelD, Responsibility, Job, JobResponsibilities, |
28 | 27 | BaseA, FK1, Identifier, Program, Channel, Page, Paragraph, Chapter, Book, |
29 | | MyObject, Order, OrderItem, SharedConnection, Task, Staff, StaffUser) |
| 28 | MyObject, Order, OrderItem, SharedConnection, Task, Staff, StaffUser, |
| 29 | CategoryRelationship) |
30 | 30 | |
31 | 31 | class BaseQuerysetTest(TestCase): |
32 | 32 | def assertValueQuerysetEqual(self, qs, values): |
… |
… |
class ExcludeTest17600(TestCase):
|
2452 | 2452 | Order.objects.exclude(~Q(items__status=1)).distinct(), |
2453 | 2453 | ['<Order: 1>']) |
2454 | 2454 | |
| 2455 | class Exclude15786(TestCase): |
| 2456 | """Regression test for #15786""" |
| 2457 | def test_ticket15786(self): |
| 2458 | c1 = SimpleCategory.objects.create(name='c1') |
| 2459 | c2 = SimpleCategory.objects.create(name='c2') |
| 2460 | o2o1 = OneToOneCategory.objects.create(category=c1) |
| 2461 | o2o2 = OneToOneCategory.objects.create(category=c2) |
| 2462 | rel = CategoryRelationship.objects.create(first=c1, second=c2) |
| 2463 | self.assertEqual( |
| 2464 | CategoryRelationship.objects.exclude( |
| 2465 | first__onetoonecategory=F('second__onetoonecategory') |
| 2466 | ).get(), rel |
| 2467 | ) |
| 2468 | |
| 2469 | |
2455 | 2470 | class NullInExcludeTest(TestCase): |
2456 | 2471 | def setUp(self): |
2457 | 2472 | NullableName.objects.create(name='i1') |