# HG changeset patch # User Brian Neal # Date 1418699807 21600 # Node ID ee56c8c8cf98e187ac1cbbdb4c490c5eb08f6ccf # Parent 63209e53f3aa80080dbd570031456fbed516a119 More WIP on ssl_images management command and tests. diff -r 63209e53f3aa -r ee56c8c8cf98 core/management/commands/ssl_images.py --- a/core/management/commands/ssl_images.py Mon Dec 15 19:51:28 2014 -0600 +++ b/core/management/commands/ssl_images.py Mon Dec 15 21:16:47 2014 -0600 @@ -24,8 +24,8 @@ LOGFILE = os.path.join(settings.PROJECT_PATH, 'logs', 'ssl_images.log') logger = logging.getLogger(__name__) -IMAGE_LINK_RE = re.compile(markdown.inlinepatterns.IMAGE_LINK_RE) -IMAGE_REF_RE = re.compile(markdown.inlinepatterns.IMAGE_REFERENCE_RE) +IMAGE_LINK_RE = re.compile(markdown.inlinepatterns.IMAGE_LINK_RE, re.UNICODE) +IMAGE_REF_RE = re.compile(markdown.inlinepatterns.IMAGE_REFERENCE_RE, re.UNICODE) SG101_HOSTS = set(['www.surfguitar101.com', 'surfguitar101.com']) MODEL_CHOICES = ['comments', 'posts'] @@ -54,7 +54,7 @@ def replace_image_markup(match): - src_parts = match.group(9).split() + src_parts = match.group(8).split() if src_parts: src = src_parts[0] if src[0] == "<" and src[-1] == ">": @@ -65,7 +65,7 @@ title = '' if len(src_parts) > 1: title = " ".join(src_parts[1:]) - alt = match.group(2) + alt = match.group(1) new_src = '' if src: diff -r 63209e53f3aa -r ee56c8c8cf98 core/tests/test_ssl_images.py --- a/core/tests/test_ssl_images.py Mon Dec 15 19:51:28 2014 -0600 +++ b/core/tests/test_ssl_images.py Mon Dec 15 21:16:47 2014 -0600 @@ -1,5 +1,5 @@ """Unit tests for the ssl_images management command.""" - +import re import unittest from core.management.commands.ssl_images import process_post @@ -7,6 +7,27 @@ class ProcessPostTestCase(unittest.TestCase): + SG101_RE = re.compile(r'http://(?:www\.)?surfguitar101.com/', re.I) + def test_empty_string(self): s = process_post('') self.assertEqual(s, '') + + def test_no_matches(self): + test_str = """Here is a post that doesn't contain any image links at + all. It also spans lines. + """ + result = process_post(test_str) + self.assertEqual(test_str, result) + + def test_sg101_images(self): + test_str = """An image: ![image](http://www.surfguitar101.com/img.jpg) + And another: ![pic](HTTP://SURFGUITAR101.COM/foo/bar/img.png). + More stuff here.""" + expected = self.SG101_RE.sub('/', test_str) + result = process_post(test_str) + self.assertNotEqual(test_str, expected) + self.assertEqual(expected, result) + + def test_https_already(self): + pass