mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #27188 -- Allowed using unique=True with FileField.
Thanks Tim Graham for the initial patch.
This commit is contained in:
committed by
Tim Graham
parent
625cd5bcb3
commit
ec9ed07488
@@ -4,6 +4,7 @@ import unittest
|
||||
|
||||
from django.core.files import temp
|
||||
from django.core.files.uploadedfile import TemporaryUploadedFile
|
||||
from django.db.utils import IntegrityError
|
||||
from django.test import TestCase, override_settings
|
||||
|
||||
from .models import Document
|
||||
@@ -61,6 +62,15 @@ class FileFieldTests(TestCase):
|
||||
Document.objects.create(myfile='something.txt')
|
||||
self.assertEqual(Document.objects.defer('myfile')[0].myfile, 'something.txt')
|
||||
|
||||
def test_unique_when_same_filename(self):
|
||||
"""
|
||||
A FileField with unique=True shouldn't allow two instances with the
|
||||
same name to be saved.
|
||||
"""
|
||||
Document.objects.create(myfile='something.txt')
|
||||
with self.assertRaises(IntegrityError):
|
||||
Document.objects.create(myfile='something.txt')
|
||||
|
||||
@unittest.skipIf(sys.platform.startswith('win'), "Windows doesn't support moving open files.")
|
||||
# The file's source and destination must be on the same filesystem.
|
||||
@override_settings(MEDIA_ROOT=temp.gettempdir())
|
||||
|
||||
Reference in New Issue
Block a user