mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Used addCleanup() in tests where appropriate.
This commit is contained in:
parent
81ccf92f15
commit
d88ec42bd0
37 changed files with 121 additions and 240 deletions
|
@ -71,16 +71,10 @@ class FileStorageTests(SimpleTestCase):
|
|||
|
||||
def setUp(self):
|
||||
self.temp_dir = tempfile.mkdtemp()
|
||||
self.addCleanup(shutil.rmtree, self.temp_dir)
|
||||
self.storage = self.storage_class(
|
||||
location=self.temp_dir, base_url="/test_media_url/"
|
||||
)
|
||||
# Set up a second temporary directory which is ensured to have a mixed
|
||||
# case name.
|
||||
self.temp_dir2 = tempfile.mkdtemp(suffix="aBc")
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree(self.temp_dir)
|
||||
shutil.rmtree(self.temp_dir2)
|
||||
|
||||
def test_empty_location(self):
|
||||
"""
|
||||
|
@ -414,14 +408,16 @@ class FileStorageTests(SimpleTestCase):
|
|||
"""The storage backend should preserve case of filenames."""
|
||||
# Create a storage backend associated with the mixed case name
|
||||
# directory.
|
||||
other_temp_storage = self.storage_class(location=self.temp_dir2)
|
||||
temp_dir2 = tempfile.mkdtemp(suffix="aBc")
|
||||
self.addCleanup(shutil.rmtree, temp_dir2)
|
||||
other_temp_storage = self.storage_class(location=temp_dir2)
|
||||
# Ask that storage backend to store a file with a mixed case filename.
|
||||
mixed_case = "CaSe_SeNsItIvE"
|
||||
file = other_temp_storage.open(mixed_case, "w")
|
||||
file.write("storage contents")
|
||||
file.close()
|
||||
self.assertEqual(
|
||||
os.path.join(self.temp_dir2, mixed_case),
|
||||
os.path.join(temp_dir2, mixed_case),
|
||||
other_temp_storage.path(mixed_case),
|
||||
)
|
||||
other_temp_storage.delete(mixed_case)
|
||||
|
@ -917,9 +913,7 @@ class FieldCallableFileStorageTests(SimpleTestCase):
|
|||
self.temp_storage_location = tempfile.mkdtemp(
|
||||
suffix="filefield_callable_storage"
|
||||
)
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree(self.temp_storage_location)
|
||||
self.addCleanup(shutil.rmtree, self.temp_storage_location)
|
||||
|
||||
def test_callable_base_class_error_raises(self):
|
||||
class NotStorage:
|
||||
|
@ -993,12 +987,10 @@ class SlowFile(ContentFile):
|
|||
class FileSaveRaceConditionTest(SimpleTestCase):
|
||||
def setUp(self):
|
||||
self.storage_dir = tempfile.mkdtemp()
|
||||
self.addCleanup(shutil.rmtree, self.storage_dir)
|
||||
self.storage = FileSystemStorage(self.storage_dir)
|
||||
self.thread = threading.Thread(target=self.save_file, args=["conflict"])
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree(self.storage_dir)
|
||||
|
||||
def save_file(self, name):
|
||||
name = self.storage.save(name, SlowFile(b"Data"))
|
||||
|
||||
|
@ -1017,12 +1009,10 @@ class FileSaveRaceConditionTest(SimpleTestCase):
|
|||
class FileStoragePermissions(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.umask = 0o027
|
||||
self.old_umask = os.umask(self.umask)
|
||||
old_umask = os.umask(self.umask)
|
||||
self.addCleanup(os.umask, old_umask)
|
||||
self.storage_dir = tempfile.mkdtemp()
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree(self.storage_dir)
|
||||
os.umask(self.old_umask)
|
||||
self.addCleanup(shutil.rmtree, self.storage_dir)
|
||||
|
||||
@override_settings(FILE_UPLOAD_PERMISSIONS=0o654)
|
||||
def test_file_upload_permissions(self):
|
||||
|
@ -1059,11 +1049,9 @@ class FileStoragePermissions(unittest.TestCase):
|
|||
class FileStoragePathParsing(SimpleTestCase):
|
||||
def setUp(self):
|
||||
self.storage_dir = tempfile.mkdtemp()
|
||||
self.addCleanup(shutil.rmtree, self.storage_dir)
|
||||
self.storage = FileSystemStorage(self.storage_dir)
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree(self.storage_dir)
|
||||
|
||||
def test_directory_with_dot(self):
|
||||
"""Regression test for #9610.
|
||||
|
||||
|
@ -1095,11 +1083,9 @@ class FileStoragePathParsing(SimpleTestCase):
|
|||
|
||||
class ContentFileStorageTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.storage_dir = tempfile.mkdtemp()
|
||||
self.storage = FileSystemStorage(self.storage_dir)
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree(self.storage_dir)
|
||||
storage_dir = tempfile.mkdtemp()
|
||||
self.addCleanup(shutil.rmtree, storage_dir)
|
||||
self.storage = FileSystemStorage(storage_dir)
|
||||
|
||||
def test_content_saving(self):
|
||||
"""
|
||||
|
@ -1120,11 +1106,9 @@ class FileLikeObjectTestCase(LiveServerTestCase):
|
|||
|
||||
def setUp(self):
|
||||
self.temp_dir = tempfile.mkdtemp()
|
||||
self.addCleanup(shutil.rmtree, self.temp_dir)
|
||||
self.storage = FileSystemStorage(location=self.temp_dir)
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree(self.temp_dir)
|
||||
|
||||
def test_urllib_request_urlopen(self):
|
||||
"""
|
||||
Test the File storage API with a file-like object coming from
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue