summaryrefslogtreecommitdiff
path: root/tests/files
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2013-06-20 18:55:27 +0800
committerRussell Keith-Magee <russell@keith-magee.com>2013-06-20 18:55:27 +0800
commit18e79f1425fa87f2f38df25c65203ec4d311f499 (patch)
tree8060a3ed343f8bf27373e4c2d79c0de224424843 /tests/files
parent3671e7e3e0603ed8908eb1328a82396e22b9224c (diff)
Fixed #20486 -- Ensure that file_move_safe raises an error if the destination already exists.
Thanks to kux for the report, and Russ Webber for the patch.
Diffstat (limited to 'tests/files')
-rw-r--r--tests/files/tests.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/files/tests.py b/tests/files/tests.py
index cd2d15acdb..f1e3d5b14b 100644
--- a/tests/files/tests.py
+++ b/tests/files/tests.py
@@ -1,11 +1,13 @@
from __future__ import absolute_import
+import os
import gzip
import shutil
import tempfile
from django.core.cache import cache
from django.core.files import File
+from django.core.files.move import file_move_safe
from django.core.files.base import ContentFile
from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import TestCase
@@ -146,3 +148,15 @@ class FileTests(unittest.TestCase):
file = SimpleUploadedFile("mode_test.txt", b"content")
self.assertFalse(hasattr(file, 'mode'))
g = gzip.GzipFile(fileobj=file)
+
+
+class FileMoveSafeTests(unittest.TestCase):
+ def test_file_move_overwrite(self):
+ handle_a, self.file_a = tempfile.mkstemp(dir=os.environ['DJANGO_TEST_TEMP_DIR'])
+ handle_b, self.file_b = tempfile.mkstemp(dir=os.environ['DJANGO_TEST_TEMP_DIR'])
+
+ # file_move_safe should raise an IOError exception if destination file exists and allow_overwrite is False
+ self.assertRaises(IOError, lambda: file_move_safe(self.file_a, self.file_b, allow_overwrite=False))
+
+ # should allow it and continue on if allow_overwrite is True
+ self.assertIsNone(file_move_safe(self.file_a, self.file_b, allow_overwrite=True))