Ticket #15786: 0001-Fixed-15786-Added-a-regression-test-for-o2o-excludes.patch

File 0001-Fixed-15786-Added-a-regression-test-for-o2o-excludes.patch, 2.7 KB (added by Simon Charette, 11 years ago)
  • tests/queries/models.py

    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):  
    390390    def __str__(self):
    391391        return "one2one " + self.new_name
    392392
     393class CategoryRelationship(models.Model):
     394    first = models.ForeignKey(SimpleCategory, related_name='first_rel')
     395    second = models.ForeignKey(SimpleCategory, related_name='second_rel')
     396
    393397class NullableName(models.Model):
    394398    name = models.CharField(max_length=20, null=True)
    395399
  • tests/queries/tests.py

    diff --git a/tests/queries/tests.py b/tests/queries/tests.py
    index f3efc24..f0a5df5 100644
    a b from collections import OrderedDict  
    44import datetime
    55from operator import attrgetter
    66import pickle
    7 import sys
    87import unittest
    98
    109from django.conf import settings
    from .models import (  
    2625    OneToOneCategory, NullableName, ProxyCategory, SingleObject, RelatedObject,
    2726    ModelA, ModelB, ModelC, ModelD, Responsibility, Job, JobResponsibilities,
    2827    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)
    3030
    3131class BaseQuerysetTest(TestCase):
    3232    def assertValueQuerysetEqual(self, qs, values):
    class ExcludeTest17600(TestCase):  
    24522452            Order.objects.exclude(~Q(items__status=1)).distinct(),
    24532453            ['<Order: 1>'])
    24542454
     2455class 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
    24552470class NullInExcludeTest(TestCase):
    24562471    def setUp(self):
    24572472        NullableName.objects.create(name='i1')
Back to Top