diff options
| author | Nick Pope <nick@nickpope.me.uk> | 2021-04-22 16:55:59 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-07-23 12:36:21 +0200 |
| commit | 4d4bf55e0ea849476f7e3abfeb018c338f18a9b4 (patch) | |
| tree | 3eef7f8e90252c2f4f2c7ca9a07992af005e1744 /tests/template_tests | |
| parent | 2fac0a18081dcc77fc860c801e5d727dc90435b3 (diff) | |
Fixed #33864 -- Deprecated length_is template filter.
Diffstat (limited to 'tests/template_tests')
| -rw-r--r-- | tests/template_tests/filter_tests/test_length_is.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/tests/template_tests/filter_tests/test_length_is.py b/tests/template_tests/filter_tests/test_length_is.py index cbda46e5b1..5f24b2ab59 100644 --- a/tests/template_tests/filter_tests/test_length_is.py +++ b/tests/template_tests/filter_tests/test_length_is.py @@ -1,9 +1,11 @@ from django.template.defaultfilters import length_is -from django.test import SimpleTestCase +from django.test import SimpleTestCase, ignore_warnings +from django.utils.deprecation import RemovedInDjango51Warning from ..utils import setup +@ignore_warnings(category=RemovedInDjango51Warning) class LengthIsTests(SimpleTestCase): @setup({"length_is01": '{% if some_list|length_is:"4" %}Four{% endif %}'}) def test_length_is01(self): @@ -103,6 +105,7 @@ class LengthIsTests(SimpleTestCase): self.assertEqual(output, "") +@ignore_warnings(category=RemovedInDjango51Warning) class FunctionTests(SimpleTestCase): def test_empty_list(self): self.assertIs(length_is([], 0), True) @@ -111,3 +114,17 @@ class FunctionTests(SimpleTestCase): def test_string(self): self.assertIs(length_is("a", 1), True) self.assertIs(length_is("a", 10), False) + + +class DeprecationTests(SimpleTestCase): + @setup( + {"length_is_warning": "{{ string|length_is:3 }}"}, + test_once=True, + ) + def test_length_is_warning(self): + msg = ( + "The length_is template filter is deprecated in favor of the length " + "template filter and the == operator within an {% if %} tag." + ) + with self.assertRaisesMessage(RemovedInDjango51Warning, msg): + self.engine.render_to_string("length_is_warning", {"string": "good"}) |
