Ticket #33375: failing-test.patch

File failing-test.patch, 3.5 KB (added by François Freitag, 3 years ago)

Failing test v2 (fixed _save and management form missing from POST data)

  • tests/admin_changelist/admin.py

    diff --git a/tests/admin_changelist/admin.py b/tests/admin_changelist/admin.py
    index 34e84a06b6..97833fa86b 100644
    a b from django.contrib.auth.admin import UserAdmin  
    33from django.contrib.auth.models import User
    44from django.core.paginator import Paginator
    55
    6 from .models import Band, Child, Event, Parent, Swallow
     6from .models import Band, Child, Event, Parent, SoftDeletable, Swallow
    77
    88site = admin.AdminSite(name="admin")
    99
    class EmptyValueChildAdmin(admin.ModelAdmin):  
    176176    @admin.display(empty_value='†')
    177177    def age_display(self, obj):
    178178        return obj.age
     179
     180
     181class SoftDeletableAdmin(admin.ModelAdmin):
     182    list_display = ["name", "deleted"]
     183    list_editable = ["deleted"]
     184    ordering = ["name"]
     185
     186    def get_queryset(self, request):
     187        return self.model.include_deleted.all()
     188
     189
     190site.register(SoftDeletable, SoftDeletableAdmin)
  • tests/admin_changelist/models.py

    diff --git a/tests/admin_changelist/models.py b/tests/admin_changelist/models.py
    index 81d7fdfb3a..0e6387d0a1 100644
    a b class CustomIdUser(models.Model):  
    119119
    120120class CharPK(models.Model):
    121121    char_pk = models.CharField(max_length=100, primary_key=True)
     122
     123
     124class SoftDeletableManager(models.Manager):
     125    def get_queryset(self):
     126        return super().get_queryset().filter(deleted=False)
     127
     128
     129class SoftDeletable(models.Model):
     130    name = models.CharField(max_length=20)
     131    deleted = models.BooleanField(default=False)
     132
     133    objects = SoftDeletableManager()
     134    include_deleted = models.Manager()
  • tests/admin_changelist/tests.py

    diff --git a/tests/admin_changelist/tests.py b/tests/admin_changelist/tests.py
    index 08fe636128..3928d19214 100644
    a b from .admin import (  
    3636from .models import (
    3737    Band, CharPK, Child, ChordsBand, ChordsMusician, Concert, CustomIdUser,
    3838    Event, Genre, Group, Invitation, Membership, Musician, OrderedObject,
    39     Parent, Quartet, Swallow, SwallowOneToOne, UnorderedObject,
     39    Parent, Quartet, SoftDeletable, Swallow, SwallowOneToOne, UnorderedObject,
    4040)
    4141
    4242
    class ChangeListTests(TestCase):  
    272272        with self.assertRaises(IncorrectLookupParameters):
    273273            m.get_changelist_instance(request)
    274274
     275    def test_list_editable_edit_objects_excluded_by_default_manager(self):
     276        deleted = SoftDeletable.objects.create(name='1-deleted', deleted=True)
     277        active = SoftDeletable.objects.create(name='2-active')
     278        self.client.force_login(self.superuser)
     279        changelist_url = reverse('admin:admin_changelist_softdeletable_changelist')
     280        data = {
     281            "form-INITIAL_FORMS": 2,
     282            "form-TOTAL_FORMS": 2,
     283            "form-0-id": deleted.pk,
     284            # Restore the soft-deleted row.
     285            "form-0-deleted": False,
     286            "form-1-id": active.pk,
     287            "form-1-deleted": False,
     288            "_save": True,
     289        }
     290        response = self.client.post(changelist_url, data)
     291        self.assertEqual(response.status_code, 302)
     292        self.assertQuerysetEqual(
     293            SoftDeletable.include_deleted.values_list("pk", "name", "deleted").order_by("name"),
     294            [
     295                (deleted.pk, "1-deleted", False),
     296                (active.pk, "2-active", False),
     297            ],
     298        )
     299
    275300    def test_custom_paginator(self):
    276301        new_parent = Parent.objects.create(name='parent')
    277302        for i in range(1, 201):
Back to Top