1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #15206 -- Added select_related call to the permissions field of the GroupAdmin to lower the number of queries. Thanks, Chris Adams.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16620 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jannis Leidel
2011-08-15 09:01:12 +00:00
parent d37e3baf62
commit 283526a5a6
2 changed files with 48 additions and 1 deletions

View File

@@ -12,7 +12,7 @@ from django.core.files import temp as tempfile
from django.core.urlresolvers import reverse
# Register auth models with the admin.
from django.contrib.auth import REDIRECT_FIELD_NAME, admin
from django.contrib.auth.models import User, Permission, UNUSABLE_PASSWORD
from django.contrib.auth.models import Group, User, Permission, UNUSABLE_PASSWORD
from django.contrib.contenttypes.models import ContentType
from django.contrib.admin.models import LogEntry, DELETION
from django.contrib.admin.sites import LOGIN_FORM_KEY
@@ -2911,6 +2911,44 @@ class UserAdminTest(TestCase):
self.assertEqual(User.objects.count(), user_count + 1)
self.assertNotEqual(new_user.password, UNUSABLE_PASSWORD)
def test_user_permission_performance(self):
u = User.objects.all()[0]
with self.assertNumQueries(7):
response = self.client.get('/test_admin/admin/auth/user/%s/' % u.pk)
self.assertEqual(response.status_code, 200)
class GroupAdminTest(TestCase):
"""
Tests group CRUD functionality.
"""
fixtures = ['admin-views-users.xml']
def setUp(self):
self.client.login(username='super', password='secret')
def tearDown(self):
self.client.logout()
def test_save_button(self):
group_count = Group.objects.count()
response = self.client.post('/test_admin/admin/auth/group/add/', {
'name': 'newgroup',
})
new_group = Group.objects.order_by('-id')[0]
self.assertRedirects(response, '/test_admin/admin/auth/group/')
self.assertEqual(Group.objects.count(), group_count + 1)
def test_group_permission_performance(self):
g = Group.objects.create(name="test_group")
with self.assertNumQueries(6): # instead of 259!
response = self.client.get('/test_admin/admin/auth/group/%s/' % g.pk)
self.assertEqual(response.status_code, 200)
try:
import docutils
except ImportError: