Mercurial > public > sg101
comparison core/tests/test_ssl_images.py @ 927:37e75385e931
Fix broken ssl_images unit test.
This was broken before the upgrade to Django 1.7.7.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Tue, 14 Apr 2015 21:25:43 -0500 |
parents | 101728976f9c |
children | 4619290d171d |
comparison
equal
deleted
inserted
replaced
926:22ed8451e163 | 927:37e75385e931 |
---|---|
121 """ | 121 """ |
122 result = process_post(test_str) | 122 result = process_post(test_str) |
123 self.assertEqual(expected, result) | 123 self.assertEqual(expected, result) |
124 | 124 |
125 @mock.patch('core.management.commands.ssl_images.save_image_to_cloud') | 125 @mock.patch('core.management.commands.ssl_images.save_image_to_cloud') |
126 @mock.patch('core.management.commands.ssl_images.check_https_availability', | |
127 new=lambda r: None) | |
128 def test_simple_replacement(self, upload_mock): | 126 def test_simple_replacement(self, upload_mock): |
129 old_src = 'http://example.com/images/my_image.jpg' | 127 old_src = 'http://example.com/images/my_image.jpg' |
130 new_src = 'https://cloud.com/ABCDEF.jpg' | 128 new_src = 'https://cloud.com/ABCDEF.jpg' |
131 test_str = """Here is a really cool http: based image: | 129 test_str = """Here is a really cool http: based image: |
132 ![flyer]({}) | 130 ![flyer]({}) |
136 Cool, right?""".format(new_src) | 134 Cool, right?""".format(new_src) |
137 | 135 |
138 upload_mock.return_value = new_src | 136 upload_mock.return_value = new_src |
139 result = process_post(test_str) | 137 result = process_post(test_str) |
140 self.assertEqual(expected, result) | 138 self.assertEqual(expected, result) |
141 upload_mock.assert_called_once_with(old_src) | 139 upload_mock.assert_called_once_with(urlparse(old_src)) |
142 | 140 |
143 @mock.patch('core.management.commands.ssl_images.save_image_to_cloud') | 141 @mock.patch('core.management.commands.ssl_images.save_image_to_cloud') |
144 @mock.patch('core.management.commands.ssl_images.check_https_availability', | |
145 new=lambda r: None) | |
146 def test_multiple_replacement(self, upload_mock): | 142 def test_multiple_replacement(self, upload_mock): |
147 old_src = [ | 143 old_src = [ |
148 'http://example.com/images/my_image.jpg', | 144 'http://example.com/images/my_image.jpg', |
149 'http://example.com/static/wow.gif', | 145 'http://example.com/static/wow.gif', |
150 'http://example.com/media/a/b/c/pic.png', | 146 'http://example.com/media/a/b/c/pic.png', |
167 expected = template.format(*new_src) | 163 expected = template.format(*new_src) |
168 | 164 |
169 upload_mock.side_effect = new_src | 165 upload_mock.side_effect = new_src |
170 result = process_post(test_str) | 166 result = process_post(test_str) |
171 self.assertEqual(expected, result) | 167 self.assertEqual(expected, result) |
172 expected_args = [mock.call(c) for c in old_src] | 168 expected_args = [mock.call(urlparse(c)) for c in old_src] |
173 self.assertEqual(upload_mock.call_args_list, expected_args) | 169 self.assertEqual(upload_mock.call_args_list, expected_args) |
174 | 170 |
175 @mock.patch('core.management.commands.ssl_images.save_image_to_cloud') | 171 @mock.patch('core.management.commands.ssl_images.save_image_to_cloud') |
176 @mock.patch('core.management.commands.ssl_images.check_https_availability', | |
177 new=lambda r: None) | |
178 def test_multiple_replacement_2(self, upload_mock): | 172 def test_multiple_replacement_2(self, upload_mock): |
179 old_src = [ | 173 old_src = [ |
180 'http://example.com/images/my_image.jpg', | 174 'http://example.com/images/my_image.jpg', |
181 'https://example.com/static/wow.gif', | 175 'https://example.com/static/wow.gif', |
182 'http://www.surfguitar101.com/media/a/b/c/pic.png', | 176 'http://www.surfguitar101.com/media/a/b/c/pic.png', |
201 expected = template.format(*new_src) | 195 expected = template.format(*new_src) |
202 | 196 |
203 upload_mock.side_effect = new_src | 197 upload_mock.side_effect = new_src |
204 result = process_post(test_str) | 198 result = process_post(test_str) |
205 self.assertEqual(expected, result) | 199 self.assertEqual(expected, result) |
206 upload_mock.assert_called_once_with(old_src[0]) | 200 upload_mock.assert_called_once_with(urlparse(old_src[0])) |
207 | 201 |
208 @mock.patch('core.management.commands.ssl_images.save_image_to_cloud') | 202 @mock.patch('core.management.commands.ssl_images.save_image_to_cloud') |
209 @mock.patch('core.management.commands.ssl_images.check_https_availability', | |
210 new=lambda r: None) | |
211 def test_caching(self, upload_mock): | 203 def test_caching(self, upload_mock): |
212 old_src = [ | 204 old_src = [ |
213 'http://example.com/images/my_image.jpg', | 205 'http://example.com/images/my_image.jpg', |
214 'http://example.com/static/wow.gif', | 206 'http://example.com/static/wow.gif', |
215 'http://example.com/images/my_image.jpg', | 207 'http://example.com/images/my_image.jpg', |
232 expected = template.format(*new_src) | 224 expected = template.format(*new_src) |
233 | 225 |
234 upload_mock.side_effect = new_src | 226 upload_mock.side_effect = new_src |
235 result = process_post(test_str) | 227 result = process_post(test_str) |
236 self.assertEqual(expected, result) | 228 self.assertEqual(expected, result) |
237 expected_args = [mock.call(c) for c in old_src[:2]] | 229 expected_args = [mock.call(urlparse(c)) for c in old_src[:2]] |
238 self.assertEqual(upload_mock.call_args_list, expected_args) | 230 self.assertEqual(upload_mock.call_args_list, expected_args) |
239 | |
240 @mock.patch('core.management.commands.ssl_images.check_https_availability') | |
241 def test_https_availability(self, check_https_mock): | |
242 old_src = [ | |
243 'http://example.com/images/my_image.jpg', | |
244 'http://example.com/static/wow.gif', | |
245 'http://example.com/images/another_image.jpg', | |
246 ] | |
247 new_src = [ | |
248 'https://example.com/images/my_image.jpg', | |
249 'https://example.com/static/wow.gif', | |
250 'https://example.com/images/another_image.jpg', | |
251 ] | |
252 | |
253 template = """Here is a really cool http: based image: | |
254 ![flyer]({}) | |
255 Cool, right? | |
256 Another one: ![pic]({}) | |
257 And finally | |
258 ![an image]({}) | |
259 """ | |
260 | |
261 test_str = template.format(*old_src) | |
262 expected = template.format(*new_src) | |
263 | |
264 check_https_mock.side_effect = new_src | |
265 result = process_post(test_str) | |
266 self.assertEqual(expected, result) | |
267 expected_args = [mock.call(urlparse(c)) for c in old_src] | |
268 self.assertEqual(check_https_mock.call_args_list, expected_args) | |
269 | 231 |
270 | 232 |
271 class HtmlCheckTestCase(unittest.TestCase): | 233 class HtmlCheckTestCase(unittest.TestCase): |
272 | 234 |
273 def test_empty(self): | 235 def test_empty(self): |