Mercurial > public > sg101
comparison core/tests/test_ssl_images.py @ 894:101728976f9c
Check html for <img src="http:...">.
Older Smiley code generated absolute URLs for smiley images. Check for this and
if found, save the model to force regeneration of HTML.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 18 Feb 2015 21:20:31 -0600 |
parents | ae146e30d588 |
children | 37e75385e931 |
comparison
equal
deleted
inserted
replaced
893:3aecf9058130 | 894:101728976f9c |
---|---|
3 import unittest | 3 import unittest |
4 from urlparse import urlparse | 4 from urlparse import urlparse |
5 | 5 |
6 import mock | 6 import mock |
7 | 7 |
8 from core.management.commands.ssl_images import html_check | |
8 from core.management.commands.ssl_images import process_post | 9 from core.management.commands.ssl_images import process_post |
9 import core.management.commands.ssl_images | 10 import core.management.commands.ssl_images |
10 | 11 |
11 | 12 |
12 class ProcessPostTestCase(unittest.TestCase): | 13 class ProcessPostTestCase(unittest.TestCase): |
263 check_https_mock.side_effect = new_src | 264 check_https_mock.side_effect = new_src |
264 result = process_post(test_str) | 265 result = process_post(test_str) |
265 self.assertEqual(expected, result) | 266 self.assertEqual(expected, result) |
266 expected_args = [mock.call(urlparse(c)) for c in old_src] | 267 expected_args = [mock.call(urlparse(c)) for c in old_src] |
267 self.assertEqual(check_https_mock.call_args_list, expected_args) | 268 self.assertEqual(check_https_mock.call_args_list, expected_args) |
269 | |
270 | |
271 class HtmlCheckTestCase(unittest.TestCase): | |
272 | |
273 def test_empty(self): | |
274 self.assertFalse(html_check('')) | |
275 | |
276 def test_no_images(self): | |
277 self.assertFalse(html_check('<p>Hi there!</p>')) | |
278 self.assertFalse(html_check('<p>Hi <b>there</b>!</p>')) | |
279 | |
280 def test_safe_image(self): | |
281 self.assertFalse(html_check('<img src="https://a.jpg" />')) | |
282 self.assertFalse(html_check('<img src="" alt="stuff" />')) | |
283 self.assertFalse(html_check('<img src="HTTPS://a.jpg" />')) | |
284 self.assertFalse(html_check(""" | |
285 <div> | |
286 <p>Look: <img src="https://a.jpg" alt="a" /></p> | |
287 <p>Look again: <img src="https://b.jpg" alt="b" /></p> | |
288 </div> | |
289 """)) | |
290 | |
291 def test_one_image(self): | |
292 self.assertTrue(html_check('<img src="http://a.jpg" alt="a" />')) | |
293 self.assertTrue(html_check( | |
294 '<p>Look: <img src="http://a.jpg" alt="a" /></p>')) | |
295 | |
296 def test_two_images(self): | |
297 self.assertTrue(html_check(""" | |
298 <p>Look: <img src="https://a.jpg" alt="a" /></p> | |
299 <p>Look again: <img src="http://b.jpg" alt="b" /></p> | |
300 """)) | |
301 self.assertTrue(html_check(""" | |
302 <p>Look: <img src="http://a.jpg" alt="a" /></p> | |
303 <p>Look again: <img src="http://b.jpg" alt="b" /></p> | |
304 """)) | |
305 self.assertTrue(html_check(""" | |
306 <div> | |
307 <p>Look: <img src="http://a.jpg" alt="a" /></p> | |
308 <p>Look again: <img src="http://b.jpg" alt="b" /></p> | |
309 </div> | |
310 """)) | |
311 self.assertTrue(html_check(""" | |
312 <div> | |
313 <p>Look: <img src="http://a.jpg" alt="a" /></p> | |
314 <p>Look again: <img src="https://b.jpg" alt="b" /></p> | |
315 </div> | |
316 """)) |