summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorOla Sitarska <ola@sitarska.com>2015-09-08 20:46:26 +0100
committerTim Graham <timograham@gmail.com>2015-09-08 19:13:43 -0400
commitf2f8972def26cea2b0e8dbe763e11436d194e3d4 (patch)
tree7dc7a636008d1a968780540279d2cdad41f2f1bc /tests
parent1bbca7961cee20c4ddd453a7d74d316e84f4bbb5 (diff)
Fixed #25135 -- Deprecated the contrib.admin allow_tags attribute.
Thanks Jaap Roes for the idea and initial patch.
Diffstat (limited to 'tests')
-rw-r--r--tests/admin_changelist/tests.py37
-rw-r--r--tests/admin_views/admin.py13
-rw-r--r--tests/admin_views/tests.py10
3 files changed, 51 insertions, 9 deletions
diff --git a/tests/admin_changelist/tests.py b/tests/admin_changelist/tests.py
index 86682581b9..5e773bcb9a 100644
--- a/tests/admin_changelist/tests.py
+++ b/tests/admin_changelist/tests.py
@@ -12,9 +12,10 @@ from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.core.urlresolvers import reverse
from django.template import Context, Template
-from django.test import TestCase, override_settings
+from django.test import TestCase, ignore_warnings, override_settings
from django.test.client import RequestFactory
from django.utils import formats, six
+from django.utils.deprecation import RemovedInDjango20Warning
from .admin import (
BandAdmin, ChildAdmin, ChordsBandAdmin, ConcertAdmin,
@@ -168,7 +169,7 @@ class ChangeListTests(TestCase):
link = reverse('admin:admin_changelist_child_change', args=(new_child.id,))
row_html = (
'<tbody><tr class="row1"><th class="field-name"><a href="%s">name</a></th>'
- '<td class="field-age_display">&dagger;</td><td class="field-age">-empty-</td></tr></tbody>' % link
+ '<td class="field-age_display">&amp;dagger;</td><td class="field-age">-empty-</td></tr></tbody>' % link
)
self.assertNotEqual(table_output.find(row_html), -1,
'Failed to find expected row element: %s' % table_output)
@@ -253,6 +254,38 @@ class ChangeListTests(TestCase):
m.list_filter, m.date_hierarchy, m.search_fields,
m.list_select_related, m.list_per_page, m.list_max_show_all, m.list_editable, m))
+ @ignore_warnings(category=RemovedInDjango20Warning)
+ def test_result_list_with_allow_tags(self):
+ """
+ Test for deprecation of allow_tags attribute
+ """
+ new_parent = Parent.objects.create(name='parent')
+ for i in range(2):
+ Child.objects.create(name='name %s' % i, parent=new_parent)
+ request = self.factory.get('/child/')
+ m = ChildAdmin(Child, custom_site)
+
+ def custom_method(self, obj=None):
+ return 'Unsafe html <br />'
+ custom_method.allow_tags = True
+
+ # Add custom method with allow_tags attribute
+ m.custom_method = custom_method
+ m.list_display = ['id', 'name', 'parent', 'custom_method']
+
+ cl = ChangeList(
+ request, Child, m.list_display, m.list_display_links,
+ m.list_filter, m.date_hierarchy, m.search_fields,
+ m.list_select_related, m.list_per_page, m.list_max_show_all, m.list_editable, m
+ )
+ FormSet = m.get_changelist_formset(request)
+ cl.formset = FormSet(queryset=cl.result_list)
+ template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}')
+ context = Context({'cl': cl})
+ table_output = template.render(context)
+ custom_field_html = '<td class="field-custom_method">Unsafe html <br /></td>'
+ self.assertInHTML(custom_field_html, table_output)
+
def test_custom_paginator(self):
new_parent = Parent.objects.create(name='parent')
for i in range(200):
diff --git a/tests/admin_views/admin.py b/tests/admin_views/admin.py
index c3cedf8444..0104181d96 100644
--- a/tests/admin_views/admin.py
+++ b/tests/admin_views/admin.py
@@ -18,6 +18,7 @@ from django.core.mail import EmailMessage
from django.db import models
from django.forms.models import BaseModelFormSet
from django.http import HttpResponse, StreamingHttpResponse
+from django.utils.html import format_html
from django.utils.safestring import mark_safe
from django.utils.six import StringIO
@@ -429,7 +430,8 @@ class PostAdmin(admin.ModelAdmin):
list_display = ['title', 'public']
readonly_fields = (
'posted', 'awesomeness_level', 'coolness', 'value',
- 'multiline', 'multiline_html', lambda obj: "foo"
+ 'multiline', 'multiline_html', lambda obj: "foo",
+ 'multiline_html_allow_tags',
)
inlines = [
@@ -444,15 +446,17 @@ class PostAdmin(admin.ModelAdmin):
def value(self, instance):
return 1000
+ value.short_description = 'Value in $US'
def multiline(self, instance):
return "Multiline\ntest\nstring"
def multiline_html(self, instance):
return mark_safe("Multiline<br>\nhtml<br>\ncontent")
- multiline_html.allow_tags = True
- value.short_description = 'Value in $US'
+ def multiline_html_allow_tags(self, instance):
+ return "Multiline<br>html<br>content<br>with allow tags"
+ multiline_html_allow_tags.allow_tags = True
class FieldOverridePostForm(forms.ModelForm):
@@ -574,8 +578,7 @@ class ComplexSortedPersonAdmin(admin.ModelAdmin):
ordering = ('name',)
def colored_name(self, obj):
- return '<span style="color: #%s;">%s</span>' % ('ff00ff', obj.name)
- colored_name.allow_tags = True
+ return format_html('<span style="color: #ff00ff;">{}</span>', obj.name)
colored_name.admin_order_field = 'name'
diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py
index 986add8479..942f033b6f 100644
--- a/tests/admin_views/tests.py
+++ b/tests/admin_views/tests.py
@@ -27,13 +27,14 @@ from django.forms.utils import ErrorList
from django.template.loader import render_to_string
from django.template.response import TemplateResponse
from django.test import (
- SimpleTestCase, TestCase, modify_settings, override_settings,
- skipUnlessDBFeature,
+ SimpleTestCase, TestCase, ignore_warnings, modify_settings,
+ override_settings, skipUnlessDBFeature,
)
from django.test.utils import override_script_prefix, patch_logger
from django.utils import formats, six, translation
from django.utils._os import upath
from django.utils.cache import get_max_age
+from django.utils.deprecation import RemovedInDjango20Warning
from django.utils.encoding import force_bytes, force_text, iri_to_uri
from django.utils.html import escape
from django.utils.http import urlencode
@@ -4681,6 +4682,7 @@ class ReadonlyTest(TestCase):
def setUp(self):
self.client.login(username='super', password='secret')
+ @ignore_warnings(category=RemovedInDjango20Warning) # for allow_tags deprecation
def test_readonly_get(self):
response = self.client.get(reverse('admin:admin_views_post_add'))
self.assertEqual(response.status_code, 200)
@@ -4699,6 +4701,8 @@ class ReadonlyTest(TestCase):
self.assertContains(response, "Multiline<br />test<br />string")
self.assertContains(response, "<p>Multiline<br />html<br />content</p>", html=True)
self.assertContains(response, "InlineMultiline<br />test<br />string")
+ # Remove only this last line when the deprecation completes.
+ self.assertContains(response, "<p>Multiline<br />html<br />content<br />with allow tags</p>", html=True)
self.assertContains(response,
formats.localize(datetime.date.today() - datetime.timedelta(days=7)))
@@ -4768,6 +4772,7 @@ class ReadonlyTest(TestCase):
response = self.client.get(reverse('admin:admin_views_topping_add'))
self.assertEqual(response.status_code, 200)
+ @ignore_warnings(category=RemovedInDjango20Warning) # for allow_tags deprecation
def test_readonly_field_overrides(self):
"""
Regression test for #22087 - ModelForm Meta overrides are ignored by
@@ -5181,6 +5186,7 @@ class CSSTest(TestCase):
def setUp(self):
self.client.login(username='super', password='secret')
+ @ignore_warnings(category=RemovedInDjango20Warning) # for allow_tags deprecation
def test_field_prefix_css_classes(self):
"""
Ensure that fields have a CSS class name with a 'field-' prefix.