summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2009-04-18 20:34:42 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2009-04-18 20:34:42 +0000
commit283442a50e1acdbc101096980d0d2c656890710c (patch)
tree00f14f64ba4205662d3eb20a63576f5a1716f247 /tests
parent01669a356ae8d10a4332c6f21590176b6bedfe0c (diff)
[1.0.X] Fixed #10002: inline file uploads now correctly display prior data. Thanks, dgouldin. Backport of r10588 from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10589 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/admin_views/models.py26
-rw-r--r--tests/regressiontests/admin_views/tests.py50
2 files changed, 74 insertions, 2 deletions
diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py
index d9ac372da0..5a451c5436 100644
--- a/tests/regressiontests/admin_views/models.py
+++ b/tests/regressiontests/admin_views/models.py
@@ -1,4 +1,7 @@
# -*- coding: utf-8 -*-
+import tempfile
+import os
+from django.core.files.storage import FileSystemStorage
from django.db import models
from django.contrib import admin
@@ -214,6 +217,27 @@ class EmptyModelAdmin(admin.ModelAdmin):
def queryset(self, request):
return super(EmptyModelAdmin, self).queryset(request).filter(pk__gt=1)
+temp_storage = FileSystemStorage(tempfile.mkdtemp())
+UPLOAD_TO = os.path.join(temp_storage.location, 'test_upload')
+
+class Gallery(models.Model):
+ name = models.CharField(max_length=100)
+
+class Picture(models.Model):
+ name = models.CharField(max_length=100)
+ image = models.FileField(storage=temp_storage, upload_to='test_upload')
+ gallery = models.ForeignKey(Gallery, related_name="pictures")
+
+class PictureInline(admin.TabularInline):
+ model = Picture
+ extra = 1
+
+class GalleryAdmin(admin.ModelAdmin):
+ inlines = [PictureInline]
+
+class PictureAdmin(admin.ModelAdmin):
+ pass
+
admin.site.register(Article, ArticleAdmin)
admin.site.register(CustomArticle, CustomArticleAdmin)
admin.site.register(Section, inlines=[ArticleInline])
@@ -224,6 +248,8 @@ admin.site.register(Persona, PersonaAdmin)
admin.site.register(Parent, ParentAdmin)
admin.site.register(EmptyModel, EmptyModelAdmin)
admin.site.register(Fabric, FabricAdmin)
+admin.site.register(Gallery, GalleryAdmin)
+admin.site.register(Picture, PictureAdmin)
# We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2.
# That way we cover all four cases:
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
index e1a23da37e..e8874ec67a 100644
--- a/tests/regressiontests/admin_views/tests.py
+++ b/tests/regressiontests/admin_views/tests.py
@@ -2,6 +2,7 @@
import re
+from django.core.files import temp as tempfile
from django.test import TestCase
from django.contrib.auth.models import User, Permission
from django.contrib.contenttypes.models import ContentType
@@ -11,7 +12,9 @@ from django.contrib.admin.util import quote
from django.utils.html import escape
# local test models
-from models import Article, CustomArticle, Section, ModelWithStringPrimaryKey, Persona, FooAccount, BarAccount, EmptyModel
+from models import (Article, BarAccount, CustomArticle, EmptyModel,
+ FooAccount, Gallery, ModelWithStringPrimaryKey,
+ Persona, Picture, Section)
try:
set
@@ -868,7 +871,6 @@ class TestInlineNotEditable(TestCase):
response = self.client.get('/test_admin/admin/admin_views/parent/add/')
self.failUnlessEqual(response.status_code, 200)
-
class AdminCustomQuerysetTest(TestCase):
fixtures = ['admin-views-users.xml']
@@ -891,3 +893,47 @@ class AdminCustomQuerysetTest(TestCase):
self.assertEqual(response.status_code, 200)
else:
self.assertEqual(response.status_code, 404)
+
+class AdminInlineFileUploadTest(TestCase):
+ fixtures = ['admin-views-users.xml', 'admin-views-actions.xml']
+ urlbit = 'admin'
+
+ def setUp(self):
+ self.client.login(username='super', password='secret')
+
+ # Set up test Picture and Gallery.
+ # These must be set up here instead of in fixtures in order to allow Picture
+ # to use a NamedTemporaryFile.
+ tdir = tempfile.gettempdir()
+ file1 = tempfile.NamedTemporaryFile(suffix=".file1", dir=tdir)
+ file1.write('a' * (2 ** 21))
+ filename = file1.name
+ file1.close()
+ g = Gallery(name="Test Gallery")
+ g.save()
+ p = Picture(name="Test Picture", image=filename, gallery=g)
+ p.save()
+
+ def tearDown(self):
+ self.client.logout()
+
+ def test_inline_file_upload_edit_validation_error_post(self):
+ """
+ Test that inline file uploads correctly display prior data (#10002).
+ """
+ post_data = {
+ "name": u"Test Gallery",
+ "pictures-TOTAL_FORMS": u"2",
+ "pictures-INITIAL_FORMS": u"1",
+ "pictures-0-id": u"1",
+ "pictures-0-gallery": u"1",
+ "pictures-0-name": "Test Picture",
+ "pictures-0-image": "",
+ "pictures-1-id": "",
+ "pictures-1-gallery": "1",
+ "pictures-1-name": "Test Picture 2",
+ "pictures-1-image": "",
+ }
+ response = self.client.post('/test_admin/%s/admin_views/gallery/1/' % self.urlbit, post_data)
+ self.failUnless(response._container[0].find("Currently:") > -1)
+