summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNick Sandford <nick@sandford.id.au>2015-11-07 11:31:06 +0000
committerTim Graham <timograham@gmail.com>2015-12-29 12:10:44 -0500
commitff19df9c2d6ad80bb9177e8190176e9c3716705f (patch)
tree9eea57fcbcfd459b58591bc6146dd40a7adfbffb /tests
parentd9e150b3117521f7c24dc6393eb29eebc3cc376a (diff)
Fixed #19536 -- Included object-tools when ModelAdmin.has_add_permission() is False.
Diffstat (limited to 'tests')
-rw-r--r--tests/admin_changelist/admin.py3
-rw-r--r--tests/admin_changelist/tests.py21
2 files changed, 21 insertions, 3 deletions
diff --git a/tests/admin_changelist/admin.py b/tests/admin_changelist/admin.py
index 4ca5ae587a..51d183dfdb 100644
--- a/tests/admin_changelist/admin.py
+++ b/tests/admin_changelist/admin.py
@@ -22,6 +22,9 @@ class EventAdmin(admin.ModelAdmin):
def event_date_func(self, event):
return event.date
+ def has_add_permission(self, request):
+ return False
+
site.register(Event, EventAdmin)
diff --git a/tests/admin_changelist/tests.py b/tests/admin_changelist/tests.py
index 93910dc3b0..81bf3bdfc6 100644
--- a/tests/admin_changelist/tests.py
+++ b/tests/admin_changelist/tests.py
@@ -21,9 +21,10 @@ from .admin import (
BandAdmin, ChildAdmin, ChordsBandAdmin, ConcertAdmin,
CustomPaginationAdmin, CustomPaginator, DynamicListDisplayChildAdmin,
DynamicListDisplayLinksChildAdmin, DynamicListFilterChildAdmin,
- DynamicSearchFieldsChildAdmin, EmptyValueChildAdmin, FilteredChildAdmin,
- GroupAdmin, InvitationAdmin, NoListDisplayLinksParentAdmin, ParentAdmin,
- QuartetAdmin, SwallowAdmin, site as custom_site,
+ DynamicSearchFieldsChildAdmin, EmptyValueChildAdmin, EventAdmin,
+ FilteredChildAdmin, GroupAdmin, InvitationAdmin,
+ NoListDisplayLinksParentAdmin, ParentAdmin, QuartetAdmin, SwallowAdmin,
+ site as custom_site,
)
from .models import (
Band, Child, ChordsBand, ChordsMusician, Concert, CustomIdUser, Event,
@@ -761,6 +762,20 @@ class ChangeListTests(TestCase):
list(real_page_range),
)
+ def test_object_tools_displayed_no_add_permission(self):
+ """
+ When ModelAdmin.has_add_permission() returns False, the object-tools
+ block is still shown.
+ """
+ superuser = self._create_superuser('superuser')
+ m = EventAdmin(Event, custom_site)
+ request = self._mocked_authenticated_request('/event/', superuser)
+ self.assertFalse(m.has_add_permission(request))
+ response = m.changelist_view(request)
+ self.assertIn('<ul class="object-tools">', response.rendered_content)
+ # The "Add" button inside the object-tools shouldn't appear.
+ self.assertNotIn('Add', response.rendered_content)
+
class AdminLogNodeTestCase(TestCase):