comparison core/tests/test_ssl_images.py @ 872:1bd9dadcd4d9

Added mock-based test for ssl_images command. Also added .tags to .hgignore.
author Brian Neal <bgneal@gmail.com>
date Sun, 21 Dec 2014 21:37:30 -0600
parents 6900040df0f8
children 9676833dfdca
comparison
equal deleted inserted replaced
871:6900040df0f8 872:1bd9dadcd4d9
1 """Unit tests for the ssl_images management command.""" 1 """Unit tests for the ssl_images management command."""
2 import re 2 import re
3 import unittest 3 import unittest
4
5 import mock
4 6
5 from core.management.commands.ssl_images import process_post 7 from core.management.commands.ssl_images import process_post
6 8
7 9
8 class ProcessPostTestCase(unittest.TestCase): 10 class ProcessPostTestCase(unittest.TestCase):
111 ![flyer](https://example.com/zzz.png) 113 ![flyer](https://example.com/zzz.png)
112 It's cool. 114 It's cool.
113 """ 115 """
114 result = process_post(test_str) 116 result = process_post(test_str)
115 self.assertEqual(expected, result) 117 self.assertEqual(expected, result)
118
119 @mock.patch('core.management.commands.ssl_images.save_image_to_cloud')
120 def test_simple_replacement(self, upload_mock):
121 old_src = 'http://example.com/images/my_image.jpg'
122 new_src = 'ttps://cloud.com/ABCDEF.jpg'
123 test_str = """Here is a really cool http: based image:
124 ![flyer]({})
125 Cool, right?""".format(old_src)
126 expected = """Here is a really cool http: based image:
127 ![flyer]({})
128 Cool, right?""".format(new_src)
129
130 upload_mock.return_value = new_src
131 result = process_post(test_str)
132 self.assertEqual(expected, result)
133 upload_mock.assert_called_once_with(old_src)