from django.template.defaultfilters import removetags from django.test import SimpleTestCase, ignore_warnings from django.utils.deprecation import RemovedInDjango20Warning from django.utils.safestring import mark_safe from ..utils import setup @ignore_warnings(category=RemovedInDjango20Warning) class RemovetagsTests(SimpleTestCase): @setup({'removetags01': '{{ a|removetags:"a b" }} {{ b|removetags:"a b" }}'}) def test_removetags01(self): output = self.engine.render_to_string( 'removetags01', { 'a': 'x

y

', 'b': mark_safe('x

y

'), }, ) self.assertEqual(output, 'x <p>y</p> x

y

') @setup({'removetags02': '{% autoescape off %}{{ a|removetags:"a b" }} {{ b|removetags:"a b" }}{% endautoescape %}'}) def test_removetags02(self): output = self.engine.render_to_string( 'removetags02', { 'a': 'x

y

', 'b': mark_safe('x

y

'), }, ) self.assertEqual(output, 'x

y

x

y

') @ignore_warnings(category=RemovedInDjango20Warning) class FunctionTests(SimpleTestCase): def test_removetags(self): self.assertEqual( removetags( 'some html with disallowed tags', 'script img', ), 'some html with alert("You smell") disallowed tags', ) def test_non_string_input(self): self.assertEqual(removetags(123, 'a'), '123')