Mercurial > public > sg101
comparison core/tests/test_html.py @ 1229:51172fb756f4 modernize
Add more tests for core.html.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Mon, 14 Apr 2025 19:30:48 -0500 |
parents | 9b197dbba34b |
children |
comparison
equal
deleted
inserted
replaced
1228:c3fad620c08a | 1229:51172fb756f4 |
---|---|
1 """Tests for the core.html module.""" | 1 """Tests for the core.html module.""" |
2 import unittest | 2 import unittest |
3 | 3 |
4 from mock import call, patch | |
5 | |
6 from core.html import clean_html, _CLEAN_PROFILES | |
4 from core.html import ImageCheckError | 7 from core.html import ImageCheckError |
5 from core.html import image_check | 8 from core.html import image_check |
6 | 9 |
7 | 10 |
8 TEST_HTML = """ | 11 TEST_HTML = """ |
72 self.assertTrue(result) | 75 self.assertTrue(result) |
73 | 76 |
74 def test_whitespace(self): | 77 def test_whitespace(self): |
75 result = image_check('\r\n\r\n') | 78 result = image_check('\r\n\r\n') |
76 self.assertTrue(result) | 79 self.assertTrue(result) |
80 | |
81 | |
82 class CleanHtmlTestCase(unittest.TestCase): | |
83 def test_all_whitespace(self): | |
84 text = ' \t \n ' | |
85 result = clean_html(text) | |
86 self.assertEqual(result, '') | |
87 | |
88 @patch('core.html.bleach.clean') | |
89 def test_comments(self, clean_mock): | |
90 text = ' Lorem ipsum ' | |
91 result = clean_html(text) | |
92 self.assertEqual(clean_mock.mock_calls, [ | |
93 call('Lorem ipsum', tags=_CLEAN_PROFILES['comments'][0], | |
94 attributes=_CLEAN_PROFILES['comments'][1], | |
95 styles=_CLEAN_PROFILES['comments'][2], strip=True, | |
96 strip_comments=True), | |
97 ]) | |
98 | |
99 @patch('core.html.bleach.clean') | |
100 def test_comments(self, clean_mock): | |
101 text = ' Lorem ipsum ' | |
102 result = clean_html(text, profile='news') | |
103 self.assertEqual(clean_mock.mock_calls, [ | |
104 call('Lorem ipsum', tags=_CLEAN_PROFILES['news'][0], | |
105 attributes=_CLEAN_PROFILES['news'][1], | |
106 styles=_CLEAN_PROFILES['news'][2], strip=True, | |
107 strip_comments=True), | |
108 ]) |