Mercurial > public > sg101
annotate core/tests/test_ssl_images.py @ 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 | 64a5acb83937 |
children | 6900040df0f8 |
rev | line source |
---|---|
bgneal@868 | 1 """Unit tests for the ssl_images management command.""" |
bgneal@870 | 2 import re |
bgneal@868 | 3 import unittest |
bgneal@868 | 4 |
bgneal@868 | 5 from core.management.commands.ssl_images import process_post |
bgneal@868 | 6 |
bgneal@868 | 7 |
bgneal@868 | 8 class ProcessPostTestCase(unittest.TestCase): |
bgneal@868 | 9 |
bgneal@870 | 10 SG101_RE = re.compile(r'http://(?:www\.)?surfguitar101.com/', re.I) |
bgneal@870 | 11 |
bgneal@868 | 12 def test_empty_string(self): |
bgneal@868 | 13 s = process_post('') |
bgneal@868 | 14 self.assertEqual(s, '') |
bgneal@870 | 15 |
bgneal@870 | 16 def test_no_matches(self): |
bgneal@870 | 17 test_str = """Here is a post that doesn't contain any image links at |
bgneal@870 | 18 all. It also spans lines. |
bgneal@870 | 19 """ |
bgneal@870 | 20 result = process_post(test_str) |
bgneal@870 | 21 self.assertEqual(test_str, result) |
bgneal@870 | 22 |
bgneal@870 | 23 def test_sg101_images(self): |
bgneal@870 | 24 test_str = """An image: ![image](http://www.surfguitar101.com/img.jpg) |
bgneal@870 | 25 And another: ![pic](HTTP://SURFGUITAR101.COM/foo/bar/img.png). |
bgneal@870 | 26 More stuff here.""" |
bgneal@870 | 27 expected = self.SG101_RE.sub('/', test_str) |
bgneal@870 | 28 result = process_post(test_str) |
bgneal@870 | 29 self.assertNotEqual(test_str, expected) |
bgneal@870 | 30 self.assertEqual(expected, result) |
bgneal@870 | 31 |
bgneal@870 | 32 def test_https_already(self): |
bgneal@870 | 33 pass |