[Zope3-checkins] CVS: Zope3/src/zope/app/form/browser/ftests - test_objectwidget.py:1.1

Garrett Smith garrett at mojave-corp.com
Fri May 7 15:41:33 EDT 2004


Update of /cvs-repository/Zope3/src/zope/app/form/browser/ftests
In directory cvs.zope.org:/tmp/cvs-serv31620/src/zope/app/form/browser/ftests

Added Files:
	test_objectwidget.py 
Log Message:
Created a page template to render the object widget since widget row
method is no longer available for use.


=== Added File Zope3/src/zope/app/form/browser/ftests/test_objectwidget.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_objectwidget.py,v 1.1 2004/05/07 19:41:32 garrett Exp $
"""

import unittest, doctest

from zope.interface import Interface, implements
from zope.publisher.browser import TestRequest
from zope.schema import Object, TextLine
from zope.app.form.browser import ObjectWidget
from zope.app.tests.functional import BrowserTestCase
from zope.app.form.browser.tests import support


class ITestContact(Interface):
    name = TextLine()
    email = TextLine()
    
class TestContact:
    implements(ITestContact)

class Test(BrowserTestCase, support.VerifyResults):
    
    def setUp(self):
        BrowserTestCase.setUp(self)
        self.field = Object(ITestContact, __name__=u'foo')

    def test_new(self):
        request = TestRequest()
        widget = ObjectWidget(self.field, request, TestContact)
        self.assertEquals(int(widget.hasInput()), 0)
        check_list = (
            'input', 'name="field.foo.name"',
            'input', 'name="field.foo.email"'
        )
        self.verifyResult(widget(), check_list)

    def test_edit(self):
        request = TestRequest(form={
            'field.foo.name': u'fred',
            'field.foo.email': u'fred at fred.com'
            })
        widget = ObjectWidget(self.field, request, TestContact)
        self.assertEquals(int(widget.hasInput()), 1)
        o = widget.getInputValue()
        self.assertEquals(hasattr(o, 'name'), 1)
        self.assertEquals(o.name, u'fred')
        self.assertEquals(o.email, u'fred at fred.com')
        check_list = (
            'input', 'name="field.foo.name"', 'value="fred"',
            'input', 'name="field.foo.email"', 'value="fred at fred.com"',
        )
        self.verifyResult(widget(), check_list)

def test_suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(Test))
    return suite

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







More information about the Zope3-Checkins mailing list