Mercurial > public > sg101
changeset 870:ee56c8c8cf98
More WIP on ssl_images management command and tests.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Mon, 15 Dec 2014 21:16:47 -0600 |
parents | 63209e53f3aa |
children | 6900040df0f8 |
files | core/management/commands/ssl_images.py core/tests/test_ssl_images.py |
diffstat | 2 files changed, 26 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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:
--- 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