Ticket #19837: 19837-test.diff

File 19837-test.diff, 1.9 KB (added by timo, 2 years ago)
  • tests/regressiontests/queries/models.py

    diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py
    index 16583e8..7f0eb63 100644
    a b class BaseA(models.Model): 
    439439    a = models.ForeignKey(FK1, null=True)
    440440    b = models.ForeignKey(FK2, null=True)
    441441    c = models.ForeignKey(FK3, null=True)
     442
     443class Identifier(models.Model):
     444    name = models.TextField()
     445
     446    def __unicode__(self):
     447        return self.name
     448
     449class Program(models.Model):
     450    identifier = models.OneToOneField(Identifier)
     451
     452class Channel(models.Model):
     453    programs = models.ManyToManyField(Program)
     454    identifier = models.OneToOneField(Identifier)
  • tests/regressiontests/queries/tests.py

    diff --git a/tests/regressiontests/queries/tests.py b/tests/regressiontests/queries/tests.py
    index ea54d18..4d688eb 100644
    a b class DisjunctionPromotionTests(TestCase): 
    26122612        qs = BaseA.objects.filter(Q(a__f1=F('c__f1')) | (Q(pk=1) & Q(pk=2)))
    26132613        self.assertEqual(str(qs.query).count('LEFT OUTER JOIN'), 2)
    26142614        self.assertEqual(str(qs.query).count('INNER JOIN'), 0)
     2615
     2616from .models import Identifier,Program, Channel
     2617
     2618class ManyToManyExcludeTest(TestCase):
     2619    def test_exclude_many_to_many(self):
     2620        Identifier.objects.create(name='extra')
     2621        program = Program.objects.create(identifier=Identifier.objects.create(name='program'))
     2622        channel = Channel.objects.create(identifier=Identifier.objects.create(name='channel'))
     2623        channel.programs.add(program)
     2624
     2625        # channel contains 'program1', so all Identifiers except that one
     2626        # should be returned
     2627        self.assertQuerysetEqual(
     2628            Identifier.objects.exclude(program__channel=channel).order_by('name'),
     2629            ['<Identifier: channel>', '<Identifier: extra>']
     2630        )
Back to Top