[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Content/File/tests - __init__.py:1.2 testFile.py:1.2 testNaiveFile.py:1.2

Jim Fulton jim@zope.com
Mon, 10 Jun 2002 19:28:30 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Content/File/tests
In directory cvs.zope.org:/tmp/cvs-serv17445/lib/python/Zope/App/OFS/Content/File/tests

Added Files:
	__init__.py testFile.py testNaiveFile.py 
Log Message:
Merged Zope-3x-branch into newly forked Zope3 CVS Tree.


=== Zope3/lib/python/Zope/App/OFS/Content/File/tests/__init__.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+# 
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (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.
+# 
+##############################################################################
+"""
+
+$Id$
+"""


=== Zope3/lib/python/Zope/App/OFS/Content/File/tests/testFile.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+# 
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (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.
+# 
+##############################################################################
+"""
+
+$Id$
+"""
+
+import unittest, ZODB
+from Interface.Verify import verifyClass
+from Zope.App.OFS.Content.File.FileChunk import FileChunk
+
+class Test( unittest.TestCase ):
+
+
+    def _makeFile(self, *args, **kw):
+        """ """
+        from Zope.App.OFS.Content.File.File import File
+
+        return File(*args, **kw)
+        
+
+    def testEmpty(self):
+
+        file = self._makeFile()
+
+        self.assertEqual(file.getContentType(), '')
+        self.assertEqual(file.getData(), '')
+
+
+    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.Content.File.File import File, IFile
+
+        self.failUnless(IFile.isImplementedByInstancesOf(File))
+        self.failUnless(verifyClass(IFile, File))        
+        
+
+
+def test_suite():
+    loader = unittest.TestLoader()
+    return loader.loadTestsFromTestCase( Test )
+
+if __name__=='__main__':
+    unittest.TextTestRunner().run( test_suite() )


=== Zope3/lib/python/Zope/App/OFS/Content/File/tests/testNaiveFile.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+# 
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (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.
+# 
+##############################################################################
+"""
+
+$Id$
+"""
+
+import unittest
+from Interface.Verify import verifyClass
+
+class Test( unittest.TestCase ):
+
+
+    def _makeNaiveFile(self, *args, **kw):
+        """ """
+        from Zope.App.OFS.Content.File.NaiveFile import NaiveFile
+
+        return NaiveFile(*args, **kw)
+        
+
+    def testEmpty( self ):
+
+        file = self._makeNaiveFile()
+
+        self.assertEqual(file.getContentType(), '')
+        self.assertEqual(file.getData(), '')
+
+
+    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.Content.File.NaiveFile import NaiveFile
+        from Zope.App.OFS.Content.File.IFile import IFile
+
+        self.failUnless(IFile.isImplementedByInstancesOf(NaiveFile))
+        self.failUnless(verifyClass(IFile, NaiveFile))        
+        
+
+
+def test_suite():
+    loader = unittest.TestLoader()
+    return loader.loadTestsFromTestCase( Test )
+
+if __name__=='__main__':
+    unittest.TextTestRunner().run( test_suite() )