Ticket #32690: ticket_32690.diff

File ticket_32690.diff, 2.1 KB (added by Mariusz Felisiak, 4 years ago)

Regression tests.

  • new file tests/ticket_32690/models.py

    commit fded86c4f71deb33a3e5db89476676f82bdcf092
    Author: Mariusz Felisiak <felisiak.mariusz@gmail.com>
    Date:   Thu Apr 29 06:58:23 2021 +0200
    
        test
    
    diff --git a/tests/ticket_32690/__init__.py b/tests/ticket_32690/__init__.py
    new file mode 100644
    index 0000000000..e69de29bb2
    diff --git a/tests/ticket_32690/models.py b/tests/ticket_32690/models.py
    new file mode 100644
    index 0000000000..06ed5a0a6f
    - +  
     1from django.db import models
     2from django.db.models import Count, Q
     3
     4
     5class RealmAccess(models.Model):
     6    name = models.CharField(max_length=100)
     7
     8
     9class Actor(models.Model):
     10    realm_access = models.ManyToManyField(RealmAccess, related_name='actors')
     11
     12
     13class ThingManager(models.QuerySet):
     14    def filter_by_realm_access_broken(self, actor):
     15        realm_access = RealmAccess.objects.filter(actors=actor)
     16        queryset = self.annotate(Count("actor__realm_access"))
     17        import sqlparse
     18        print(sqlparse.format(str(queryset.filter(
     19            Q(
     20                actor__realm_access__in=realm_access
     21            )
     22            | Q(actor__realm_access__count=0)
     23        ).query), reindent=True, keyword_case='upper'))
     24
     25        return queryset.filter(
     26            Q(
     27                actor__realm_access__in=realm_access
     28            )
     29            | Q(actor__realm_access__count=0)
     30        )
     31
     32class Thing(models.Model):
     33    actor = models.ForeignKey(Actor, on_delete=models.CASCADE)
     34    date = models.DateField()
     35
     36    objects = ThingManager.as_manager()
  • new file tests/ticket_32690/tests.py

    diff --git a/tests/ticket_32690/tests.py b/tests/ticket_32690/tests.py
    new file mode 100644
    index 0000000000..ff70c1c7fe
    - +  
     1from django.test import TestCase
     2
     3from .models import Actor, RealmAccess, Thing
     4
     5class MyTests(TestCase):
     6
     7    def test_1(self):
     8        actor1 = Actor.objects.create()
     9        actor2 = Actor.objects.create()
     10
     11        r1 = RealmAccess.objects.create(name='ok')
     12        r2 = RealmAccess.objects.create(name='ok2')
     13
     14        actor1.realm_access.add(r1)
     15
     16        list(Thing.objects.filter_by_realm_access_broken(actor1))
Back to Top