[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/tests - testNaiveFile.py:1.1.2.1 testNaiveFileEdit.py:1.1.2.1
Stephan Richter
srichter@cbu.edu
Sat, 19 Jan 2002 15:05:21 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/tests
In directory cvs.zope.org:/tmp/cvs-serv7462/tests
Added Files:
Tag: Zope-3x-branch
testNaiveFile.py testNaiveFileEdit.py
Log Message:
- Added Support for simple File saved in the ZODB
- Provided a Web-based view
Note: You should not use this object to save large pieces of data.
=== Added File Zope3/lib/python/Zope/App/OFS/tests/testNaiveFile.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 Interface import verify
class Test( unittest.TestCase ):
def _makeNaiveFile(self, *args, **kw):
""" """
from Zope.App.OFS.NaiveFile import NaiveFile
return NaiveFile(*args, **kw)
def testEmpty( self ):
file = self._makeNaiveFile()
self.assertEqual(file.getContentType(), '')
self.assertEqual(file.getData(), None)
def testConstructor(self):
file = self._makeNaiveFile('Foobar')
self.assertEqual(file.getContentType(), '')
self.assertEqual(file.getData(), 'Foobar')
file = self._makeNaiveFile('Foobar', 'text/plain')
self.assertEqual(file.getContentType(), 'text/plain')
self.assertEqual(file.getData(), 'Foobar')
file = self._makeNaiveFile(data='Foobar', contentType='text/plain')
self.assertEqual(file.getContentType(), 'text/plain')
self.assertEqual(file.getData(), 'Foobar')
def testMutators(self):
file = self._makeNaiveFile()
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 testInterface(self):
from Zope.App.OFS.NaiveFile import NaiveFile, INaiveFile
self.failUnless(INaiveFile.isImplementedByInstancesOf(NaiveFile))
self.failUnless(verify(INaiveFile, NaiveFile))
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/tests/testNaiveFileEdit.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.NaiveFileEdit import NaiveFileEdit
from Zope.App.OFS.NaiveFile import NaiveFile
class Test( unittest.TestCase ):
def testEdit(self):
""" """
file = NaiveFile()
fe = NaiveFileEdit(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()