[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/File/tests - testFile.py:1.1.2.1 testFileEdit.py:1.1.2.1 testNaiveFile.py:1.1.2.2 testNaiveFileEdit.py:NONE
Stephan Richter
srichter@cbu.edu
Mon, 21 Jan 2002 12:42:07 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/File/tests
In directory cvs.zope.org:/tmp/cvs-serv22486/File/tests
Modified Files:
Tag: Zope-3x-branch
testNaiveFile.py
Added Files:
Tag: Zope-3x-branch
testFile.py testFileEdit.py
Removed Files:
Tag: Zope-3x-branch
testNaiveFileEdit.py
Log Message:
NaiveFile and File:
- I fixed the Interface to also return the size of the file
- Implemented a real file that saves data chunks a la Zope 2
- Cleaned up the API, so that both NaiveFile and File can use the same
views, which I think is what Zope 3 is all about.
- TODO: Support File upload from the Web.
Image:
- Cleaned up API and methods
- renamed Interface method getSize() to getImageSize()
- Image now inherits File instead of NaiveFile
=== Added File Zope3/lib/python/Zope/App/OFS/File/tests/testFile.py ===
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 1.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.
import unittest, ZODB
from Interface import verify
from Zope.App.OFS.File.FileChunk import FileChunk
class Test( unittest.TestCase ):
def _makeFile(self, *args, **kw):
""" """
from Zope.App.OFS.File.File import File
return File(*args, **kw)
def testEmpty(self):
file = self._makeFile()
self.assertEqual(file.getContentType(), '')
self.assertEqual(file.getData(), None)
def testConstructor(self):
file = self._makeFile('Foobar')
self.assertEqual(file.getContentType(), '')
self.assertEqual(file.getData(), 'Foobar')
file = self._makeFile('Foobar', 'text/plain')
self.assertEqual(file.getContentType(), 'text/plain')
self.assertEqual(file.getData(), 'Foobar')
file = self._makeFile(data='Foobar', contentType='text/plain')
self.assertEqual(file.getContentType(), 'text/plain')
self.assertEqual(file.getData(), 'Foobar')
def testMutators(self):
file = self._makeFile()
file.setContentType('text/plain')
self.assertEqual(file.getContentType(), 'text/plain')
file.setData('Foobar')
self.assertEqual(file.getData(), 'Foobar')
file.edit('Blah', 'text/html')
self.assertEqual(file.getContentType(), 'text/html')
self.assertEqual(file.getData(), 'Blah')
def testLargeDataInput(self):
file = self._makeFile()
# Insert as string
file.setData('Foobar'*60000)
self.assertEqual(file.getSize(), 6*60000)
self.assertEqual(file.getData(), 'Foobar'*60000)
# Insert data as FileChunk
fc = FileChunk('Foobar'*4000)
file.setData(fc)
self.assertEqual(file.getSize(), 6*4000)
self.assertEqual(file.getData(), 'Foobar'*4000)
# Insert data from file object
import cStringIO
sio = cStringIO.StringIO()
sio.write('Foobar'*100000)
sio.seek(0)
file.setData(sio)
self.assertEqual(file.getSize(), 6*100000)
self.assertEqual(file.getData(), 'Foobar'*100000)
def testInterface(self):
from Zope.App.OFS.File.File import File, IFile
self.failUnless(IFile.isImplementedByInstancesOf(File))
self.failUnless(verify(IFile, File))
def test_suite():
loader = unittest.TestLoader()
return loader.loadTestsFromTestCase( Test )
if __name__=='__main__':
unittest.TextTestRunner().run( test_suite() )
=== Added File Zope3/lib/python/Zope/App/OFS/File/tests/testFileEdit.py ===
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 1.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.
import unittest
from Zope.App.OFS.File.FileEdit import FileEdit
from Zope.App.OFS.File.NaiveFile import NaiveFile
class Test( unittest.TestCase ):
def testEdit(self):
""" """
file = NaiveFile()
fe = FileEdit(file)
fe.edit('Data', 'text/plain')
self.assertEqual(fe.getContext().getContentType(), 'text/plain')
self.assertEqual(fe.getContext().getData(), 'Data')
def test_suite():
loader = unittest.TestLoader()
return loader.loadTestsFromTestCase( Test )
if __name__=='__main__':
unittest.main()
=== Zope3/lib/python/Zope/App/OFS/File/tests/testNaiveFile.py 1.1.2.1 => 1.1.2.2 ===
def testInterface(self):
- from Zope.App.OFS.File.NaiveFile import NaiveFile, INaiveFile
+ from Zope.App.OFS.File.NaiveFile import NaiveFile
+ from Zope.App.OFS.File.IFile import IFile
- self.failUnless(INaiveFile.isImplementedByInstancesOf(NaiveFile))
- self.failUnless(verify(INaiveFile, NaiveFile))
+ self.failUnless(IFile.isImplementedByInstancesOf(NaiveFile))
+ self.failUnless(verify(IFile, NaiveFile))
=== Removed File Zope3/lib/python/Zope/App/OFS/File/tests/testNaiveFileEdit.py ===