diff options
| author | Thomas Grainger <tom@yplanapp.com> | 2015-11-23 10:46:19 +0000 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-12-05 15:51:57 -0500 |
| commit | d638cdc42acec608c1967f44af6be32a477c239f (patch) | |
| tree | 44e102c555476dae8f2f339b6fa11bb57f982386 /tests/admin_views | |
| parent | 105028eec64064c11dfd3d5415317ba1fab81214 (diff) | |
Fixed #25165 -- Removed inline JavaScript from the admin.
This allows setting a Content-Security-Policy HTTP header
(refs #15727).
Special thanks to blighj, the original author of this patch.
Diffstat (limited to 'tests/admin_views')
| -rw-r--r-- | tests/admin_views/tests.py | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index 7ccaf75c6a..db960b34b0 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals import datetime +import json import os import re import unittest @@ -260,8 +261,7 @@ class AdminViewBasicTest(AdminViewBasicTestCase): 'date_1': '14:55:39', } response = self.client.post(reverse('admin:admin_views_article_add'), post_data) - self.assertContains(response, 'dismissAddRelatedObjectPopup') - self.assertContains(response, 'title with a new\\u000Aline') + self.assertContains(response, 'title with a new\\nline') def test_basic_edit_POST(self): """ @@ -734,7 +734,7 @@ class AdminViewBasicTest(AdminViewBasicTestCase): """ actor = Actor.objects.create(name="Palin", age=27) response = self.client.get("%s?%s" % (reverse('admin:admin_views_actor_changelist'), IS_POPUP_VAR)) - self.assertContains(response, "opener.dismissRelatedLookupPopup(window, '%s')" % actor.pk) + self.assertContains(response, 'data-popup-opener="%s"' % actor.pk) def test_hide_change_password(self): """ @@ -3445,27 +3445,23 @@ action)</option> self.assertEqual(response.template_name, 'admin/popup_response.html') def test_popup_template_escaping(self): - context = { + popup_response_data = json.dumps({ 'new_value': 'new_value\\', 'obj': 'obj\\', 'value': 'value\\', + }) + context = { + 'popup_response_data': popup_response_data, } output = render_to_string('admin/popup_response.html', context) self.assertIn( - 'opener.dismissAddRelatedObjectPopup(window, "value\\u005C", "obj\\u005C");', output + r'"value\\"', output ) - - context['action'] = 'change' - output = render_to_string('admin/popup_response.html', context) self.assertIn( - 'opener.dismissChangeRelatedObjectPopup(window, ' - '"value\\u005C", "obj\\u005C", "new_value\\u005C");', output + r'"new_value\\"', output ) - - context['action'] = 'delete' - output = render_to_string('admin/popup_response.html', context) self.assertIn( - 'opener.dismissDeleteRelatedObjectPopup(window, "value\\u005C");', output + r'"obj\\"', output ) @@ -4273,16 +4269,19 @@ class PrePopulatedTest(TestCase): def test_prepopulated_on(self): response = self.client.get(reverse('admin:admin_views_prepopulatedpost_add')) - self.assertContains(response, "id: '#id_slug',") - self.assertContains(response, "field['dependency_ids'].push('#id_title');") - self.assertContains(response, "id: '#id_prepopulatedsubpost_set-0-subslug',") + self.assertContains(response, ""id": "#id_slug"") + self.assertContains(response, ""dependency_ids": ["#id_title"]") + self.assertContains(response, ""id": "#id_prepopulatedsubpost_set-0-subslug"") def test_prepopulated_off(self): response = self.client.get(reverse('admin:admin_views_prepopulatedpost_change', args=(self.p1.pk,))) self.assertContains(response, "A Long Title") - self.assertNotContains(response, "id: '#id_slug'") - self.assertNotContains(response, "field['dependency_ids'].push('#id_title');") - self.assertNotContains(response, "id: '#id_prepopulatedsubpost_set-0-subslug',") + self.assertNotContains(response, ""id": "#id_slug"") + self.assertNotContains(response, ""dependency_ids": ["#id_title"]") + self.assertNotContains( + response, + ""id": "#id_prepopulatedsubpost_set-0-subslug"" + ) @override_settings(USE_THOUSAND_SEPARATOR=True, USE_L10N=True) def test_prepopulated_maxlength_localized(self): @@ -4291,7 +4290,7 @@ class PrePopulatedTest(TestCase): that maxLength (in the JavaScript) is rendered without separators. """ response = self.client.get(reverse('admin:admin_views_prepopulatedpostlargeslug_add')) - self.assertContains(response, "maxLength: 1000") # instead of 1,000 + self.assertContains(response, ""maxLength": 1000") # instead of 1,000 @override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @@ -4933,7 +4932,7 @@ class UserAdminTest(TestCase): '_save': '1', } response = self.client.post(reverse('admin:auth_user_add') + '?_popup=1', data, follow=True) - self.assertContains(response, 'dismissAddRelatedObjectPopup') + self.assertContains(response, '"obj": "newuser"') def test_user_fk_change_popup(self): """User change through a FK popup should return the appropriate JavaScript response.""" @@ -4957,7 +4956,8 @@ class UserAdminTest(TestCase): '_save': '1', } response = self.client.post(url, data, follow=True) - self.assertContains(response, 'dismissChangeRelatedObjectPopup') + self.assertContains(response, '"obj": "newuser"') + self.assertContains(response, '"action": "change"') def test_user_fk_delete_popup(self): """User deletion through a FK popup should return the appropriate JavaScript response.""" @@ -4973,7 +4973,7 @@ class UserAdminTest(TestCase): '_popup': '1', } response = self.client.post(url, data, follow=True) - self.assertContains(response, 'dismissDeleteRelatedObjectPopup') + self.assertContains(response, '"action": "delete"') def test_save_add_another_button(self): user_count = User.objects.count() |
