Updated tests for deprecation of Option.get_(add|change|delete)_permission.

refs #20642.
This commit is contained in:
Tim Graham 2013-07-01 09:19:55 -04:00
parent cfcf4b3605
commit a6a905c619
2 changed files with 10 additions and 8 deletions

View File

@ -3,6 +3,7 @@ from __future__ import unicode_literals
import datetime import datetime
import decimal import decimal
from django.contrib.auth import get_permission_codename
from django.db import models from django.db import models
from django.db.models.constants import LOOKUP_SEP from django.db.models.constants import LOOKUP_SEP
from django.db.models.deletion import Collector from django.db.models.deletion import Collector
@ -119,7 +120,7 @@ def get_deleted_objects(objs, opts, user, admin_site, using):
opts.model_name), opts.model_name),
None, (quote(obj._get_pk_val()),)) None, (quote(obj._get_pk_val()),))
p = '%s.%s' % (opts.app_label, p = '%s.%s' % (opts.app_label,
opts.get_delete_permission()) get_permission_codename('delete', opts))
if not user.has_perm(p): if not user.has_perm(p):
perms_needed.add(opts.verbose_name) perms_needed.add(opts.verbose_name)
# Display a link to the admin page. # Display a link to the admin page.

View File

@ -15,6 +15,7 @@ from django.core.files import temp as tempfile
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
# Register auth models with the admin. # Register auth models with the admin.
from django.contrib import 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.helpers import ACTION_CHECKBOX_NAME
from django.contrib.admin.models import LogEntry, DELETION from django.contrib.admin.models import LogEntry, DELETION
from django.contrib.admin.sites import LOGIN_FORM_KEY from django.contrib.admin.sites import LOGIN_FORM_KEY
@ -854,20 +855,20 @@ class AdminViewPermissionsTest(TestCase):
# User who can add Articles # User who can add Articles
add_user = User.objects.get(username='adduser') add_user = User.objects.get(username='adduser')
add_user.user_permissions.add(get_perm(Article, add_user.user_permissions.add(get_perm(Article,
opts.get_add_permission())) get_permission_codename('add', opts)))
# User who can change Articles # User who can change Articles
change_user = User.objects.get(username='changeuser') change_user = User.objects.get(username='changeuser')
change_user.user_permissions.add(get_perm(Article, change_user.user_permissions.add(get_perm(Article,
opts.get_change_permission())) get_permission_codename('change', opts)))
# User who can delete Articles # User who can delete Articles
delete_user = User.objects.get(username='deleteuser') delete_user = User.objects.get(username='deleteuser')
delete_user.user_permissions.add(get_perm(Article, 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, delete_user.user_permissions.add(get_perm(Section,
Section._meta.get_delete_permission())) get_permission_codename('delete', Section._meta)))
# login POST dicts # login POST dicts
self.super_login = { self.super_login = {
@ -1210,7 +1211,7 @@ class AdminViewPermissionsTest(TestCase):
# Allow the add user to add sections too. Now they can see the "add # Allow the add user to add sections too. Now they can see the "add
# section" link. # section" link.
add_user = User.objects.get(username='adduser') 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) add_user.user_permissions.add(perm)
response = self.client.get(url) response = self.client.get(url)
self.assertContains(response, add_link_text) self.assertContains(response, add_link_text)
@ -1315,7 +1316,7 @@ class AdminViewsNoUrlTest(TestCase):
# User who can change Reports # User who can change Reports
change_user = User.objects.get(username='changeuser') change_user = User.objects.get(username='changeuser')
change_user.user_permissions.add(get_perm(Report, change_user.user_permissions.add(get_perm(Report,
opts.get_change_permission())) get_permission_codename('change', opts)))
# login POST dict # login POST dict
self.changeuser_login = { self.changeuser_login = {
@ -1372,7 +1373,7 @@ class AdminViewDeletedObjectsTest(TestCase):
self.client.logout() self.client.logout()
delete_user = User.objects.get(username='deleteuser') delete_user = User.objects.get(username='deleteuser')
delete_user.user_permissions.add(get_perm(Plot, 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', self.assertTrue(self.client.login(username='deleteuser',
password='secret')) password='secret'))