diff user_photos/tests/test_forms.py @ 976:f5aa74dcdd7a

Ensure temporary files get deleted during hotlinking.
author Brian Neal <bgneal@gmail.com>
date Mon, 05 Oct 2015 20:07:44 -0500
parents 6f55c086db1e
children
line wrap: on
line diff
--- a/user_photos/tests/test_forms.py	Mon Oct 05 20:06:24 2015 -0500
+++ b/user_photos/tests/test_forms.py	Mon Oct 05 20:07:44 2015 -0500
@@ -1,6 +1,7 @@
 """
 Tests for the forms in the user_photos application.
 """
+from contextlib import contextmanager
 
 import mock
 from django import forms
@@ -11,6 +12,11 @@
 from user_photos.forms import HotLinkImageForm
 
 
+@contextmanager
+def fake_remove_file(path):
+    yield path
+
+
 class HotLinkImageFormTestCase(TestCase):
 
     def setUp(self):
@@ -41,6 +47,7 @@
 
     @mock.patch('user_photos.forms.rate_limit_user')
     @mock.patch('user_photos.forms.download_file')
+    @mock.patch('user_photos.forms.remove_file', new=fake_remove_file)
     @mock.patch('user_photos.forms.S3Bucket')
     @mock.patch('user_photos.forms.upload')
     def test_white_listed_url(self, upload_mock, bucket_mock, dl_mock, rate_limit_mock):
@@ -56,6 +63,7 @@
 
     @mock.patch('user_photos.forms.rate_limit_user')
     @mock.patch('user_photos.forms.download_file')
+    @mock.patch('user_photos.forms.remove_file', new=fake_remove_file)
     @mock.patch('user_photos.forms.S3Bucket')
     @mock.patch('user_photos.forms.upload')
     def test_happy_path(self, upload_mock, bucket_mock, dl_mock, rate_limit_mock):