comparison core/tests/test_ssl_images.py @ 873:9676833dfdca

Add more tests for ssl_images.
author Brian Neal <bgneal@gmail.com>
date Mon, 22 Dec 2014 20:10:15 -0600
parents 1bd9dadcd4d9
children ae146e30d588
comparison
equal deleted inserted replaced
872:1bd9dadcd4d9 873:9676833dfdca
117 self.assertEqual(expected, result) 117 self.assertEqual(expected, result)
118 118
119 @mock.patch('core.management.commands.ssl_images.save_image_to_cloud') 119 @mock.patch('core.management.commands.ssl_images.save_image_to_cloud')
120 def test_simple_replacement(self, upload_mock): 120 def test_simple_replacement(self, upload_mock):
121 old_src = 'http://example.com/images/my_image.jpg' 121 old_src = 'http://example.com/images/my_image.jpg'
122 new_src = 'ttps://cloud.com/ABCDEF.jpg' 122 new_src = 'https://cloud.com/ABCDEF.jpg'
123 test_str = """Here is a really cool http: based image: 123 test_str = """Here is a really cool http: based image:
124 ![flyer]({}) 124 ![flyer]({})
125 Cool, right?""".format(old_src) 125 Cool, right?""".format(old_src)
126 expected = """Here is a really cool http: based image: 126 expected = """Here is a really cool http: based image:
127 ![flyer]({}) 127 ![flyer]({})
129 129
130 upload_mock.return_value = new_src 130 upload_mock.return_value = new_src
131 result = process_post(test_str) 131 result = process_post(test_str)
132 self.assertEqual(expected, result) 132 self.assertEqual(expected, result)
133 upload_mock.assert_called_once_with(old_src) 133 upload_mock.assert_called_once_with(old_src)
134
135 @mock.patch('core.management.commands.ssl_images.save_image_to_cloud')
136 def test_multiple_replacement(self, upload_mock):
137 old_src = [
138 'http://example.com/images/my_image.jpg',
139 'http://example.com/static/wow.gif',
140 'http://example.com/media/a/b/c/pic.png',
141 ]
142 new_src = [
143 'https://cloud.com/some/path/012345.jpg',
144 'https://cloud.com/some/path/6789AB.gif',
145 'https://cloud.com/some/path/CDEF01.png',
146 ]
147
148 template = """Here is a really cool http: based image:
149 ![flyer]({})
150 Cool, right?
151 Another one: ![pic]({})
152 And finally
153 ![an image]({})
154 """
155
156 test_str = template.format(*old_src)
157 expected = template.format(*new_src)
158
159 upload_mock.side_effect = new_src
160 result = process_post(test_str)
161 self.assertEqual(expected, result)
162 expected_args = [mock.call(c) for c in old_src]
163 self.assertEqual(upload_mock.call_args_list, expected_args)
164
165 @mock.patch('core.management.commands.ssl_images.save_image_to_cloud')
166 def test_multiple_replacement_2(self, upload_mock):
167 old_src = [
168 'http://example.com/images/my_image.jpg',
169 'https://example.com/static/wow.gif',
170 'http://www.surfguitar101.com/media/a/b/c/pic.png',
171 'http://surfguitar101.com/media/a/b/c/pic2.png',
172 ]
173 new_src = [
174 'https://cloud.com/some/path/012345.jpg',
175 'https://example.com/static/wow.gif',
176 '/media/a/b/c/pic.png',
177 '/media/a/b/c/pic2.png',
178 ]
179
180 template = """Here is a really cool http: based image:
181 ![flyer]({})
182 Cool, right?
183 Another two: ![pic]({}) ![photo]({})
184 And finally
185 ![an image]({}).
186 """
187
188 test_str = template.format(*old_src)
189 expected = template.format(*new_src)
190
191 upload_mock.side_effect = new_src
192 result = process_post(test_str)
193 self.assertEqual(expected, result)
194 upload_mock.assert_called_once_with(old_src[0])