Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.6.x] Updated tests for deprecation of Option.get_(add|change|delet…

…e)_permission.

refs #20642.

Backport of a6a905c from master.
  • Loading branch information...
commit 3c51962cabc9537221b86c667aac5ffaa1469660 1 parent e03a88b
Tim Graham timgraham authored
Showing with 10 additions and 8 deletions.
  1. +2 −1  django/contrib/admin/util.py
  2. +8 −7 tests/admin_views/tests.py
3  django/contrib/admin/util.py
View
@@ -3,6 +3,7 @@
import datetime
import decimal
+from django.contrib.auth import get_permission_codename
from django.db import models
from django.db.models.constants import LOOKUP_SEP
from django.db.models.deletion import Collector
@@ -119,7 +120,7 @@ def format_callback(obj):
opts.model_name),
None, (quote(obj._get_pk_val()),))
p = '%s.%s' % (opts.app_label,
- opts.get_delete_permission())
+ get_permission_codename('delete', opts))
if not user.has_perm(p):
perms_needed.add(opts.verbose_name)
# Display a link to the admin page.
15 tests/admin_views/tests.py
View
@@ -15,6 +15,7 @@
from django.core.urlresolvers import reverse
# Register auth models with the admin.
from django.contrib import admin
+from django.contrib.auth import get_permission_codename
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
from django.contrib.admin.models import LogEntry, DELETION
from django.contrib.admin.sites import LOGIN_FORM_KEY
@@ -854,20 +855,20 @@ def setUp(self):
# User who can add Articles
add_user = User.objects.get(username='adduser')
add_user.user_permissions.add(get_perm(Article,
- opts.get_add_permission()))
+ get_permission_codename('add', opts)))
# User who can change Articles
change_user = User.objects.get(username='changeuser')
change_user.user_permissions.add(get_perm(Article,
- opts.get_change_permission()))
+ get_permission_codename('change', opts)))
# User who can delete Articles
delete_user = User.objects.get(username='deleteuser')
delete_user.user_permissions.add(get_perm(Article,
- opts.get_delete_permission()))
+ get_permission_codename('delete', opts)))
delete_user.user_permissions.add(get_perm(Section,
- Section._meta.get_delete_permission()))
+ get_permission_codename('delete', Section._meta)))
# login POST dicts
self.super_login = {
@@ -1210,7 +1211,7 @@ def testConditionallyShowAddSectionLink(self):
# Allow the add user to add sections too. Now they can see the "add
# section" link.
add_user = User.objects.get(username='adduser')
- perm = get_perm(Section, Section._meta.get_add_permission())
+ perm = get_perm(Section, get_permission_codename('add', Section._meta))
add_user.user_permissions.add(perm)
response = self.client.get(url)
self.assertContains(response, add_link_text)
@@ -1315,7 +1316,7 @@ def setUp(self):
# User who can change Reports
change_user = User.objects.get(username='changeuser')
change_user.user_permissions.add(get_perm(Report,
- opts.get_change_permission()))
+ get_permission_codename('change', opts)))
# login POST dict
self.changeuser_login = {
@@ -1372,7 +1373,7 @@ def test_perms_needed(self):
self.client.logout()
delete_user = User.objects.get(username='deleteuser')
delete_user.user_permissions.add(get_perm(Plot,
- Plot._meta.get_delete_permission()))
+ get_permission_codename('delete', Plot._meta)))
self.assertTrue(self.client.login(username='deleteuser',
password='secret'))
Please sign in to comment.
Something went wrong with that request. Please try again.