mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Fixed #29723 -- Fixed crash if InlineModelAdmin.has_add_permission() doesn't accept the obj argument.
* Refs #27991 -- Added testing for ModelAdmin.get_inline_instances() if the inline's has_add_permission() doesn't accept 'obj'. * Fixed #29723 -- Fixed crash if InlineModelAdmin.has_add_permission() doesn't accept the obj argument.
This commit is contained in:
parent
54b331451c
commit
fd8a7a5313
3 changed files with 57 additions and 8 deletions
|
@ -1,4 +1,8 @@
|
|||
from datetime import date
|
||||
|
||||
from django.contrib.admin.options import ModelAdmin, TabularInline
|
||||
from django.contrib.admin.sites import AdminSite
|
||||
from django.test import TestCase
|
||||
from django.utils.deprecation import RemovedInDjango30Warning
|
||||
|
||||
from .models import Band, Song
|
||||
|
@ -56,3 +60,45 @@ class HasAddPermissionObjTests(CheckTestCase):
|
|||
)
|
||||
with self.assertWarnsMessage(RemovedInDjango30Warning, msg):
|
||||
self.assertIsValid(BandAdmin, Band)
|
||||
|
||||
|
||||
class MockRequest:
|
||||
method = 'POST'
|
||||
FILES = {}
|
||||
POST = {}
|
||||
|
||||
|
||||
class SongInline(TabularInline):
|
||||
model = Song
|
||||
|
||||
def has_add_permission(self, request):
|
||||
return True
|
||||
|
||||
|
||||
class BandAdmin(ModelAdmin):
|
||||
inlines = [SongInline]
|
||||
|
||||
|
||||
class ModelAdminTests(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.band = Band.objects.create(name='The Doors', bio='', sign_date=date(1965, 1, 1))
|
||||
self.song = Song.objects.create(name='test', band=self.band)
|
||||
self.site = AdminSite()
|
||||
self.request = MockRequest()
|
||||
self.request.user = self.MockAddUser()
|
||||
self.ma = BandAdmin(Band, self.site)
|
||||
|
||||
class MockAddUser:
|
||||
def has_perm(self, perm):
|
||||
return perm == 'modeladmin.add_band'
|
||||
|
||||
def test_get_inline_instances(self):
|
||||
self.assertEqual(len(self.ma.get_inline_instances(self.request)), 1)
|
||||
|
||||
def test_get_inline_formsets(self):
|
||||
formsets, inline_instances = self.ma._create_formsets(self.request, self.band, change=True)
|
||||
self.assertEqual(len(self.ma.get_inline_formsets(self.request, formsets, inline_instances)), 1)
|
||||
|
||||
def test_get_formsets_with_inlines(self):
|
||||
self.assertEqual(len(list(self.ma. get_formsets_with_inlines(self.request, self.band))), 1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue