[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Image/tests - __init__.py:1.1.2.1 testImage.py:1.1.2.1 testImageData.py:1.1.2.1 testImageEdit.py:1.1.2.1

Stephan Richter srichter@cbu.edu
Sat, 19 Jan 2002 23:57:33 -0500


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

Added Files:
      Tag: Zope-3x-branch
	__init__.py testImage.py testImageData.py testImageEdit.py 
Log Message:
- Restructuring the directory structure in Zope.App.OFS
- Added a simple Image support including two views

NOTE: The ImageData.tag() method does not work yet, since absolute_url is 
      not implemented yet.


=== Added File Zope3/lib/python/Zope/App/OFS/Image/tests/__init__.py ===


=== Added File Zope3/lib/python/Zope/App/OFS/Image/tests/testImage.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 _makeImage(self, *args, **kw):
        """ """
        from Zope.App.OFS.Image.Image import Image

        return Image(*args, **kw)
        

    def testEmpty( self ):

        file = self._makeImage()

        self.assertEqual(file.getContentType(), '')
        self.assertEqual(file.getData(), None)


    def testConstructor(self):

        file = self._makeImage('Data')
        self.assertEqual(file.getContentType(), '')
        self.assertEqual(file.getData(), 'Data')
    


    def testMutators(self):

        file = self._makeImage()
        
        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/plain')
        self.assertEqual(file.getData(), 'Blah')


    def testInterface(self):
        
        from Zope.App.OFS.Image.Image import Image, IImage

        self.failUnless(IImage.isImplementedByInstancesOf(Image))
        self.failUnless(verify(IImage, Image))        
        


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/Image/tests/testImageData.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.Image.ImageData import ImageData
from Zope.App.OFS.Image.Image import Image


class Test( unittest.TestCase ):

    def testData(self):
        """ """
        image = Image('Data')

        id = ImageData(image) 

        self.assertEqual(id.index(), 'Data')


    def testTag(self):
        """ """

        # We need that, sinc eabsolute_url is not implemented yet.
        def absolute_url():
            return '/img'
            
        image = Image()        
        fe = ImageData(image)
        fe.absolute_url = absolute_url

        self.assertEqual(fe.tag(),
            '<img src="/img" alt="" height="-1" width="-1" border="0" />')
        self.assertEqual(fe.tag(alt="Test Image"),
            '<img src="/img" alt="Test Image" height="-1" width="-1" border="0" />')
        self.assertEqual(fe.tag(height=100, width=100),
            '<img src="/img" alt="" height="100" width="100" border="0" />')
        self.assertEqual(fe.tag(border=1),
            '<img src="/img" alt="" height="-1" width="-1" border="1" />')
        self.assertEqual(fe.tag(css_class="Image"),
            '<img src="/img" alt="" height="-1" width="-1" border="0" class="Image" />')
        self.assertEqual(fe.tag(height=100, width="100", border=1, css_class="Image"),
            '<img src="/img" alt="" height="100" width="100" class="Image" border="1" />')


def test_suite():
    loader = unittest.TestLoader()
    return loader.loadTestsFromTestCase( Test )

if __name__=='__main__':
    unittest.main()


=== Added File Zope3/lib/python/Zope/App/OFS/Image/tests/testImageEdit.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, cStringIO

from Zope.App.OFS.Image.ImageEdit import ImageEdit
from Zope.App.OFS.Image.Image import Image


class Test( unittest.TestCase ):

    def testEdit(self):
        """ """
        file = Image()
        fe = ImageEdit(file) 

        file = cStringIO.StringIO()
        file.write('Data')
        file.seek(0)

        fe.editAction(file, '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()