diff options
| author | Ramiro Morales <cramm0@gmail.com> | 2012-08-26 17:54:49 -0300 |
|---|---|---|
| committer | Ramiro Morales <cramm0@gmail.com> | 2012-08-26 17:54:49 -0300 |
| commit | 5a9e127efc37490b2a1caa605e987a693245b5fa (patch) | |
| tree | 26ac4a48e5b74e90a3c9afd078941aa23c7eb930 /tests/regressiontests/admin_custom_urls | |
| parent | c73f2bd65c8a94b9d52b6684e0d7fb0055401daa (diff) | |
Made model instance history admin view link not hard-coded. Refs #15294.
Diffstat (limited to 'tests/regressiontests/admin_custom_urls')
| -rw-r--r-- | tests/regressiontests/admin_custom_urls/fixtures/actions.json | 9 | ||||
| -rw-r--r-- | tests/regressiontests/admin_custom_urls/tests.py | 38 |
2 files changed, 37 insertions, 10 deletions
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 + '<app name>/<model name>/!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, '<a href="%s" class="historylink"' % + expected_link) |
