From 5a9e127efc37490b2a1caa605e987a693245b5fa Mon Sep 17 00:00:00 2001 From: Ramiro Morales Date: Sun, 26 Aug 2012 17:54:49 -0300 Subject: [PATCH] Made model instance history admin view link not hard-coded. Refs #15294. --- .../admin/templates/admin/change_form.html | 2 +- .../admin_custom_urls/fixtures/actions.json | 9 ++++- .../admin_custom_urls/tests.py | 38 ++++++++++++++----- 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/django/contrib/admin/templates/admin/change_form.html b/django/contrib/admin/templates/admin/change_form.html index 82d7296c85..e27875cdad 100644 --- a/django/contrib/admin/templates/admin/change_form.html +++ b/django/contrib/admin/templates/admin/change_form.html @@ -29,7 +29,7 @@ {% if change %}{% if not is_popup %} diff --git a/tests/regressiontests/admin_custom_urls/fixtures/actions.json b/tests/regressiontests/admin_custom_urls/fixtures/actions.json index d803393a12..a63cf8135c 100644 --- a/tests/regressiontests/admin_custom_urls/fixtures/actions.json +++ b/tests/regressiontests/admin_custom_urls/fixtures/actions.json @@ -40,5 +40,12 @@ "fields": { "description": "An action with a name suspected of being a XSS attempt" } + }, + { + "pk": "The name of an action", + "model": "admin_custom_urls.action", + "fields": { + "description": "A generic action" + } } -] \ No newline at end of file +] diff --git a/tests/regressiontests/admin_custom_urls/tests.py b/tests/regressiontests/admin_custom_urls/tests.py index 459f67c521..64ff9f6692 100644 --- a/tests/regressiontests/admin_custom_urls/tests.py +++ b/tests/regressiontests/admin_custom_urls/tests.py @@ -10,6 +10,12 @@ from .models import Action @override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',)) class AdminCustomUrlsTest(TestCase): + """ + Remember that: + * The Action model has a CharField PK. + * The ModelAdmin for Action customizes the add_view URL, it's + '//!add/' + """ fixtures = ['users.json', 'actions.json'] def setUp(self): @@ -20,20 +26,24 @@ class AdminCustomUrlsTest(TestCase): def testBasicAddGet(self): """ - A smoke test to ensure GET on the add_view works. + Ensure GET on the add_view works. """ response = self.client.get('/custom_urls/admin/admin_custom_urls/action/!add/') self.assertIsInstance(response, TemplateResponse) self.assertEqual(response.status_code, 200) def testAddWithGETArgs(self): + """ + Ensure GET on the add_view plus specifying a field value in the query + string works. + """ response = self.client.get('/custom_urls/admin/admin_custom_urls/action/!add/', {'name': 'My Action'}) self.assertEqual(response.status_code, 200) self.assertContains(response, 'value="My Action"') def testBasicAddPost(self): """ - A smoke test to ensure POST on add_view works. + Ensure POST on add_view works. """ post_data = { '_popup': '1', @@ -47,8 +57,7 @@ class AdminCustomUrlsTest(TestCase): def testAdminUrlsNoClash(self): """ - Test that some admin URLs work correctly. The model has a CharField - PK and the add_view URL has been customized. + Test that some admin URLs work correctly. """ # Should get the change_view for model instance with PK 'add', not show # the add_view @@ -57,17 +66,28 @@ class AdminCustomUrlsTest(TestCase): self.assertContains(response, 'Change action') # Ditto, but use reverse() to build the URL - path = reverse('admin:%s_action_change' % Action._meta.app_label, + url = reverse('admin:%s_action_change' % Action._meta.app_label, args=('add',)) - response = self.client.get(path) + response = self.client.get(url) self.assertEqual(response.status_code, 200) self.assertContains(response, 'Change action') # Should correctly get the change_view for the model instance with the - # funny-looking PK - path = reverse('admin:%s_action_change' % Action._meta.app_label, + # funny-looking PK (the one wth a 'path/to/html/document.html' value) + url = reverse('admin:%s_action_change' % Action._meta.app_label, args=("path/to/html/document.html",)) - response = self.client.get(path) + response = self.client.get(url) self.assertEqual(response.status_code, 200) self.assertContains(response, 'Change action') self.assertContains(response, 'value="path/to/html/document.html"') + + def testChangeViewHistoryButton(self): + url = reverse('admin:%s_action_change' % Action._meta.app_label, + args=('The name of an action',)) + response = self.client.get(url) + self.assertEqual(response.status_code, 200) + expected_link = reverse('admin:%s_action_history' % + Action._meta.app_label, + args=('The name of an action',)) + self.assertContains(response, '