[Zope3-checkins] CVS: Zope3/src/zope/app/browser/content/tests - __init__.py:1.1.2.1 test_dtmlpageeval.py:1.1.2.1 test_imagedata.py:1.1.2.1 test_imageupload.py:1.1.2.1 test_zptpageeval.py:1.1.2.1

Jim Fulton jim@zope.com
Mon, 23 Dec 2002 14:31:07 -0500


Update of /cvs-repository/Zope3/src/zope/app/browser/content/tests
In directory cvs.zope.org:/tmp/cvs-serv19908/zope/app/browser/content/tests

Added Files:
      Tag: NameGeddon-branch
	__init__.py test_dtmlpageeval.py test_imagedata.py 
	test_imageupload.py test_zptpageeval.py 
Log Message:
Initial renaming before debugging

=== Added File Zope3/src/zope/app/browser/content/tests/__init__.py ===
#
# This file is necessary to make this directory a package.


=== Added File Zope3/src/zope/app/browser/content/tests/test_dtmlpageeval.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: test_dtmlpageeval.py,v 1.1.2.1 2002/12/23 19:31:06 jim Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from zope.testing.cleanup import CleanUp # Base class w registry cleanup

from zope.app.browser.content.dtmlpageeval import \
     DTMLPageEval
from zope.proxy.context.context import ContextWrapper


class Test(CleanUp, TestCase):

    def test(self):

        class Template:
            def render(self, request, **kw):
                self.called = request, kw
                request.response.setHeader('content-type', self.content_type)
                return 42

            content_type = 'text/x-test'

        class Folder: name='zope'
        folder = Folder()
        
        class Request(object):

            def _getResponse(self):
                return self

            response = property(_getResponse)
            
            def setHeader(self, name, value):
                setattr(self, name, value)
                           
        request = Request()

        template = ContextWrapper(Template(), folder)

        view = DTMLPageEval(template, None)
        self.assertEqual(view.index(request), 42)
        self.assertEqual(template.called, (request, {}))
        self.assertEqual(getattr(request, 'content-type'), 'text/x-test')

def test_suite():
    return makeSuite(Test)

if __name__=='__main__':
    main(defaultTest='test_suite')


=== Added File Zope3/src/zope/app/browser/content/tests/test_imagedata.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: test_imagedata.py,v 1.1.2.1 2002/12/23 19:31:06 jim Exp $
"""

import unittest

from zope.app.browser.content.image import ImageData
from zope.app.content.image import Image


class Test( unittest.TestCase ):

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

        id = ImageData(image, None) 

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


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

        # We need that, sinc eabsolute_url is not implemented yet.
        def absolute_url():
            return '/img'
            
        image = Image()        
        fe = ImageData(image, None)
        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/src/zope/app/browser/content/tests/test_imageupload.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.
#
##############################################################################
"""XXX short summary goes here.

XXX longer description goes here.

$Id: test_imageupload.py,v 1.1.2.1 2002/12/23 19:31:06 jim Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
import os
from zope.publisher.browser import TestRequest
import Zope.App.OFS.Content.Image
from zope.app.content.image import Image, IImage
from zope.app.browser.content.image import ImageUpload
from zope.app.browser.form.editview import EditView
from zope.app.tests.placelesssetup import PlacelessSetup
from zope.component.view \
     import provideView, setDefaultViewName
from zope.app.browser.form.widget import BytesWidget, BytesAreaWidget
from zope.schema.interfaces import IField, IBytesLine, IBytes
from zope.publisher.interfaces.browser import IBrowserPresentation

class IU(ImageUpload, EditView):
    schema = IImage


class Test(PlacelessSetup, TestCase):

    def setUp(self):
        PlacelessSetup.setUp(self)

        # Configure the widget views
        setDefaultViewName(IField, IBrowserPresentation, 'edit')
        provideView(IBytesLine, 'edit', IBrowserPresentation, BytesWidget)
        provideView(IBytes, 'edit', IBrowserPresentation, BytesAreaWidget)

        icondir = os.path.split(Zope.App.OFS.Content.Image.__file__)[0]
        data = open(os.path.join(icondir, 'Image_icon.gif'), 'rb').read()
        image = Image(data)
        self.__view = IU(image, TestRequest())

    def test_size(self):
        self.assertEqual(self.__view.size(), "16 x 16 pixels")

    def test_apply_update_no_data(self):
        view = self.__view
        ct = view.context.contentType
        data = view.context.data
        d = {}
        self.failUnless(view.apply_update(d))
        self.assertEqual(view.context.contentType, ct)
        self.assertEqual(view.context.data, data)
        d = {'contentType': 'image/gif'}
        self.failUnless(view.apply_update(d))
        self.assertEqual(view.context.contentType, ct)
        self.assertEqual(view.context.data, data)

    def test_apply_update_new_contentType(self):
        view = self.__view
        view.context.contentType = 'foo/bar'
        self.assertEqual(view.context.contentType, 'foo/bar')
        data = view.context.data
        d = {'contentType': 'xxx/yyy'}
        self.failIf(view.apply_update(d))
        self.assertEqual(view.context.contentType, 'xxx/yyy')
        self.assertEqual(view.context.data, data)

    def test_apply_update_new_data(self):
        view = self.__view
        gifdata = view.context.data
        view.context.contentType = 'foo/bar'
        view.context.data = ''
        ct = view.context.contentType
        self.assertEqual(ct, 'foo/bar')
        data = view.context.data
        self.assertEqual(data, '')
        d = {'data': gifdata}
        self.failIf(view.apply_update(d))
        self.assertEqual(view.context.contentType, 'image/gif')
        self.assertEqual(view.context.data, gifdata)

    def test_apply_update_new_data_and_new_ct(self):
        view = self.__view
        gifdata = view.context.data
        view.context.contentType = 'foo/bar'
        view.context.data = ''
        ct = view.context.contentType
        self.assertEqual(ct, 'foo/bar')
        data = view.context.data
        self.assertEqual(data, '')
        d = {'contentType': 'xxx/yyy', 'data': gifdata}
        self.failIf(view.apply_update(d))
        self.assertEqual(view.context.contentType, 'image/gif')
        self.assertEqual(view.context.data, gifdata)
        
    

def test_suite():
    return TestSuite((
        makeSuite(Test),
        ))

if __name__=='__main__':
    main(defaultTest='test_suite')


=== Added File Zope3/src/zope/app/browser/content/tests/test_zptpageeval.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
# 
##############################################################################
"""

Revision information:
$Id: test_zptpageeval.py,v 1.1.2.1 2002/12/23 19:31:06 jim Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from zope.testing.cleanup import CleanUp # Base class w registry cleanup

from zope.app.browser.content.zpt import ZPTPageEval
from zope.proxy.context.context import ContextWrapper


class Test(CleanUp, TestCase):

    def testTemplateRendering(self):

        class Template:
            def render(self, request, **kw):
                self.called = request, kw
                return 42

            content_type = 'text/x-test'

        class Folder: name='zope'
        folder = Folder()
        
        class Request(object):
            def _getResponse(self):
                return self

            response = property(_getResponse)
            
            def setHeader(self, name, value):
                setattr(self, name, value)
                           
        request = Request()

        template = ContextWrapper(Template(), folder)

        view = ZPTPageEval(template, None)
        self.assertEqual(view.index(request), 42)
        self.assertEqual(template.called, (request, {}))
        self.assertEqual(getattr(request, 'content-type'), 'text/x-test')

def test_suite():
    return makeSuite(Test)

if __name__=='__main__':
    main(defaultTest='test_suite')