diff options
| author | Scott Vitale <svvitale@gmail.com> | 2016-06-02 15:11:43 -0600 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-06-07 12:24:03 -0400 |
| commit | be729b6120a50fff28195c28896c83a9b1e0c355 (patch) | |
| tree | e7052cbc8c9c92989007e164dd959f94c5c83410 /tests/utils_tests/test_safestring.py | |
| parent | 5e3f4c2e53d9dde0fcf9f5f33f63c15c4750019f (diff) | |
Fixed #10107 -- Allowed using mark_safe() as a decorator.
Thanks ArcTanSusan for the initial patch.
Diffstat (limited to 'tests/utils_tests/test_safestring.py')
| -rw-r--r-- | tests/utils_tests/test_safestring.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/utils_tests/test_safestring.py b/tests/utils_tests/test_safestring.py index 6ea3972f78..6afcb3b1f7 100644 --- a/tests/utils_tests/test_safestring.py +++ b/tests/utils_tests/test_safestring.py @@ -109,3 +109,33 @@ class SafeStringTest(SimpleTestCase): s = text.slugify(lazystr('a')) s += mark_safe('&b') self.assertRenderEqual('{{ s }}', 'a&b', s=s) + + def test_mark_safe_as_decorator(self): + """ + mark_safe used as a decorator leaves the result of a function + unchanged. + """ + def clean_string_provider(): + return '<html><body>dummy</body></html>' + + self.assertEqual(mark_safe(clean_string_provider)(), clean_string_provider()) + + def test_mark_safe_decorator_does_not_affect_dunder_html(self): + """ + mark_safe doesn't affect a callable that has an __html__() method. + """ + class SafeStringContainer: + def __html__(self): + return '<html></html>' + + self.assertIs(mark_safe(SafeStringContainer), SafeStringContainer) + + def test_mark_safe_decorator_does_not_affect_promises(self): + """ + mark_safe doesn't affect lazy strings (Promise objects). + """ + def html_str(): + return '<html></html>' + + lazy_str = lazy(html_str, str)() + self.assertEqual(mark_safe(lazy_str), html_str()) |
