Replaced some more hardcoded admin URLs
This commit is contained in:
parent
c5d1a5ef5c
commit
50aa1a790c
|
@ -8,6 +8,7 @@ from django.contrib.auth.forms import (
|
|||
)
|
||||
from django.contrib.auth.models import Group, User
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.db import transaction
|
||||
from django.http import Http404, HttpResponseRedirect
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
@ -133,7 +134,9 @@ class UserAdmin(admin.ModelAdmin):
|
|||
msg = ugettext('Password changed successfully.')
|
||||
messages.success(request, msg)
|
||||
update_session_auth_hash(request, form.user)
|
||||
return HttpResponseRedirect('..')
|
||||
return HttpResponseRedirect(
|
||||
reverse('%s:auth_user_change' % self.admin_site.name, args=(user.pk,))
|
||||
)
|
||||
else:
|
||||
form = self.change_password_form(user)
|
||||
|
||||
|
|
|
@ -861,32 +861,39 @@ class ChangelistTests(AuthViewsTestCase):
|
|||
def test_changelist_disallows_password_lookups(self):
|
||||
# A lookup that tries to filter on password isn't OK
|
||||
with patch_logger('django.security.DisallowedModelAdminLookup', 'error') as logger_calls:
|
||||
response = self.client.get('/admin/auth/user/?password__startswith=sha1$')
|
||||
response = self.client.get(reverse('auth_test_admin:auth_user_changelist') + '?password__startswith=sha1$')
|
||||
self.assertEqual(response.status_code, 400)
|
||||
self.assertEqual(len(logger_calls), 1)
|
||||
|
||||
def test_user_change_email(self):
|
||||
data = self.get_user_data(self.admin)
|
||||
data['email'] = 'new_' + data['email']
|
||||
response = self.client.post('/admin/auth/user/%s/' % self.admin.pk, data)
|
||||
self.assertRedirects(response, '/admin/auth/user/')
|
||||
response = self.client.post(
|
||||
reverse('auth_test_admin:auth_user_change', args=(self.admin.pk,)),
|
||||
data
|
||||
)
|
||||
self.assertRedirects(response, reverse('auth_test_admin:auth_user_changelist'))
|
||||
row = LogEntry.objects.latest('id')
|
||||
self.assertEqual(row.change_message, 'Changed email.')
|
||||
|
||||
def test_user_not_change(self):
|
||||
response = self.client.post('/admin/auth/user/%s/' % self.admin.pk,
|
||||
response = self.client.post(
|
||||
reverse('auth_test_admin:auth_user_change', args=(self.admin.pk,)),
|
||||
self.get_user_data(self.admin)
|
||||
)
|
||||
self.assertRedirects(response, '/admin/auth/user/')
|
||||
self.assertRedirects(response, reverse('auth_test_admin:auth_user_changelist'))
|
||||
row = LogEntry.objects.latest('id')
|
||||
self.assertEqual(row.change_message, 'No fields changed.')
|
||||
|
||||
def test_user_change_password(self):
|
||||
response = self.client.post('/admin/auth/user/%s/password/' % self.admin.pk, {
|
||||
'password1': 'password1',
|
||||
'password2': 'password1',
|
||||
})
|
||||
self.assertRedirects(response, '/admin/auth/user/%s/' % self.admin.pk)
|
||||
response = self.client.post(
|
||||
reverse('auth_test_admin:auth_user_password_change', args=(self.admin.pk,)),
|
||||
{
|
||||
'password1': 'password1',
|
||||
'password2': 'password1',
|
||||
}
|
||||
)
|
||||
self.assertRedirects(response, reverse('auth_test_admin:auth_user_change', args=(self.admin.pk,)))
|
||||
row = LogEntry.objects.latest('id')
|
||||
self.assertEqual(row.change_message, 'Changed password.')
|
||||
self.logout()
|
||||
|
@ -894,11 +901,14 @@ class ChangelistTests(AuthViewsTestCase):
|
|||
|
||||
def test_user_change_different_user_password(self):
|
||||
u = User.objects.get(email='staffmember@example.com')
|
||||
response = self.client.post('/admin/auth/user/%s/password/' % u.pk, {
|
||||
'password1': 'password1',
|
||||
'password2': 'password1',
|
||||
})
|
||||
self.assertRedirects(response, '/admin/auth/user/%s/' % u.pk)
|
||||
response = self.client.post(
|
||||
reverse('auth_test_admin:auth_user_password_change', args=(u.pk,)),
|
||||
{
|
||||
'password1': 'password1',
|
||||
'password2': 'password1',
|
||||
}
|
||||
)
|
||||
self.assertRedirects(response, reverse('auth_test_admin:auth_user_change', args=(u.pk,)))
|
||||
row = LogEntry.objects.latest('id')
|
||||
self.assertEqual(row.user_id, self.admin.pk)
|
||||
self.assertEqual(row.object_id, str(u.pk))
|
||||
|
|
|
@ -6,6 +6,7 @@ from django.contrib.admin.sites import AdminSite
|
|||
from django.contrib.auth.models import User
|
||||
from django.contrib.contenttypes.admin import GenericTabularInline
|
||||
from django.contrib.contenttypes.forms import generic_inlineformset_factory
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.forms.formsets import DEFAULT_MAX_NUM
|
||||
from django.forms.models import ModelForm
|
||||
from django.test import RequestFactory, TestCase, override_settings
|
||||
|
@ -42,14 +43,16 @@ class GenericAdminViewTest(TestCase):
|
|||
"""
|
||||
A smoke test to ensure GET on the add_view works.
|
||||
"""
|
||||
response = self.client.get('/generic_inline_admin/admin/generic_inline_admin/episode/add/')
|
||||
response = self.client.get(reverse('admin:generic_inline_admin_episode_add'))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_basic_edit_GET(self):
|
||||
"""
|
||||
A smoke test to ensure GET on the change_view works.
|
||||
"""
|
||||
response = self.client.get('/generic_inline_admin/admin/generic_inline_admin/episode/%d/' % self.episode_pk)
|
||||
response = self.client.get(
|
||||
reverse('admin:generic_inline_admin_episode_change', args=(self.episode_pk,))
|
||||
)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_basic_add_POST(self):
|
||||
|
@ -63,7 +66,7 @@ class GenericAdminViewTest(TestCase):
|
|||
"generic_inline_admin-media-content_type-object_id-INITIAL_FORMS": "0",
|
||||
"generic_inline_admin-media-content_type-object_id-MAX_NUM_FORMS": "0",
|
||||
}
|
||||
response = self.client.post('/generic_inline_admin/admin/generic_inline_admin/episode/add/', post_data)
|
||||
response = self.client.post(reverse('admin:generic_inline_admin_episode_add'), post_data)
|
||||
self.assertEqual(response.status_code, 302) # redirect somewhere
|
||||
|
||||
def test_basic_edit_POST(self):
|
||||
|
@ -83,7 +86,7 @@ class GenericAdminViewTest(TestCase):
|
|||
"generic_inline_admin-media-content_type-object_id-2-id": "",
|
||||
"generic_inline_admin-media-content_type-object_id-2-url": "",
|
||||
}
|
||||
url = '/generic_inline_admin/admin/generic_inline_admin/episode/%d/' % self.episode_pk
|
||||
url = reverse('admin:generic_inline_admin_episode_change', args=(self.episode_pk,))
|
||||
response = self.client.post(url, post_data)
|
||||
self.assertEqual(response.status_code, 302) # redirect somewhere
|
||||
|
||||
|
@ -147,7 +150,7 @@ class GenericInlineAdminParametersTest(TestCase):
|
|||
With one initial form, extra (default) at 3, there should be 4 forms.
|
||||
"""
|
||||
e = self._create_object(Episode)
|
||||
response = self.client.get('/generic_inline_admin/admin/generic_inline_admin/episode/%s/' % e.pk)
|
||||
response = self.client.get(reverse('admin:generic_inline_admin_episode_change', args=(e.pk,)))
|
||||
formset = response.context['inline_admin_formsets'][0].formset
|
||||
self.assertEqual(formset.total_form_count(), 4)
|
||||
self.assertEqual(formset.initial_form_count(), 1)
|
||||
|
@ -164,7 +167,7 @@ class GenericInlineAdminParametersTest(TestCase):
|
|||
modeladmin.inlines = [ExtraInline]
|
||||
|
||||
e = self._create_object(Episode)
|
||||
request = self.factory.get('/generic_inline_admin/admin/generic_inline_admin/episode/%s/' % e.pk)
|
||||
request = self.factory.get(reverse('admin:generic_inline_admin_episode_change', args=(e.pk,)))
|
||||
request.user = User(username='super', is_superuser=True)
|
||||
response = modeladmin.changeform_view(request, object_id=str(e.pk))
|
||||
formset = response.context_data['inline_admin_formsets'][0].formset
|
||||
|
@ -184,7 +187,7 @@ class GenericInlineAdminParametersTest(TestCase):
|
|||
modeladmin.inlines = [MaxNumInline]
|
||||
|
||||
e = self._create_object(Episode)
|
||||
request = self.factory.get('/generic_inline_admin/admin/generic_inline_admin/episode/%s/' % e.pk)
|
||||
request = self.factory.get(reverse('admin:generic_inline_admin_episode_change', args=(e.pk,)))
|
||||
request.user = User(username='super', is_superuser=True)
|
||||
response = modeladmin.changeform_view(request, object_id=str(e.pk))
|
||||
formset = response.context_data['inline_admin_formsets'][0].formset
|
||||
|
@ -204,7 +207,7 @@ class GenericInlineAdminParametersTest(TestCase):
|
|||
modeladmin.inlines = [MinNumInline]
|
||||
|
||||
e = self._create_object(Episode)
|
||||
request = self.factory.get('/generic_inline_admin/admin/generic_inline_admin/episode/%s/' % e.pk)
|
||||
request = self.factory.get(reverse('admin:generic_inline_admin_episode_change', args=(e.pk,)))
|
||||
request.user = User(username='super', is_superuser=True)
|
||||
response = modeladmin.changeform_view(request, object_id=str(e.pk))
|
||||
formset = response.context_data['inline_admin_formsets'][0].formset
|
||||
|
@ -223,7 +226,7 @@ class GenericInlineAdminParametersTest(TestCase):
|
|||
modeladmin = admin.ModelAdmin(Episode, admin_site)
|
||||
modeladmin.inlines = [GetExtraInline]
|
||||
e = self._create_object(Episode)
|
||||
request = self.factory.get('/generic_inline_admin/admin/generic_inline_admin/episode/%s/' % e.pk)
|
||||
request = self.factory.get(reverse('admin:generic_inline_admin_episode_change', args=(e.pk,)))
|
||||
request.user = User(username='super', is_superuser=True)
|
||||
response = modeladmin.changeform_view(request, object_id=str(e.pk))
|
||||
formset = response.context_data['inline_admin_formsets'][0].formset
|
||||
|
@ -242,7 +245,7 @@ class GenericInlineAdminParametersTest(TestCase):
|
|||
modeladmin = admin.ModelAdmin(Episode, admin_site)
|
||||
modeladmin.inlines = [GetMinNumInline]
|
||||
e = self._create_object(Episode)
|
||||
request = self.factory.get('/generic_inline_admin/admin/generic_inline_admin/episode/%s/' % e.pk)
|
||||
request = self.factory.get(reverse('admin:generic_inline_admin_episode_change', args=(e.pk,)))
|
||||
request.user = User(username='super', is_superuser=True)
|
||||
response = modeladmin.changeform_view(request, object_id=str(e.pk))
|
||||
formset = response.context_data['inline_admin_formsets'][0].formset
|
||||
|
@ -261,7 +264,7 @@ class GenericInlineAdminParametersTest(TestCase):
|
|||
modeladmin = admin.ModelAdmin(Episode, admin_site)
|
||||
modeladmin.inlines = [GetMaxNumInline]
|
||||
e = self._create_object(Episode)
|
||||
request = self.factory.get('/generic_inline_admin/admin/generic_inline_admin/episode/%s/' % e.pk)
|
||||
request = self.factory.get(reverse('admin:generic_inline_admin_episode_change', args=(e.pk,)))
|
||||
request.user = User(username='super', is_superuser=True)
|
||||
response = modeladmin.changeform_view(request, object_id=str(e.pk))
|
||||
formset = response.context_data['inline_admin_formsets'][0].formset
|
||||
|
@ -289,9 +292,9 @@ class GenericInlineAdminWithUniqueTogetherTest(TestCase):
|
|||
"generic_inline_admin-phonenumber-content_type-object_id-0-phone_number": "555-555-5555",
|
||||
"generic_inline_admin-phonenumber-content_type-object_id-0-category": "%s" % category_id,
|
||||
}
|
||||
response = self.client.get('/generic_inline_admin/admin/generic_inline_admin/contact/add/')
|
||||
response = self.client.get(reverse('admin:generic_inline_admin_contact_add'))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
response = self.client.post('/generic_inline_admin/admin/generic_inline_admin/contact/add/', post_data)
|
||||
response = self.client.post(reverse('admin:generic_inline_admin_contact_add'), post_data)
|
||||
self.assertEqual(response.status_code, 302) # redirect somewhere
|
||||
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ from django.apps import apps
|
|||
from django.contrib import admin
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core import checks, management
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.db import DEFAULT_DB_ALIAS, models
|
||||
from django.db.models import signals
|
||||
from django.test import TestCase, override_settings
|
||||
|
@ -408,17 +409,18 @@ class ProxyModelAdminTests(TestCase):
|
|||
user = TrackerUser.objects.get(name='Django Pony')
|
||||
proxy = ProxyTrackerUser.objects.get(name='Django Pony')
|
||||
|
||||
user_str = (
|
||||
'Tracker user: <a href="/admin/proxy_models/trackeruser/%s/">%s</a>' % (user.pk, user))
|
||||
proxy_str = (
|
||||
'Proxy tracker user: <a href="/admin/proxy_models/proxytrackeruser/%s/">%s</a>' %
|
||||
(proxy.pk, proxy))
|
||||
user_str = 'Tracker user: <a href="%s">%s</a>' % (
|
||||
reverse('admin:proxy_models_trackeruser_change', args=(user.pk,)), user
|
||||
)
|
||||
proxy_str = 'Proxy tracker user: <a href="%s">%s</a>' % (
|
||||
reverse('admin:proxy_models_proxytrackeruser_change', args=(proxy.pk,)), proxy
|
||||
)
|
||||
|
||||
self.client.login(username='super', password='secret')
|
||||
response = self.client.get('/admin/proxy_models/trackeruser/%s/delete/' % (user.pk,))
|
||||
response = self.client.get(reverse('admin:proxy_models_trackeruser_delete', args=(user.pk,)))
|
||||
delete_str = response.context['deleted_objects'][0]
|
||||
self.assertEqual(delete_str, user_str)
|
||||
response = self.client.get('/admin/proxy_models/proxytrackeruser/%s/delete/' % (proxy.pk,))
|
||||
response = self.client.get(reverse('admin:proxy_models_proxytrackeruser_delete', args=(proxy.pk,)))
|
||||
delete_str = response.context['deleted_objects'][0]
|
||||
self.assertEqual(delete_str, proxy_str)
|
||||
self.client.logout()
|
||||
|
|
Loading…
Reference in New Issue