summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2008-08-08 20:59:02 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2008-08-08 20:59:02 +0000
commit7899568e01fc9c68afe995fa71de915dd9fcdd76 (patch)
tree35f1e999a9a48fe24790f00c2335e558a53fc718 /tests
parentc49eac7d4f64c374d19aa81f2c813a4b20e4cad7 (diff)
File storage refactoring, adding far more flexibility to Django's file handling. The new files.txt document has details of the new features.
This is a backwards-incompatible change; consult BackwardsIncompatibleChanges for details. Fixes #3567, #3621, #4345, #5361, #5655, #7415. Many thanks to Marty Alchin who did the vast majority of this work. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8244 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/modeltests/files/__init__.py1
-rw-r--r--tests/modeltests/files/models.py118
-rw-r--r--tests/modeltests/model_forms/models.py69
-rw-r--r--tests/regressiontests/admin_widgets/models.py14
-rw-r--r--tests/regressiontests/bug639/models.py12
-rw-r--r--tests/regressiontests/bug639/tests.py2
-rw-r--r--tests/regressiontests/file_storage/__init__.py1
-rw-r--r--tests/regressiontests/file_storage/models.py44
-rw-r--r--tests/regressiontests/file_storage/test.pngbin0 -> 482 bytes
-rw-r--r--tests/regressiontests/file_storage/tests.py66
-rw-r--r--tests/regressiontests/file_uploads/models.py7
-rw-r--r--tests/regressiontests/file_uploads/tests.py22
-rw-r--r--tests/regressiontests/serializers_regress/models.py4
-rw-r--r--tests/regressiontests/serializers_regress/tests.py4
14 files changed, 303 insertions, 61 deletions
diff --git a/tests/modeltests/files/__init__.py b/tests/modeltests/files/__init__.py
new file mode 100644
index 0000000000..8b13789179
--- /dev/null
+++ b/tests/modeltests/files/__init__.py
@@ -0,0 +1 @@
+
diff --git a/tests/modeltests/files/models.py b/tests/modeltests/files/models.py
new file mode 100644
index 0000000000..a2ee5a7256
--- /dev/null
+++ b/tests/modeltests/files/models.py
@@ -0,0 +1,118 @@
+"""
+42. Storing files according to a custom storage system
+
+FileField and its variations can take a "storage" argument to specify how and
+where files should be stored.
+"""
+
+import tempfile
+
+from django.db import models
+from django.core.files.base import ContentFile
+from django.core.files.storage import FileSystemStorage
+from django.core.cache import cache
+
+temp_storage = FileSystemStorage(location=tempfile.gettempdir())
+
+# Write out a file to be used as default content
+temp_storage.save('tests/default.txt', ContentFile('default content'))
+
+class Storage(models.Model):
+ def custom_upload_to(self, filename):
+ return 'foo'
+
+ def random_upload_to(self, filename):
+ # This returns a different result each time,
+ # to make sure it only gets called once.
+ import random
+ return '%s/%s' % (random.randint(100, 999), filename)
+
+ normal = models.FileField(storage=temp_storage, upload_to='tests')
+ custom = models.FileField(storage=temp_storage, upload_to=custom_upload_to)
+ random = models.FileField(storage=temp_storage, upload_to=random_upload_to)
+ default = models.FileField(storage=temp_storage, upload_to='tests', default='tests/default.txt')
+
+__test__ = {'API_TESTS':"""
+# An object without a file has limited functionality.
+
+>>> obj1 = Storage()
+>>> obj1.normal
+<FieldFile: None>
+>>> obj1.normal.size
+Traceback (most recent call last):
+...
+ValueError: The 'normal' attribute has no file associated with it.
+
+# Saving a file enables full functionality.
+
+>>> obj1.normal.save('django_test.txt', ContentFile('content'))
+>>> obj1.normal
+<FieldFile: tests/django_test.txt>
+>>> obj1.normal.size
+7
+>>> obj1.normal.read()
+'content'
+
+# Files can be read in a little at a time, if necessary.
+
+>>> obj1.normal.open()
+>>> obj1.normal.read(3)
+'con'
+>>> obj1.normal.read()
+'tent'
+>>> '-'.join(obj1.normal.chunks(chunk_size=2))
+'co-nt-en-t'
+
+# Save another file with the same name.
+
+>>> obj2 = Storage()
+>>> obj2.normal.save('django_test.txt', ContentFile('more content'))
+>>> obj2.normal
+<FieldFile: tests/django_test_.txt>
+>>> obj2.normal.size
+12
+
+# Push the objects into the cache to make sure they pickle properly
+
+>>> cache.set('obj1', obj1)
+>>> cache.set('obj2', obj2)
+>>> cache.get('obj2').normal
+<FieldFile: tests/django_test_.txt>
+
+# Deleting an object deletes the file it uses, if there are no other objects
+# still using that file.
+
+>>> obj2.delete()
+>>> obj2.normal.save('django_test.txt', ContentFile('more content'))
+>>> obj2.normal
+<FieldFile: tests/django_test_.txt>
+
+# Default values allow an object to access a single file.
+
+>>> obj3 = Storage.objects.create()
+>>> obj3.default
+<FieldFile: tests/default.txt>
+>>> obj3.default.read()
+'default content'
+
+# But it shouldn't be deleted, even if there are no more objects using it.
+
+>>> obj3.delete()
+>>> obj3 = Storage()
+>>> obj3.default.read()
+'default content'
+
+# Verify the fix for #5655, making sure the directory is only determined once.
+
+>>> obj4 = Storage()
+>>> obj4.random.save('random_file', ContentFile('random content'))
+>>> obj4.random
+<FieldFile: .../random_file>
+
+# Clean up the temporary files.
+
+>>> obj1.normal.delete()
+>>> obj2.normal.delete()
+>>> obj3.default.delete()
+>>> obj4.random.delete()
+"""}
diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py
index be2a8ba835..3463cb7554 100644
--- a/tests/modeltests/model_forms/models.py
+++ b/tests/modeltests/model_forms/models.py
@@ -11,6 +11,9 @@ import os
import tempfile
from django.db import models
+from django.core.files.storage import FileSystemStorage
+
+temp_storage = FileSystemStorage(tempfile.gettempdir())
ARTICLE_STATUS = (
(1, 'Draft'),
@@ -60,7 +63,7 @@ class PhoneNumber(models.Model):
class TextFile(models.Model):
description = models.CharField(max_length=20)
- file = models.FileField(upload_to=tempfile.gettempdir())
+ file = models.FileField(storage=temp_storage, upload_to='tests')
def __unicode__(self):
return self.description
@@ -73,9 +76,9 @@ class ImageFile(models.Model):
# for PyPy, you need to check for the underlying modules
# If PIL is not available, this test is equivalent to TextFile above.
import Image, _imaging
- image = models.ImageField(upload_to=tempfile.gettempdir())
+ image = models.ImageField(storage=temp_storage, upload_to='tests')
except ImportError:
- image = models.FileField(upload_to=tempfile.gettempdir())
+ image = models.FileField(storage=temp_storage, upload_to='tests')
def __unicode__(self):
return self.description
@@ -786,6 +789,8 @@ u'Assistance'
# FileField ###################################################################
+# File forms.
+
>>> class TextFileForm(ModelForm):
... class Meta:
... model = TextFile
@@ -808,9 +813,9 @@ True
<class 'django.core.files.uploadedfile.SimpleUploadedFile'>
>>> instance = f.save()
>>> instance.file
-u'...test1.txt'
+<FieldFile: tests/test1.txt>
->>> os.unlink(instance.get_file_filename())
+>>> instance.file.delete()
>>> f = TextFileForm(data={'description': u'Assistance'}, files={'file': SimpleUploadedFile('test1.txt', 'hello world')})
>>> f.is_valid()
@@ -819,7 +824,7 @@ True
<class 'django.core.files.uploadedfile.SimpleUploadedFile'>
>>> instance = f.save()
>>> instance.file
-u'...test1.txt'
+<FieldFile: tests/test1.txt>
# Edit an instance that already has the file defined in the model. This will not
# save the file again, but leave it exactly as it is.
@@ -828,13 +833,13 @@ u'...test1.txt'
>>> f.is_valid()
True
>>> f.cleaned_data['file']
-u'...test1.txt'
+<FieldFile: tests/test1.txt>
>>> instance = f.save()
>>> instance.file
-u'...test1.txt'
+<FieldFile: tests/test1.txt>
# Delete the current file since this is not done by Django.
->>> os.unlink(instance.get_file_filename())
+>>> instance.file.delete()
# Override the file by uploading a new one.
@@ -843,20 +848,20 @@ u'...test1.txt'
True
>>> instance = f.save()
>>> instance.file
-u'...test2.txt'
+<FieldFile: tests/test2.txt>
# Delete the current file since this is not done by Django.
->>> os.unlink(instance.get_file_filename())
+>>> instance.file.delete()
>>> f = TextFileForm(data={'description': u'Assistance'}, files={'file': SimpleUploadedFile('test2.txt', 'hello world')})
>>> f.is_valid()
True
>>> instance = f.save()
>>> instance.file
-u'...test2.txt'
+<FieldFile: tests/test2.txt>
# Delete the current file since this is not done by Django.
->>> os.unlink(instance.get_file_filename())
+>>> instance.file.delete()
>>> instance.delete()
@@ -868,17 +873,17 @@ u'...test2.txt'
True
>>> instance = f.save()
>>> instance.file
-''
+<FieldFile: None>
>>> f = TextFileForm(data={'description': u'Assistance'}, files={'file': SimpleUploadedFile('test3.txt', 'hello world')}, instance=instance)
>>> f.is_valid()
True
>>> instance = f.save()
>>> instance.file
-u'...test3.txt'
+<FieldFile: tests/test3.txt>
# Delete the current file since this is not done by Django.
->>> os.unlink(instance.get_file_filename())
+>>> instance.file.delete()
>>> instance.delete()
>>> f = TextFileForm(data={'description': u'Assistance'}, files={'file': SimpleUploadedFile('test3.txt', 'hello world')})
@@ -886,10 +891,10 @@ u'...test3.txt'
True
>>> instance = f.save()
>>> instance.file
-u'...test3.txt'
+<FieldFile: tests/test3.txt>
# Delete the current file since this is not done by Django.
->>> os.unlink(instance.get_file_filename())
+>>> instance.file.delete()
>>> instance.delete()
# ImageField ###################################################################
@@ -911,10 +916,10 @@ True
<class 'django.core.files.uploadedfile.SimpleUploadedFile'>
>>> instance = f.save()
>>> instance.image
-u'...test.png'
+<ImageFieldFile: tests/test.png>
# Delete the current file since this is not done by Django.
->>> os.unlink(instance.get_image_filename())
+>>> instance.image.delete()
>>> f = ImageFileForm(data={'description': u'An image'}, files={'image': SimpleUploadedFile('test.png', image_data)})
>>> f.is_valid()
@@ -923,7 +928,7 @@ True
<class 'django.core.files.uploadedfile.SimpleUploadedFile'>
>>> instance = f.save()
>>> instance.image
-u'...test.png'
+<ImageFieldFile: tests/test.png>
# Edit an instance that already has the image defined in the model. This will not
# save the image again, but leave it exactly as it is.
@@ -932,14 +937,14 @@ u'...test.png'
>>> f.is_valid()
True
>>> f.cleaned_data['image']
-u'...test.png'
+<ImageFieldFile: tests/test.png>
>>> instance = f.save()
>>> instance.image
-u'...test.png'
+<ImageFieldFile: tests/test.png>
# Delete the current image since this is not done by Django.
->>> os.unlink(instance.get_image_filename())
+>>> instance.image.delete()
# Override the file by uploading a new one.
@@ -948,10 +953,10 @@ u'...test.png'
True
>>> instance = f.save()
>>> instance.image
-u'...test2.png'
+<ImageFieldFile: tests/test2.png>
# Delete the current file since this is not done by Django.
->>> os.unlink(instance.get_image_filename())
+>>> instance.image.delete()
>>> instance.delete()
>>> f = ImageFileForm(data={'description': u'Changed it'}, files={'image': SimpleUploadedFile('test2.png', image_data)})
@@ -959,10 +964,10 @@ u'...test2.png'
True
>>> instance = f.save()
>>> instance.image
-u'...test2.png'
+<ImageFieldFile: tests/test2.png>
# Delete the current file since this is not done by Django.
->>> os.unlink(instance.get_image_filename())
+>>> instance.image.delete()
>>> instance.delete()
# Test the non-required ImageField
@@ -973,17 +978,17 @@ u'...test2.png'
True
>>> instance = f.save()
>>> instance.image
-''
+<ImageFieldFile: None>
>>> f = ImageFileForm(data={'description': u'And a final one'}, files={'image': SimpleUploadedFile('test3.png', image_data)}, instance=instance)
>>> f.is_valid()
True
>>> instance = f.save()
>>> instance.image
-u'...test3.png'
+<ImageFieldFile: tests/test3.png>
# Delete the current file since this is not done by Django.
->>> os.unlink(instance.get_image_filename())
+>>> instance.image.delete()
>>> instance.delete()
>>> f = ImageFileForm(data={'description': u'And a final one'}, files={'image': SimpleUploadedFile('test3.png', image_data)})
@@ -991,7 +996,7 @@ u'...test3.png'
True
>>> instance = f.save()
>>> instance.image
-u'...test3.png'
+<ImageFieldFile: tests/test3.png>
>>> instance.delete()
# Media on a ModelForm ########################################################
diff --git a/tests/regressiontests/admin_widgets/models.py b/tests/regressiontests/admin_widgets/models.py
index 584d973c83..544806f819 100644
--- a/tests/regressiontests/admin_widgets/models.py
+++ b/tests/regressiontests/admin_widgets/models.py
@@ -1,6 +1,7 @@
from django.conf import settings
from django.db import models
+from django.core.files.storage import default_storage
class Member(models.Model):
name = models.CharField(max_length=100)
@@ -18,6 +19,7 @@ class Band(models.Model):
class Album(models.Model):
band = models.ForeignKey(Band)
name = models.CharField(max_length=100)
+ cover_art = models.ImageField(upload_to='albums')
def __unicode__(self):
return self.name
@@ -46,12 +48,12 @@ HTML escaped.
>>> print conditional_escape(w.render('test', datetime(2007, 12, 1, 9, 30)))
<p class="datetime">Date: <input value="2007-12-01" type="text" class="vDateField" name="test_0" size="10" /><br />Time: <input value="09:30:00" type="text" class="vTimeField" name="test_1" size="8" /></p>
->>> w = AdminFileWidget()
->>> print conditional_escape(w.render('test', 'test'))
-Currently: <a target="_blank" href="%(MEDIA_URL)stest">test</a> <br />Change: <input type="file" name="test" />
-
>>> band = Band.objects.create(pk=1, name='Linkin Park')
->>> album = band.album_set.create(name='Hybrid Theory')
+>>> album = band.album_set.create(name='Hybrid Theory', cover_art=r'albums\hybrid_theory.jpg')
+
+>>> w = AdminFileWidget()
+>>> print conditional_escape(w.render('test', album.cover_art))
+Currently: <a target="_blank" href="%(STORAGE_URL)salbums/hybrid_theory.jpg">albums\hybrid_theory.jpg</a> <br />Change: <input type="file" name="test" />
>>> rel = Album._meta.get_field('band').rel
>>> w = ForeignKeyRawIdWidget(rel)
@@ -81,5 +83,5 @@ True
""" % {
'ADMIN_MEDIA_PREFIX': settings.ADMIN_MEDIA_PREFIX,
- 'MEDIA_URL': settings.MEDIA_URL,
+ 'STORAGE_URL': default_storage.url(''),
}}
diff --git a/tests/regressiontests/bug639/models.py b/tests/regressiontests/bug639/models.py
index fc241aba8c..22dd440fc3 100644
--- a/tests/regressiontests/bug639/models.py
+++ b/tests/regressiontests/bug639/models.py
@@ -1,16 +1,20 @@
import tempfile
+
from django.db import models
+from django.core.files.storage import FileSystemStorage
+
+temp_storage = FileSystemStorage(tempfile.gettempdir())
class Photo(models.Model):
title = models.CharField(max_length=30)
- image = models.FileField(upload_to=tempfile.gettempdir())
+ image = models.FileField(storage=temp_storage, upload_to='tests')
# Support code for the tests; this keeps track of how many times save() gets
# called on each instance.
def __init__(self, *args, **kwargs):
- super(Photo, self).__init__(*args, **kwargs)
- self._savecount = 0
+ super(Photo, self).__init__(*args, **kwargs)
+ self._savecount = 0
def save(self):
super(Photo, self).save()
- self._savecount +=1 \ No newline at end of file
+ self._savecount += 1
diff --git a/tests/regressiontests/bug639/tests.py b/tests/regressiontests/bug639/tests.py
index 2726dec897..69e4a3ba3b 100644
--- a/tests/regressiontests/bug639/tests.py
+++ b/tests/regressiontests/bug639/tests.py
@@ -36,4 +36,4 @@ class Bug639Test(unittest.TestCase):
Make sure to delete the "uploaded" file to avoid clogging /tmp.
"""
p = Photo.objects.get()
- os.unlink(p.get_image_filename())
+ p.image.delete(save=False)
diff --git a/tests/regressiontests/file_storage/__init__.py b/tests/regressiontests/file_storage/__init__.py
new file mode 100644
index 0000000000..8b13789179
--- /dev/null
+++ b/tests/regressiontests/file_storage/__init__.py
@@ -0,0 +1 @@
+
diff --git a/tests/regressiontests/file_storage/models.py b/tests/regressiontests/file_storage/models.py
new file mode 100644
index 0000000000..8cd8b9e56c
--- /dev/null
+++ b/tests/regressiontests/file_storage/models.py
@@ -0,0 +1,44 @@
+import os
+import tempfile
+from django.db import models
+from django.core.files.storage import FileSystemStorage
+from django.core.files.base import ContentFile
+
+temp_storage = FileSystemStorage(tempfile.gettempdir())
+
+# Test for correct behavior of width_field/height_field.
+# Of course, we can't run this without PIL.
+
+try:
+ # Checking for the existence of Image is enough for CPython, but
+ # for PyPy, you need to check for the underlying modules
+ import Image, _imaging
+except ImportError:
+ Image = None
+
+# If we have PIL, do these tests
+if Image:
+ class Person(models.Model):
+ name = models.CharField(max_length=50)
+ mugshot = models.ImageField(storage=temp_storage, upload_to='tests',
+ height_field='mug_height',
+ width_field='mug_width')
+ mug_height = models.PositiveSmallIntegerField()
+ mug_width = models.PositiveSmallIntegerField()
+
+ __test__ = {'API_TESTS': """
+
+>>> image_data = open(os.path.join(os.path.dirname(__file__), "test.png"), 'rb').read()
+>>> p = Person(name="Joe")
+>>> p.mugshot.save("mug", ContentFile(image_data))
+>>> p.mugshot.width
+16
+>>> p.mugshot.height
+16
+>>> p.mug_height
+16
+>>> p.mug_width
+16
+
+"""}
+ \ No newline at end of file
diff --git a/tests/regressiontests/file_storage/test.png b/tests/regressiontests/file_storage/test.png
new file mode 100644
index 0000000000..4f17cd075d
--- /dev/null
+++ b/tests/regressiontests/file_storage/test.png
Binary files differ
diff --git a/tests/regressiontests/file_storage/tests.py b/tests/regressiontests/file_storage/tests.py
new file mode 100644
index 0000000000..a4503d9805
--- /dev/null
+++ b/tests/regressiontests/file_storage/tests.py
@@ -0,0 +1,66 @@
+"""
+Tests for the file storage mechanism
+
+>>> import tempfile
+>>> from django.core.files.storage import FileSystemStorage
+>>> from django.core.files.base import ContentFile
+
+>>> temp_storage = FileSystemStorage(location=tempfile.gettempdir())
+
+# Standard file access options are available, and work as expected.
+
+>>> temp_storage.exists('storage_test')
+False
+>>> file = temp_storage.open('storage_test', 'w')
+>>> file.write('storage contents')
+>>> file.close()
+
+>>> temp_storage.exists('storage_test')
+True
+>>> file = temp_storage.open('storage_test', 'r')
+>>> file.read()
+'storage contents'
+>>> file.close()
+
+>>> temp_storage.delete('storage_test')
+>>> temp_storage.exists('storage_test')
+False
+
+# Files can only be accessed if they're below the specified location.
+
+>>> temp_storage.exists('..')
+Traceback (most recent call last):
+...
+SuspiciousOperation: Attempted access to '..' denied.
+>>> temp_storage.open('/etc/passwd')
+Traceback (most recent call last):
+ ...
+SuspiciousOperation: Attempted access to '/etc/passwd' denied.
+
+# Custom storage systems can be created to customize behavior
+
+>>> class CustomStorage(FileSystemStorage):
+... def get_available_name(self, name):
+... # Append numbers to duplicate files rather than underscores, like Trac
+...
+... parts = name.split('.')
+... basename, ext = parts[0], parts[1:]
+... number = 2
+...
+... while self.exists(name):
+... name = '.'.join([basename, str(number)] + ext)
+... number += 1
+...
+... return name
+>>> custom_storage = CustomStorage(tempfile.gettempdir())
+
+>>> first = custom_storage.save('custom_storage', ContentFile('custom contents'))
+>>> first
+u'custom_storage'
+>>> second = custom_storage.save('custom_storage', ContentFile('more contents'))
+>>> second
+u'custom_storage.2'
+
+>>> custom_storage.delete(first)
+>>> custom_storage.delete(second)
+"""
diff --git a/tests/regressiontests/file_uploads/models.py b/tests/regressiontests/file_uploads/models.py
index 3701750afe..9d020509af 100644
--- a/tests/regressiontests/file_uploads/models.py
+++ b/tests/regressiontests/file_uploads/models.py
@@ -1,9 +1,10 @@
import tempfile
import os
from django.db import models
+from django.core.files.storage import FileSystemStorage
-UPLOAD_ROOT = tempfile.mkdtemp()
-UPLOAD_TO = os.path.join(UPLOAD_ROOT, 'test_upload')
+temp_storage = FileSystemStorage(tempfile.mkdtemp())
+UPLOAD_TO = os.path.join(temp_storage.location, 'test_upload')
class FileModel(models.Model):
- testfile = models.FileField(upload_to=UPLOAD_TO)
+ testfile = models.FileField(storage=temp_storage, upload_to='test_upload')
diff --git a/tests/regressiontests/file_uploads/tests.py b/tests/regressiontests/file_uploads/tests.py
index dd6b7c4181..7c8b53ea89 100644
--- a/tests/regressiontests/file_uploads/tests.py
+++ b/tests/regressiontests/file_uploads/tests.py
@@ -9,7 +9,7 @@ from django.test import TestCase, client
from django.utils import simplejson
from django.utils.hashcompat import sha_constructor
-from models import FileModel, UPLOAD_ROOT, UPLOAD_TO
+from models import FileModel, temp_storage, UPLOAD_TO
class FileUploadTests(TestCase):
def test_simple_upload(self):
@@ -194,22 +194,22 @@ class DirectoryCreationTests(unittest.TestCase):
"""
def setUp(self):
self.obj = FileModel()
- if not os.path.isdir(UPLOAD_ROOT):
- os.makedirs(UPLOAD_ROOT)
+ if not os.path.isdir(temp_storage.location):
+ os.makedirs(temp_storage.location)
def tearDown(self):
- os.chmod(UPLOAD_ROOT, 0700)
- shutil.rmtree(UPLOAD_ROOT)
+ os.chmod(temp_storage.location, 0700)
+ shutil.rmtree(temp_storage.location)
def test_readonly_root(self):
"""Permission errors are not swallowed"""
- os.chmod(UPLOAD_ROOT, 0500)
+ os.chmod(temp_storage.location, 0500)
try:
- self.obj.save_testfile_file('foo.txt', SimpleUploadedFile('foo.txt', 'x'))
+ self.obj.testfile.save('foo.txt', SimpleUploadedFile('foo.txt', 'x'))
except OSError, err:
self.assertEquals(err.errno, errno.EACCES)
- except:
- self.fail("OSError [Errno %s] not raised" % errno.EACCES)
+ except Exception, err:
+ self.fail("OSError [Errno %s] not raised." % errno.EACCES)
def test_not_a_directory(self):
"""The correct IOError is raised when the upload directory name exists but isn't a directory"""
@@ -217,11 +217,11 @@ class DirectoryCreationTests(unittest.TestCase):
fd = open(UPLOAD_TO, 'w')
fd.close()
try:
- self.obj.save_testfile_file('foo.txt', SimpleUploadedFile('foo.txt', 'x'))
+ self.obj.testfile.save('foo.txt', SimpleUploadedFile('foo.txt', 'x'))
except IOError, err:
# The test needs to be done on a specific string as IOError
# is raised even without the patch (just not early enough)
self.assertEquals(err.args[0],
- "%s exists and is not a directory" % UPLOAD_TO)
+ "%s exists and is not a directory." % UPLOAD_TO)
except:
self.fail("IOError not raised")
diff --git a/tests/regressiontests/serializers_regress/models.py b/tests/regressiontests/serializers_regress/models.py
index 7d3f9d3b1d..4e2fbb1ee2 100644
--- a/tests/regressiontests/serializers_regress/models.py
+++ b/tests/regressiontests/serializers_regress/models.py
@@ -157,8 +157,8 @@ class DecimalPKData(models.Model):
class EmailPKData(models.Model):
data = models.EmailField(primary_key=True)
-class FilePKData(models.Model):
- data = models.FileField(primary_key=True, upload_to='/foo/bar')
+# class FilePKData(models.Model):
+# data = models.FileField(primary_key=True, upload_to='/foo/bar')
class FilePathPKData(models.Model):
data = models.FilePathField(primary_key=True)
diff --git a/tests/regressiontests/serializers_regress/tests.py b/tests/regressiontests/serializers_regress/tests.py
index f990d57a17..7a38af4cf9 100644
--- a/tests/regressiontests/serializers_regress/tests.py
+++ b/tests/regressiontests/serializers_regress/tests.py
@@ -144,7 +144,7 @@ test_data = [
(data_obj, 41, EmailData, None),
(data_obj, 42, EmailData, ""),
(data_obj, 50, FileData, 'file:///foo/bar/whiz.txt'),
- (data_obj, 51, FileData, None),
+# (data_obj, 51, FileData, None),
(data_obj, 52, FileData, ""),
(data_obj, 60, FilePathData, "/foo/bar/whiz.txt"),
(data_obj, 61, FilePathData, None),
@@ -242,7 +242,7 @@ The end."""),
# (pk_obj, 620, DatePKData, datetime.date(2006,6,16)),
# (pk_obj, 630, DateTimePKData, datetime.datetime(2006,6,16,10,42,37)),
(pk_obj, 640, EmailPKData, "hovercraft@example.com"),
- (pk_obj, 650, FilePKData, 'file:///foo/bar/whiz.txt'),
+# (pk_obj, 650, FilePKData, 'file:///foo/bar/whiz.txt'),
(pk_obj, 660, FilePathPKData, "/foo/bar/whiz.txt"),
(pk_obj, 670, DecimalPKData, decimal.Decimal('12.345')),
(pk_obj, 671, DecimalPKData, decimal.Decimal('-12.345')),