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

Stephan Richter srichter@cbu.edu
Wed, 27 Mar 2002 10:54:39 -0500


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

Added Files:
      Tag: Zope-3x-branch
	__init__.py testFile.py testFileEdit.py testNaiveFile.py 
Log Message:
New Content Objects:

- NaiveFile --> all the data is stored in one string
- File --> Uses a BTree to store the data in chunks (more efficient)
- Image --> Can store and display an image a la Z2 (based on File)
- ZPTPage --> A simple version of ZPT for the content space to allow some 
  dynamics data (please do not use this for scripting)

Also:

- Expansion of supported views
- all edit screens are Formulator supported



=== Added File Zope3/lib/python/Zope/App/OFS/Content/File/tests/__init__.py ===
##############################################################################
#
# 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: __init__.py,v 1.1.2.1 2002/03/27 15:54:37 srichter Exp $
"""


=== Added File Zope3/lib/python/Zope/App/OFS/Content/File/tests/testFile.py ===
##############################################################################
#
# 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: testFile.py,v 1.1.2.1 2002/03/27 15:54:37 srichter Exp $
"""

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(), 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.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() )


=== Added File Zope3/lib/python/Zope/App/OFS/Content/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.Content.File.FileEdit import FileEdit
from Zope.App.OFS.Content.File.NaiveFile import NaiveFile


class Test( unittest.TestCase ):

    def testEdit(self):
        """ """
        file = NaiveFile()

        fe = FileEdit(file) 

        fe.getContext().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()


=== Added File Zope3/lib/python/Zope/App/OFS/Content/File/tests/testNaiveFile.py ===
##############################################################################
#
# 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: testNaiveFile.py,v 1.1.2.1 2002/03/27 15:54:37 srichter Exp $
"""

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(), 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.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() )