[Checkins] SVN: zope.app.file/trunk/ Get ready for 3.4.0 release.

Stephan Richter srichter at cosmos.phy.tufts.edu
Wed Oct 24 10:08:54 EDT 2007


Log message for revision 81031:
  Get ready for 3.4.0 release.
  

Changed:
  A   zope.app.file/trunk/CHANGES.txt
  A   zope.app.file/trunk/README.txt
  U   zope.app.file/trunk/buildout.cfg
  D   zope.app.file/trunk/setup.cfg
  U   zope.app.file/trunk/setup.py
  U   zope.app.file/trunk/src/zope/app/file/browser/file.py
  D   zope.app.file/trunk/src/zope/app/file/browser/ftests.py
  A   zope.app.file/trunk/src/zope/app/file/browser/tests/test_functional.py

-=-
Added: zope.app.file/trunk/CHANGES.txt
===================================================================
--- zope.app.file/trunk/CHANGES.txt	                        (rev 0)
+++ zope.app.file/trunk/CHANGES.txt	2007-10-24 14:08:53 UTC (rev 81031)
@@ -0,0 +1,8 @@
+=======
+CHANGES
+=======
+
+3.4.0 (2007-10-24)
+------------------
+
+- Initial release independent of the main Zope tree.


Property changes on: zope.app.file/trunk/CHANGES.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: zope.app.file/trunk/README.txt
===================================================================
--- zope.app.file/trunk/README.txt	                        (rev 0)
+++ zope.app.file/trunk/README.txt	2007-10-24 14:08:53 UTC (rev 81031)
@@ -0,0 +1,2 @@
+This package provides two basic Zope 3 content components, File and Image, and
+their ZMI-compliant browser views.


Property changes on: zope.app.file/trunk/README.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: zope.app.file/trunk/buildout.cfg
===================================================================
--- zope.app.file/trunk/buildout.cfg	2007-10-24 13:59:10 UTC (rev 81030)
+++ zope.app.file/trunk/buildout.cfg	2007-10-24 14:08:53 UTC (rev 81031)
@@ -1,10 +1,8 @@
 [buildout]
-develop = . 
+develop = .
 parts = test
-find-links = http://download.zope.org/distribution/
 
 [test]
 recipe = zc.recipe.testrunner
-defaults = ['--tests-pattern', '^f?tests$']
 eggs = zope.app.file [test]
 

Deleted: zope.app.file/trunk/setup.cfg
===================================================================
--- zope.app.file/trunk/setup.cfg	2007-10-24 13:59:10 UTC (rev 81030)
+++ zope.app.file/trunk/setup.cfg	2007-10-24 14:08:53 UTC (rev 81031)
@@ -1,2 +0,0 @@
-[egg_info]
-tag_svn_revision = 1
\ No newline at end of file

Modified: zope.app.file/trunk/setup.py
===================================================================
--- zope.app.file/trunk/setup.py	2007-10-24 13:59:10 UTC (rev 81030)
+++ zope.app.file/trunk/setup.py	2007-10-24 14:08:53 UTC (rev 81031)
@@ -15,18 +15,44 @@
 
 $Id$
 """
-
 import os
+from setuptools import setup, find_packages
 
-from setuptools import setup, find_packages, Extension
+def read(*rnames):
+    return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
 
 setup(name='zope.app.file',
-      version = '3.4.0b1',
-      url='http://svn.zope.org/zope.app.file',
-      license='ZPL 2.1',
-      description='Zope file',
+      version = '3.4.0',
       author='Zope Corporation and Contributors',
       author_email='zope3-dev at zope.org',
+      description='File and Image -- Zope 3 Content Components',
+      long_description=(
+          read('README.txt')
+          + '\n\n' +
+          + 'Detailed Dcoumentation\n' +
+          + '----------------------\n'
+          + '\n\n' +
+          read('src', 'zope', 'app', 'file', 'browser', 'file.txt')
+          + '\n\n' +
+          read('src', 'zope', 'app', 'file', 'browser', 'image.txt')
+          + '\n\n' +
+          read('src', 'zope', 'app', 'file', 'browser', 'url.txt')
+          + '\n\n' +
+          read('CHANGES.txt')
+          ),
+      keywords = "zope3 file image content",
+      classifiers = [
+          'Development Status :: 5 - Production/Stable',
+          'Environment :: Web Environment',
+          'Intended Audience :: Developers',
+          'License :: OSI Approved :: Zope Public License',
+          'Programming Language :: Python',
+          'Natural Language :: English',
+          'Operating System :: OS Independent',
+          'Topic :: Internet :: WWW/HTTP',
+          'Framework :: Zope3'],
+      url='http://cheeseshop.python.org/pypi/zope.app.file',
+      license='ZPL 2.1',
       packages=find_packages('src'),
       package_dir = {'': 'src'},
       namespace_packages=['zope', 'zope.app'],

Modified: zope.app.file/trunk/src/zope/app/file/browser/file.py
===================================================================
--- zope.app.file/trunk/src/zope/app/file/browser/file.py	2007-10-24 13:59:10 UTC (rev 81030)
+++ zope.app.file/trunk/src/zope/app/file/browser/file.py	2007-10-24 14:08:53 UTC (rev 81031)
@@ -26,7 +26,7 @@
 from zope.app.file.interfaces import IFile
 from zope.app.file.i18n import ZopeMessageFactory as _
 from zope.dublincore.interfaces import IZopeDublinCore
-import zope.datetime 
+import zope.datetime
 
 import time
 from datetime import datetime
@@ -64,7 +64,7 @@
 
         If the file is adaptable to IZopeDublinCore the
         "Last-Modified" header is also set.
-        
+
         >>> request.response.getHeader('Last-Modified') is None
         True
 
@@ -78,20 +78,20 @@
         'data of file'
         >>> request.response.getHeader('Last-Modified')
         'Sun, 01 Jan 2006 00:00:00 GMT'
-        
+
         If the "If-Modified-Since" header is set and is newer a 304
         status is returned and the value is empty.
-        
+
         >>> modified = datetime(2007,12,31,tzinfo=pytz.utc)
         >>> modHeader = zope.datetime.rfc1123_date(zope.datetime.time(modified.isoformat()))
         >>> request = TestRequest(IF_MODIFIED_SINCE=modHeader)
-        
+
         >>> view = FileTestView(aFile,request)
         >>> view.show()
         ''
         >>> request.response.getStatus()
         304
-        
+
         """
 
         if self.request is not None:
@@ -105,7 +105,7 @@
             modified=None
         if modified is None or not isinstance(modified,datetime):
             return self.context.data
-        
+
         header= self.request.getHeader('If-Modified-Since', None)
         lmt = zope.datetime.time(modified.isoformat())
         if header is not None:

Deleted: zope.app.file/trunk/src/zope/app/file/browser/ftests.py
===================================================================
--- zope.app.file/trunk/src/zope/app/file/browser/ftests.py	2007-10-24 13:59:10 UTC (rev 81030)
+++ zope.app.file/trunk/src/zope/app/file/browser/ftests.py	2007-10-24 14:08:53 UTC (rev 81031)
@@ -1,331 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2003, 2004 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Functional tests for File and Image.
-
-$Id$
-"""
-
-import re
-import unittest
-from xml.sax.saxutils import escape
-from StringIO import StringIO
-from zope.testing import renormalizing
-
-from zope.app.testing import functional
-from zope.app.testing.functional import BrowserTestCase
-from zope.app.file.file import File
-from zope.app.file.image import Image
-from zope.app.file.tests.test_image import zptlogo
-from zope.app.file.testing import AppFileLayer
-
-
-class FileTest(BrowserTestCase):
-
-    content = u'File <Data>'
-
-    def addFile(self):
-        file = File(self.content)
-        root = self.getRootFolder()
-        root['file'] = file
-        self.commit()
-
-    def testAddForm(self):
-        response = self.publish(
-            '/+/zope.app.file.File=',
-            basic='mgr:mgrpw')
-        self.assertEqual(response.getStatus(), 200)
-        body = response.getBody()
-        self.assert_('Add a File' in body)
-        self.assert_('Content Type' in body)
-        self.assert_('Data' in body)
-        self.assert_('Object Name' in body)
-        self.assert_('"Add"' in body)
-        self.checkForBrokenLinks(body, '/+/zope.app.file.File=',
-                                 'mgr:mgrpw')
-
-    def testAdd(self):
-        response = self.publish(
-            '/+/zope.app.file.File=',
-            form={'type_name': u'zope.app.file.File',
-                  'field.data': StringIO('A file'),
-                  'field.data.used': '',
-                  'add_input_name': u'file',
-                  'UPDATE_SUBMIT': u'Add'},
-            basic='mgr:mgrpw')
-        self.assertEqual(response.getStatus(), 302)
-        self.assertEqual(response.getHeader('Location'),
-                         'http://localhost/@@contents.html')
-        root = self.getRootFolder()
-        self.assert_('file' in root)
-        file = root['file']
-        self.assertEqual(file.data, 'A file')
-
-    def testAddWithoutName(self):
-        data = StringIO('File Contents')
-        data.filename="test.txt"
-        response = self.publish(
-            '/+/zope.app.file.File=',
-            form={'type_name': u'zope.app.file.File',
-                  'field.data': data,
-                  'field.data.used': '',
-                  'UPDATE_SUBMIT': u'Add'},
-            basic='mgr:mgrpw')
-        self.assertEqual(response.getStatus(), 302)
-        self.assertEqual(response.getHeader('Location'),
-                         'http://localhost/@@contents.html')
-        root = self.getRootFolder()
-        self.assert_('test.txt' in root)
-        file = root['test.txt']
-        self.assertEqual(file.data, 'File Contents')
-
-    def testEditForm(self):
-        self.addFile()
-        response = self.publish(
-            '/file/@@edit.html',
-            basic='mgr:mgrpw')
-        self.assertEqual(response.getStatus(), 200)
-        body = response.getBody()
-        self.assert_('Change a file' in body)
-        self.assert_('Content Type' in body)
-        self.assert_('Data' in body)
-        self.assert_(escape(self.content) in body)
-        self.checkForBrokenLinks(body, '/file/@@edit.html', 'mgr:mgrpw')
-
-    def testEdit(self):
-        self.addFile()
-        response = self.publish(
-            '/file/@@edit.html',
-            form={'field.data': u'<h1>A File</h1>',
-                  'field.data.used': '',
-                  'field.contentType': u'text/plain',
-                  'UPDATE_SUBMIT': u'Edit'},
-            basic='mgr:mgrpw')
-        self.assertEqual(response.getStatus(), 200)
-        body = response.getBody()
-        self.assert_('Change a file' in body)
-        self.assert_('Content Type' in body)
-        self.assert_('Data' in body)
-        self.assert_(escape(u'<h1>A File</h1>') in body)
-        root = self.getRootFolder()
-        file = root['file']
-        self.assertEqual(file.data, '<h1>A File</h1>')
-        self.assertEqual(file.contentType, 'text/plain')
-
-    def testUploadForm(self):
-        self.addFile()
-        response = self.publish(
-            '/file/@@upload.html',
-            basic='mgr:mgrpw')
-        self.assertEqual(response.getStatus(), 200)
-        body = response.getBody()
-        self.assert_('Upload a file' in body)
-        self.assert_('Content Type' in body)
-        self.assert_('Data' in body)
-        self.failIf(escape(self.content) in body)
-        self.checkForBrokenLinks(body, '/file/@@upload.html', 'mgr:mgrpw')
-
-    def testUpload(self):
-        self.addFile()
-        response = self.publish(
-            '/file/@@upload.html',
-            form={'field.data': StringIO('<h1>A file</h1>'),
-                  'field.data.used': '',
-                  'field.contentType': u'text/plain',
-                  'UPDATE_SUBMIT': u'Change'},
-            basic='mgr:mgrpw')
-        self.assertEqual(response.getStatus(), 200)
-        body = response.getBody()
-        self.assert_('Upload a file' in body)
-        self.assert_('Content Type' in body)
-        self.assert_('Data' in body)
-        self.failIf(escape(u'<h1>A File</h1>') in body)
-        root = self.getRootFolder()
-        file = root['file']
-        self.assertEqual(file.data, '<h1>A file</h1>')
-        self.assertEqual(file.contentType, 'text/plain')
-
-    def testIndex(self):
-        self.addFile()
-        response = self.publish(
-            '/file/@@index.html',
-            basic='mgr:mgrpw')
-        self.assertEqual(response.getStatus(), 200)
-        body = response.getBody()
-        self.assertEqual(body, self.content)
-        self.checkForBrokenLinks(body, '/file/@@index.html', 'mgr:mgrpw')
-
-    def testPreview(self):
-        self.addFile()
-        response = self.publish(
-            '/file/@@preview.html',
-            basic='mgr:mgrpw')
-        self.assertEqual(response.getStatus(), 200)
-        body = response.getBody()
-        self.assert_('<iframe src="."' in body)
-        self.checkForBrokenLinks(body, '/file/@@preview.html', 'mgr:mgrpw')
-
-
-class ImageTest(BrowserTestCase):
-
-    content = zptlogo
-
-    def addImage(self):
-        image = Image(self.content)
-        root = self.getRootFolder()
-        root['image'] = image
-        self.commit()
-
-    def testAddForm(self):
-        response = self.publish(
-            '/+/zope.app.file.Image=',
-            basic='mgr:mgrpw')
-        self.assertEqual(response.getStatus(), 200)
-        body = response.getBody()
-        self.assert_('Add an Image' in body)
-        self.assert_('Content Type' in body)
-        self.assert_('Data' in body)
-        self.assert_('Object Name' in body)
-        self.assert_('"Add"' in body)
-        self.checkForBrokenLinks(body, '/+/zope.app.file.Image=',
-                                 'mgr:mgrpw')
-
-    def testAdd(self):
-        response = self.publish(
-            '/+/zope.app.file.Image=',
-            form={'type_name': u'zope.app.image.Image',
-                  'field.data': StringIO(self.content),
-                  'field.data.used': '',
-                  'add_input_name': u'image',
-                  'UPDATE_SUBMIT': u'Add'},
-            basic='mgr:mgrpw')
-        self.assertEqual(response.getStatus(), 302)
-        self.assertEqual(response.getHeader('Location'),
-                         'http://localhost/@@contents.html')
-        root = self.getRootFolder()
-        self.assert_('image' in root)
-        image = root['image']
-        self.assertEqual(image.data, self.content)
-
-    def testAddWithoutName(self):
-        data = StringIO(self.content)
-        data.filename="test.gif"
-        response = self.publish(
-            '/+/zope.app.file.Image=',
-            form={'type_name': u'zope.app.image.Image',
-                  'field.data': data,
-                  'field.data.used': '',
-                  'UPDATE_SUBMIT': u'Add'},
-            basic='mgr:mgrpw')
-        self.assertEqual(response.getStatus(), 302)
-        self.assertEqual(response.getHeader('Location'),
-                         'http://localhost/@@contents.html')
-        root = self.getRootFolder()
-        self.assert_('test.gif' in root)
-        image = root['test.gif']
-        self.assertEqual(image.data, self.content)
-
-    def testUploadForm(self):
-        self.addImage()
-        response = self.publish(
-            '/image/@@upload.html',
-            basic='mgr:mgrpw')
-        self.assertEqual(response.getStatus(), 200)
-        body = response.getBody()
-        self.assert_('Upload an image' in body)
-        self.assert_('Content Type' in body)
-        self.assert_('Data' in body)
-        self.assert_('1 KB 16x16' in body)
-        self.checkForBrokenLinks(body, '/image/@@upload.html', 'mgr:mgrpw')
-
-    def testUpload(self):
-        self.addImage()
-        response = self.publish(
-            '/image/@@upload.html',
-            form={'field.data': StringIO(''),
-                  'field.data.used': '',
-                  'UPDATE_SUBMIT': u'Change'},
-            basic='mgr:mgrpw')
-        self.assertEqual(response.getStatus(), 200)
-        body = response.getBody()
-        self.assert_('Upload an image' in body)
-        self.assert_('Content Type' in body)
-        self.assert_('Data' in body)
-        self.assert_('0 KB ?x?' in body)
-        root = self.getRootFolder()
-        image = root['image']
-        self.assertEqual(image.data, '')
-        self.assertEqual(image.contentType, 'image/gif')
-
-    def testUpload_only_change_content_type(self):
-        self.addImage()
-        response = self.publish(
-            '/image/@@upload.html',
-            form={'field.contentType': 'image/png',
-                  'UPDATE_SUBMIT': u'Change'},
-            basic='mgr:mgrpw')
-        self.assertEqual(response.getStatus(), 200)
-        body = response.getBody()
-        self.assert_('Upload an image' in body)
-        self.assert_('Content Type' in body)
-        self.assert_('Data' in body)
-        self.assert_('1 KB 16x16' in body)
-        root = self.getRootFolder()
-        image = root['image']
-        self.assertEqual(image.data, self.content)
-        self.assertEqual(image.contentType, 'image/png')
-
-    def testIndex(self):
-        self.addImage()
-        response = self.publish(
-            '/image/@@index.html',
-            basic='mgr:mgrpw')
-        self.assertEqual(response.getStatus(), 200)
-        body = response.getBody()
-        self.assertEqual(body, self.content)
-        self.checkForBrokenLinks(body, '/image/@@index.html', 'mgr:mgrpw')
-
-    def testPreview(self):
-        self.addImage()
-        response = self.publish(
-            '/image/@@preview.html',
-            basic='mgr:mgrpw')
-        self.assertEqual(response.getStatus(), 200)
-        body = response.getBody()
-        self.assert_('<iframe src="."' in body)
-        self.checkForBrokenLinks(body, '/image/@@preview.html', 'mgr:mgrpw')
-
-
-checker = renormalizing.RENormalizing([
-    (re.compile(r"HTTP/1\.1 200 .*"), "HTTP/1.1 200 OK"),
-    (re.compile(r"HTTP/1\.1 303 .*"), "HTTP/1.1 303 See Other"),
-    ])
-
-
-def test_suite():
-    FileTest.layer = AppFileLayer
-    ImageTest.layer = AppFileLayer
-    url = functional.FunctionalDocFileSuite('url.txt', checker=checker)
-    url.layer = AppFileLayer
-    file = functional.FunctionalDocFileSuite('file.txt', checker=checker)
-    file.layer = AppFileLayer
-    return unittest.TestSuite((
-        unittest.makeSuite(FileTest),
-        unittest.makeSuite(ImageTest),
-        url,
-        file,
-        ))
-
-
-if __name__ == '__main__':
-    unittest.main(defaultTest='test_suite')

Copied: zope.app.file/trunk/src/zope/app/file/browser/tests/test_functional.py (from rev 81029, zope.app.file/trunk/src/zope/app/file/browser/ftests.py)
===================================================================
--- zope.app.file/trunk/src/zope/app/file/browser/tests/test_functional.py	                        (rev 0)
+++ zope.app.file/trunk/src/zope/app/file/browser/tests/test_functional.py	2007-10-24 14:08:53 UTC (rev 81031)
@@ -0,0 +1,331 @@
+##############################################################################
+#
+# Copyright (c) 2003, 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Functional tests for File and Image.
+
+$Id$
+"""
+
+import re
+import unittest
+from xml.sax.saxutils import escape
+from StringIO import StringIO
+from zope.testing import renormalizing
+
+from zope.app.testing import functional
+from zope.app.testing.functional import BrowserTestCase
+from zope.app.file.file import File
+from zope.app.file.image import Image
+from zope.app.file.tests.test_image import zptlogo
+from zope.app.file.testing import AppFileLayer
+
+
+class FileTest(BrowserTestCase):
+
+    content = u'File <Data>'
+
+    def addFile(self):
+        file = File(self.content)
+        root = self.getRootFolder()
+        root['file'] = file
+        self.commit()
+
+    def testAddForm(self):
+        response = self.publish(
+            '/+/zope.app.file.File=',
+            basic='mgr:mgrpw')
+        self.assertEqual(response.getStatus(), 200)
+        body = response.getBody()
+        self.assert_('Add a File' in body)
+        self.assert_('Content Type' in body)
+        self.assert_('Data' in body)
+        self.assert_('Object Name' in body)
+        self.assert_('"Add"' in body)
+        self.checkForBrokenLinks(body, '/+/zope.app.file.File=',
+                                 'mgr:mgrpw')
+
+    def testAdd(self):
+        response = self.publish(
+            '/+/zope.app.file.File=',
+            form={'type_name': u'zope.app.file.File',
+                  'field.data': StringIO('A file'),
+                  'field.data.used': '',
+                  'add_input_name': u'file',
+                  'UPDATE_SUBMIT': u'Add'},
+            basic='mgr:mgrpw')
+        self.assertEqual(response.getStatus(), 302)
+        self.assertEqual(response.getHeader('Location'),
+                         'http://localhost/@@contents.html')
+        root = self.getRootFolder()
+        self.assert_('file' in root)
+        file = root['file']
+        self.assertEqual(file.data, 'A file')
+
+    def testAddWithoutName(self):
+        data = StringIO('File Contents')
+        data.filename="test.txt"
+        response = self.publish(
+            '/+/zope.app.file.File=',
+            form={'type_name': u'zope.app.file.File',
+                  'field.data': data,
+                  'field.data.used': '',
+                  'UPDATE_SUBMIT': u'Add'},
+            basic='mgr:mgrpw')
+        self.assertEqual(response.getStatus(), 302)
+        self.assertEqual(response.getHeader('Location'),
+                         'http://localhost/@@contents.html')
+        root = self.getRootFolder()
+        self.assert_('test.txt' in root)
+        file = root['test.txt']
+        self.assertEqual(file.data, 'File Contents')
+
+    def testEditForm(self):
+        self.addFile()
+        response = self.publish(
+            '/file/@@edit.html',
+            basic='mgr:mgrpw')
+        self.assertEqual(response.getStatus(), 200)
+        body = response.getBody()
+        self.assert_('Change a file' in body)
+        self.assert_('Content Type' in body)
+        self.assert_('Data' in body)
+        self.assert_(escape(self.content) in body)
+        self.checkForBrokenLinks(body, '/file/@@edit.html', 'mgr:mgrpw')
+
+    def testEdit(self):
+        self.addFile()
+        response = self.publish(
+            '/file/@@edit.html',
+            form={'field.data': u'<h1>A File</h1>',
+                  'field.data.used': '',
+                  'field.contentType': u'text/plain',
+                  'UPDATE_SUBMIT': u'Edit'},
+            basic='mgr:mgrpw')
+        self.assertEqual(response.getStatus(), 200)
+        body = response.getBody()
+        self.assert_('Change a file' in body)
+        self.assert_('Content Type' in body)
+        self.assert_('Data' in body)
+        self.assert_(escape(u'<h1>A File</h1>') in body)
+        root = self.getRootFolder()
+        file = root['file']
+        self.assertEqual(file.data, '<h1>A File</h1>')
+        self.assertEqual(file.contentType, 'text/plain')
+
+    def testUploadForm(self):
+        self.addFile()
+        response = self.publish(
+            '/file/@@upload.html',
+            basic='mgr:mgrpw')
+        self.assertEqual(response.getStatus(), 200)
+        body = response.getBody()
+        self.assert_('Upload a file' in body)
+        self.assert_('Content Type' in body)
+        self.assert_('Data' in body)
+        self.failIf(escape(self.content) in body)
+        self.checkForBrokenLinks(body, '/file/@@upload.html', 'mgr:mgrpw')
+
+    def testUpload(self):
+        self.addFile()
+        response = self.publish(
+            '/file/@@upload.html',
+            form={'field.data': StringIO('<h1>A file</h1>'),
+                  'field.data.used': '',
+                  'field.contentType': u'text/plain',
+                  'UPDATE_SUBMIT': u'Change'},
+            basic='mgr:mgrpw')
+        self.assertEqual(response.getStatus(), 200)
+        body = response.getBody()
+        self.assert_('Upload a file' in body)
+        self.assert_('Content Type' in body)
+        self.assert_('Data' in body)
+        self.failIf(escape(u'<h1>A File</h1>') in body)
+        root = self.getRootFolder()
+        file = root['file']
+        self.assertEqual(file.data, '<h1>A file</h1>')
+        self.assertEqual(file.contentType, 'text/plain')
+
+    def testIndex(self):
+        self.addFile()
+        response = self.publish(
+            '/file/@@index.html',
+            basic='mgr:mgrpw')
+        self.assertEqual(response.getStatus(), 200)
+        body = response.getBody()
+        self.assertEqual(body, self.content)
+        self.checkForBrokenLinks(body, '/file/@@index.html', 'mgr:mgrpw')
+
+    def testPreview(self):
+        self.addFile()
+        response = self.publish(
+            '/file/@@preview.html',
+            basic='mgr:mgrpw')
+        self.assertEqual(response.getStatus(), 200)
+        body = response.getBody()
+        self.assert_('<iframe src="."' in body)
+        self.checkForBrokenLinks(body, '/file/@@preview.html', 'mgr:mgrpw')
+
+
+class ImageTest(BrowserTestCase):
+
+    content = zptlogo
+
+    def addImage(self):
+        image = Image(self.content)
+        root = self.getRootFolder()
+        root['image'] = image
+        self.commit()
+
+    def testAddForm(self):
+        response = self.publish(
+            '/+/zope.app.file.Image=',
+            basic='mgr:mgrpw')
+        self.assertEqual(response.getStatus(), 200)
+        body = response.getBody()
+        self.assert_('Add an Image' in body)
+        self.assert_('Content Type' in body)
+        self.assert_('Data' in body)
+        self.assert_('Object Name' in body)
+        self.assert_('"Add"' in body)
+        self.checkForBrokenLinks(body, '/+/zope.app.file.Image=',
+                                 'mgr:mgrpw')
+
+    def testAdd(self):
+        response = self.publish(
+            '/+/zope.app.file.Image=',
+            form={'type_name': u'zope.app.image.Image',
+                  'field.data': StringIO(self.content),
+                  'field.data.used': '',
+                  'add_input_name': u'image',
+                  'UPDATE_SUBMIT': u'Add'},
+            basic='mgr:mgrpw')
+        self.assertEqual(response.getStatus(), 302)
+        self.assertEqual(response.getHeader('Location'),
+                         'http://localhost/@@contents.html')
+        root = self.getRootFolder()
+        self.assert_('image' in root)
+        image = root['image']
+        self.assertEqual(image.data, self.content)
+
+    def testAddWithoutName(self):
+        data = StringIO(self.content)
+        data.filename="test.gif"
+        response = self.publish(
+            '/+/zope.app.file.Image=',
+            form={'type_name': u'zope.app.image.Image',
+                  'field.data': data,
+                  'field.data.used': '',
+                  'UPDATE_SUBMIT': u'Add'},
+            basic='mgr:mgrpw')
+        self.assertEqual(response.getStatus(), 302)
+        self.assertEqual(response.getHeader('Location'),
+                         'http://localhost/@@contents.html')
+        root = self.getRootFolder()
+        self.assert_('test.gif' in root)
+        image = root['test.gif']
+        self.assertEqual(image.data, self.content)
+
+    def testUploadForm(self):
+        self.addImage()
+        response = self.publish(
+            '/image/@@upload.html',
+            basic='mgr:mgrpw')
+        self.assertEqual(response.getStatus(), 200)
+        body = response.getBody()
+        self.assert_('Upload an image' in body)
+        self.assert_('Content Type' in body)
+        self.assert_('Data' in body)
+        self.assert_('1 KB 16x16' in body)
+        self.checkForBrokenLinks(body, '/image/@@upload.html', 'mgr:mgrpw')
+
+    def testUpload(self):
+        self.addImage()
+        response = self.publish(
+            '/image/@@upload.html',
+            form={'field.data': StringIO(''),
+                  'field.data.used': '',
+                  'UPDATE_SUBMIT': u'Change'},
+            basic='mgr:mgrpw')
+        self.assertEqual(response.getStatus(), 200)
+        body = response.getBody()
+        self.assert_('Upload an image' in body)
+        self.assert_('Content Type' in body)
+        self.assert_('Data' in body)
+        self.assert_('0 KB ?x?' in body)
+        root = self.getRootFolder()
+        image = root['image']
+        self.assertEqual(image.data, '')
+        self.assertEqual(image.contentType, 'image/gif')
+
+    def testUpload_only_change_content_type(self):
+        self.addImage()
+        response = self.publish(
+            '/image/@@upload.html',
+            form={'field.contentType': 'image/png',
+                  'UPDATE_SUBMIT': u'Change'},
+            basic='mgr:mgrpw')
+        self.assertEqual(response.getStatus(), 200)
+        body = response.getBody()
+        self.assert_('Upload an image' in body)
+        self.assert_('Content Type' in body)
+        self.assert_('Data' in body)
+        self.assert_('1 KB 16x16' in body)
+        root = self.getRootFolder()
+        image = root['image']
+        self.assertEqual(image.data, self.content)
+        self.assertEqual(image.contentType, 'image/png')
+
+    def testIndex(self):
+        self.addImage()
+        response = self.publish(
+            '/image/@@index.html',
+            basic='mgr:mgrpw')
+        self.assertEqual(response.getStatus(), 200)
+        body = response.getBody()
+        self.assertEqual(body, self.content)
+        self.checkForBrokenLinks(body, '/image/@@index.html', 'mgr:mgrpw')
+
+    def testPreview(self):
+        self.addImage()
+        response = self.publish(
+            '/image/@@preview.html',
+            basic='mgr:mgrpw')
+        self.assertEqual(response.getStatus(), 200)
+        body = response.getBody()
+        self.assert_('<iframe src="."' in body)
+        self.checkForBrokenLinks(body, '/image/@@preview.html', 'mgr:mgrpw')
+
+
+checker = renormalizing.RENormalizing([
+    (re.compile(r"HTTP/1\.1 200 .*"), "HTTP/1.1 200 OK"),
+    (re.compile(r"HTTP/1\.1 303 .*"), "HTTP/1.1 303 See Other"),
+    ])
+
+
+def test_suite():
+    FileTest.layer = AppFileLayer
+    ImageTest.layer = AppFileLayer
+    url = functional.FunctionalDocFileSuite('url.txt', checker=checker)
+    url.layer = AppFileLayer
+    file = functional.FunctionalDocFileSuite('file.txt', checker=checker)
+    file.layer = AppFileLayer
+    return unittest.TestSuite((
+        unittest.makeSuite(FileTest),
+        unittest.makeSuite(ImageTest),
+        url,
+        file,
+        ))
+
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')



More information about the Checkins mailing list