Ticket #18233: fix_18233.diff

File fix_18233.diff, 2.3 KB (added by Aviral Dasgupta, 12 years ago)

Fixed and added tests.

  • AUTHORS

    diff --git a/AUTHORS b/AUTHORS
    index e3aec98..526f355 100644
    a b answer newbie questions, and generally made Django that much better:  
    563563    Gasper Zejn <zejn@kiberpipa.org>
    564564    Jarek Zgoda <jarek.zgoda@gmail.com>
    565565    Cheng Zhang
     566    Aviral Dasgupta <aviraldg@gmail.com>
    566567
    567568A big THANK YOU goes to:
    568569
  • django/core/files/move.py

    diff --git a/django/core/files/move.py b/django/core/files/move.py
    index 3349fc2..4681e00 100644
    a b def file_move_safe(old_file_name, new_file_name, chunk_size = 1024*64, allow_ove  
    5151        return
    5252
    5353    try:
     54        if not allow_overwrite and os.path.exists(new_file_name):
     55            raise IOError('Destination file already exists: \'{0}\''.format(new_file_name))
    5456        os.rename(old_file_name, new_file_name)
    5557        return
    5658    except OSError:
  • tests/regressiontests/file_storage/tests.py

    diff --git a/tests/regressiontests/file_storage/tests.py b/tests/regressiontests/file_storage/tests.py
    index c28b019..f607b83 100644
    a b from django.core.files.base import File, ContentFile  
    2323from django.core.files.images import get_image_dimensions
    2424from django.core.files.storage import FileSystemStorage, get_storage_class
    2525from django.core.files.uploadedfile import UploadedFile
     26from django.core.files.move import file_move_safe
    2627from django.test import SimpleTestCase
    2728from django.utils import unittest
    2829from ..servers.tests import LiveServerBase
    class FileLikeObjectTestCase(LiveServerBase):  
    586587        remote_file = self.urlopen('/example_view/')
    587588
    588589        self.assertEqual(stored_file.read(), remote_file.read())
     590
     591class MoveTestCase(unittest.TestCase):
     592    """
     593    Test django.core.files.move.
     594    """
     595    def setUp(self):
     596        self.file_a = tempfile.mkstemp()
     597        self.file_b = tempfile.mkstemp()
     598
     599    def tearDown(self):
     600        os.close(self.file_a[0])
     601        os.close(self.file_b[0])
     602        os.remove(self.file_a[1])
     603        os.remove(self.file_b[1])
     604
     605    def test_overwrite_existing_file(self):
     606        """
     607        Test that file_move_safe raises an IOError if you try to overwrite an
     608        existing file without passing in allow_overwrite=True.
     609        """
     610        self.assertRaises(IOError, file_move_safe, self.file_a[1], self.file_b[1])
Back to Top