# HG changeset patch # User Brian Neal # Date 1744677048 18000 # Node ID 51172fb756f40e55f2600c682bdbb8522fa43958 # Parent c3fad620c08a92ee3d0ddfe23bbf835d6470cb5f Add more tests for core.html. diff -r c3fad620c08a -r 51172fb756f4 core/tests/test_html.py --- a/core/tests/test_html.py Mon Apr 14 19:07:56 2025 -0500 +++ b/core/tests/test_html.py Mon Apr 14 19:30:48 2025 -0500 @@ -1,6 +1,9 @@ """Tests for the core.html module.""" import unittest +from mock import call, patch + +from core.html import clean_html, _CLEAN_PROFILES from core.html import ImageCheckError from core.html import image_check @@ -74,3 +77,32 @@ def test_whitespace(self): result = image_check('\r\n\r\n') self.assertTrue(result) + + +class CleanHtmlTestCase(unittest.TestCase): + def test_all_whitespace(self): + text = ' \t \n ' + result = clean_html(text) + self.assertEqual(result, '') + + @patch('core.html.bleach.clean') + def test_comments(self, clean_mock): + text = ' Lorem ipsum ' + result = clean_html(text) + self.assertEqual(clean_mock.mock_calls, [ + call('Lorem ipsum', tags=_CLEAN_PROFILES['comments'][0], + attributes=_CLEAN_PROFILES['comments'][1], + styles=_CLEAN_PROFILES['comments'][2], strip=True, + strip_comments=True), + ]) + + @patch('core.html.bleach.clean') + def test_comments(self, clean_mock): + text = ' Lorem ipsum ' + result = clean_html(text, profile='news') + self.assertEqual(clean_mock.mock_calls, [ + call('Lorem ipsum', tags=_CLEAN_PROFILES['news'][0], + attributes=_CLEAN_PROFILES['news'][1], + styles=_CLEAN_PROFILES['news'][2], strip=True, + strip_comments=True), + ])