comparison user_photos/tests/test_forms.py @ 1202:50e511e032db

Get unit tests working again.
author Brian Neal <bgneal@gmail.com>
date Sat, 04 Jan 2025 14:10:38 -0600
parents f5aa74dcdd7a
children
comparison
equal deleted inserted replaced
1201:fe10aea76cbd 1202:50e511e032db
46 self.assertFalse(form.is_valid()) 46 self.assertFalse(form.is_valid())
47 47
48 @mock.patch('user_photos.forms.rate_limit_user') 48 @mock.patch('user_photos.forms.rate_limit_user')
49 @mock.patch('user_photos.forms.download_file') 49 @mock.patch('user_photos.forms.download_file')
50 @mock.patch('user_photos.forms.remove_file', new=fake_remove_file) 50 @mock.patch('user_photos.forms.remove_file', new=fake_remove_file)
51 @mock.patch('user_photos.forms.S3Bucket') 51 @mock.patch('user_photos.forms.process_upload')
52 @mock.patch('user_photos.forms.upload') 52 def test_white_listed_url(self, upload_mock, dl_mock, rate_limit_mock):
53 def test_white_listed_url(self, upload_mock, bucket_mock, dl_mock, rate_limit_mock):
54 url = 'https://{}/a.jpg'.format(settings.USER_IMAGES_SOURCES[0]) 53 url = 'https://{}/a.jpg'.format(settings.USER_IMAGES_SOURCES[0])
55 args = {'url': url} 54 args = {'url': url}
56 form = HotLinkImageForm(args, user=self.user) 55 form = HotLinkImageForm(args, user=self.user)
57 self.assertTrue(form.is_valid()) 56 self.assertTrue(form.is_valid())
58 result = form.save() 57 result = form.save()
59 self.assertEqual(result, url) 58 self.assertEqual(result, url)
60 self.assertFalse(dl_mock.called) 59 self.assertFalse(dl_mock.called)
61 self.assertFalse(bucket_mock.called)
62 self.assertFalse(upload_mock.called) 60 self.assertFalse(upload_mock.called)
63 61
64 @mock.patch('user_photos.forms.rate_limit_user') 62 @mock.patch('user_photos.forms.rate_limit_user')
65 @mock.patch('user_photos.forms.download_file') 63 @mock.patch('user_photos.forms.download_file')
66 @mock.patch('user_photos.forms.remove_file', new=fake_remove_file) 64 @mock.patch('user_photos.forms.remove_file', new=fake_remove_file)
67 @mock.patch('user_photos.forms.S3Bucket') 65 @mock.patch('user_photos.forms.process_upload')
68 @mock.patch('user_photos.forms.upload') 66 def test_happy_path(self, upload_mock, dl_mock, rate_limit_mock):
69 def test_happy_path(self, upload_mock, bucket_mock, dl_mock, rate_limit_mock):
70 url = 'http://example.com/a.jpg' 67 url = 'http://example.com/a.jpg'
71 args = {'url': url} 68 args = {'url': url}
72 form = HotLinkImageForm(args, user=self.user) 69 form = HotLinkImageForm(args, user=self.user)
73 self.assertTrue(form.is_valid()) 70 self.assertTrue(form.is_valid())
74 new_url = 'https://img.example.com/a.jpg' 71 new_url = 'https://img.example.com/a.jpg'