[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Forms/Views/Browser/tests - SchemaTestObject.py:1.1 WidgetTest.py:1.1 testBrowserWidget.py:1.1 testCheckBoxWidget.py:1.1 testFileWidget.py:1.1 testListWidget.py:1.1 testMultiCheckboxWidget.py:1.1 testMultiListWidget.py:1.1 testPasswordWidget.py:1.1 testRadioWidget.py:1.1 testTextAreaWidget.py:1.1 testTextWidget.py:1.1
Stephan Richter
srichter@cbu.edu
Tue, 16 Jul 2002 11:15:55 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/Forms/Views/Browser/tests
In directory cvs.zope.org:/tmp/cvs-serv20976/lib/python/Zope/App/Forms/Views/Browser/tests
Added Files:
SchemaTestObject.py WidgetTest.py testBrowserWidget.py
testCheckBoxWidget.py testFileWidget.py testListWidget.py
testMultiCheckboxWidget.py testMultiListWidget.py
testPasswordWidget.py testRadioWidget.py testTextAreaWidget.py
testTextWidget.py
Log Message:
:) I forgot to add the new files...
=== Added File Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/SchemaTestObject.py ===
##############################################################################
#
# Copyright (c) 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: SchemaTestObject.py,v 1.1 2002/07/16 15:15:55 srichter Exp $
"""
import Schema
from Zope.App.Forms.Views.Browser import Widget
class Email(Schema.String):
pass
class STestObject(Schema):
id = Schema.String(
id="id",
title="Id",
required=1)
title = Schema.String(
id="title",
title="Title",
required=0)
data = Schema.String(
id="data",
title="Data",
description="Data stored by the object",
required=0)
creator = Email(
id="creator",
title="Creator",
description="Email of the creator of the content object",
default="foo@bar.com",
required=1)
class TestObject:
__schema__ = Schema
id = None
title = "Test Object"
data = ''
creator = ''
class Edit(FormView):
schema = STestObject
custom_widgets = {'creator': Widget.TextWidget(displaywidth=30),
'data': Widget.FileWidget()}
=== Added File Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/WidgetTest.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: WidgetTest.py,v 1.1 2002/07/16 15:15:55 srichter Exp $
"""
import unittest
from Zope.App.Forms.Views.Browser.Widget import BrowserWidget
class ContentObject:
"""Class to provide a stub for a field"""
foo = "Foo Value"
class Field:
"""Field Stub """
id = 'foo'
def __init__(self, context):
self._context = context
def getPropertyInContext(self):
return self._context.getFoo()
def getValue(self, name):
return getattr(self, name, None)
class WidgetTest(unittest.TestCase):
def _getWidget(self, field):
return BrowserWidget(field)
def setUp(self):
obj = ContentObject()
field = Field(obj)
self._widget = self._getWidget(field)
def testProperties(self):
self.assertEqual(self._widget.getValue('tag'), 'input')
self.assertEqual(self._widget.getValue('type'), 'text')
self.assertEqual(self._widget.getValue('cssClass'), '')
self.assertEqual(self._widget.getValue('hidden'), 0)
self.assertEqual(self._widget.getValue('extra'), '')
def testRendering(self):
request = {'field_foo': 'Foo Value'}
result1 = '<input type="text" name="field_foo" value="Foo Value" />'
self.assertEqual(result1, self._widget.render(request))
result2 = '<input type="hidden" name="field_foo" value="Foo Value" />'
self.assertEqual(result2, self._widget.render_hidden(request))
self._widget.extra = '''style="color: red"'''
result3 = ('<input type="hidden" name="field_foo" '
'value="Foo Value" style="color: red" />')
self.assertEqual(result3, self._widget.render_hidden(request))
def test_suite():
return TestSuite((
makeSuite(TextWidgetTest),
))
if __name__=='__main__':
main(defaultTest='test_suite')
=== Added File Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testBrowserWidget.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: testBrowserWidget.py,v 1.1 2002/07/16 15:15:55 srichter Exp $
"""
import unittest
from Zope.App.Forms.Views.Browser.Widget import BrowserWidget
class Field:
"""Field Stub """
id = 'foo'
class BrowserWidgetTest(unittest.TestCase):
def setUp(self):
field = Field()
request = {'field_foo': 'Foo Value'}
self._widget = BrowserWidget(field, request)
def _verifyResult(self, result, check_list):
for check in check_list:
self.assertNotEqual(-1, result.find(check),
'"'+check+'" not found in "'+result+'"')
def testProperties(self):
self.assertEqual(self._widget.getValue('tag'), 'input')
self.assertEqual(self._widget.getValue('type'), 'text')
self.assertEqual(self._widget.getValue('cssClass'), '')
self.assertEqual(self._widget.getValue('hidden'), 0)
self.assertEqual(self._widget.getValue('extra'), '')
def testRender(self):
value = 'Foo Value'
check_list = ('type="text"', 'name="field_foo"', 'value="Foo Value"')
self._verifyResult(self._widget.render(value), check_list)
check_list = ('type="hidden"',) + check_list[1:]
self._verifyResult(self._widget.renderHidden(value), check_list)
check_list = ('type="hidden"', 'style="color: red"') + check_list[1:]
self._widget.extra = 'style="color: red"'
self._verifyResult(self._widget.renderHidden(value), check_list)
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(BrowserWidgetTest),
))
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
=== Added File Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testCheckBoxWidget.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: testCheckBoxWidget.py,v 1.1 2002/07/16 15:15:55 srichter Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from Zope.App.Forms.Views.Browser.Widget import CheckBoxWidget
from testBrowserWidget import BrowserWidgetTest, Field
class CheckBoxWidgetTest(BrowserWidgetTest):
def setUp(self):
field = Field()
request = {'field_foo': 'Foo Value'}
self._widget = CheckBoxWidget(field, request)
def testProperties(self):
self.assertEqual(self._widget.getValue('tag'), 'input')
self.assertEqual(self._widget.getValue('type'), 'checkbox')
self.assertEqual(self._widget.getValue('cssClass'), '')
self.assertEqual(self._widget.getValue('hidden'), 0)
self.assertEqual(self._widget.getValue('extra'), '')
self.assertEqual(self._widget.getValue('default'), 0)
def testRender(self):
value = 1
check_list = ('type="checkbox"', 'name="field_foo"',
'checked="checked"')
self._verifyResult(self._widget.render(value), check_list)
value = 0
check_list = check_list[:-1]
self._verifyResult(self._widget.render(value), check_list)
check_list = ('type="hidden"',) + check_list[1:-1]
self._verifyResult(self._widget.renderHidden(value), check_list)
check_list = ('style="color: red"',) + check_list
self._widget.extra = 'style="color: red"'
self._verifyResult(self._widget.renderHidden(value), check_list)
def test_suite():
return TestSuite((
makeSuite(CheckBoxWidgetTest),
))
if __name__=='__main__':
main(defaultTest='test_suite')
=== Added File Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testFileWidget.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: testFileWidget.py,v 1.1 2002/07/16 15:15:55 srichter Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from Zope.App.Forms.Views.Browser.Widget import FileWidget
from testBrowserWidget import BrowserWidgetTest, Field
class FileWidgetTest(BrowserWidgetTest):
def setUp(self):
field = Field()
request = {'field_foo': 'Foo Value'}
self._widget = FileWidget(field, request)
def testProperties(self):
self.assertEqual(self._widget.getValue('tag'), 'input')
self.assertEqual(self._widget.getValue('type'), 'file')
self.assertEqual(self._widget.getValue('cssClass'), '')
self.assertEqual(self._widget.getValue('hidden'), 0)
self.assertEqual(self._widget.getValue('extra'), '')
self.assertEqual(self._widget.getValue('default'), '')
self.assertEqual(self._widget.getValue('displayWidth'), 20)
self.assertEqual(self._widget.getValue('displayMaxWidth'), '')
def testRender(self):
value = 'Foo Value'
check_list = ('type="file"', 'name="field_foo"', 'size="20"')
self._verifyResult(self._widget.render(value), check_list)
check_list = ('type="hidden"',) + check_list[1:-1]
self._verifyResult(self._widget.renderHidden(value), check_list)
check_list = ('style="color: red"',) + check_list
self._widget.extra = 'style="color: red"'
self._verifyResult(self._widget.renderHidden(value), check_list)
def test_suite():
return TestSuite((
makeSuite(FileWidgetTest),
))
if __name__=='__main__':
main(defaultTest='test_suite')
=== Added File Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testListWidget.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: testListWidget.py,v 1.1 2002/07/16 15:15:55 srichter Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from Zope.App.Forms.Views.Browser.Widget import ListWidget
from testBrowserWidget import BrowserWidgetTest
class Field:
"""Field Stub """
id = 'foo'
items = [('Foo', 'foo'), ('Bar', 'bar')]
def get(self, name):
return getattr(self, name)
class ListWidgetTest(BrowserWidgetTest):
def setUp(self):
field = Field()
request = {'field_foo': 'Foo Value'}
self._widget = ListWidget(field, request)
def testProperties(self):
self.assertEqual(self._widget.getValue('cssClass'), "")
self.assertEqual(self._widget.getValue('hidden'), 0)
self.assertEqual(self._widget.getValue('extra'), '')
self.assertEqual(self._widget.getValue('items'), [])
self.assertEqual(self._widget.getValue('firstItem'), 0)
self.assertEqual(self._widget.getValue('size'), 5)
def testRenderItem(self):
check_list = ('option', 'value="foo"', 'Foo')
self._verifyResult(self._widget.renderItem('Foo', 'foo', 'bar', None),
check_list)
check_list += ('selected="selected"',)
self._verifyResult(
self._widget.renderSelectedItem('Foo', 'foo', 'bar', None),
check_list)
def testRenderItems(self):
check_list = ('option', 'value="foo"', 'Bar',
'value="foo"', 'Foo', 'selected="selected"')
self._verifyResult('\n'.join(self._widget.renderItems('foo')),
check_list)
def testRender(self):
value = 'foo'
check_list = ('select', 'name="field_foo"', 'size="5"',
'option', 'value="foo"', '>Foo<',
'value="foo"', '>Bar<', 'selected="selected"')
self._verifyResult(self._widget.render(value), check_list)
check_list = ('type="hidden"', 'name="field_foo"', 'value="foo"')
self._verifyResult(self._widget.renderHidden(value), check_list)
check_list = ('style="color: red"',) + check_list
self._widget.extra = 'style="color: red"'
self._verifyResult(self._widget.renderHidden(value), check_list)
def test_suite():
return TestSuite((
makeSuite(ListWidgetTest),
))
if __name__=='__main__':
main(defaultTest='test_suite')
=== Added File Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testMultiCheckboxWidget.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: testMultiCheckboxWidget.py,v 1.1 2002/07/16 15:15:55 srichter Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from Zope.App.Forms.Views.Browser.Widget import MultiCheckBoxWidget
from testBrowserWidget import BrowserWidgetTest
class Field:
"""Field Stub """
id = 'foo'
items = [('Foo', 'foo1'), ('Bar', 'bar1')]
def get(self, name):
return getattr(self, name)
class MultiCheckBoxWidgetTest(BrowserWidgetTest):
def setUp(self):
field = Field()
request = {'field_foo': 'Foo Value'}
self._widget = MultiCheckBoxWidget(field, request)
def testProperties(self):
self.assertEqual(self._widget.getValue('cssClass'), "")
self.assertEqual(self._widget.getValue('hidden'), 0)
self.assertEqual(self._widget.getValue('extra'), '')
self.assertEqual(self._widget.getValue('items'), [])
self.assertEqual(self._widget.getValue('orientation'), 'vertical')
def testRenderItem(self):
check_list = ('type="checkbox"', 'name="field_bar"', 'value="foo"',
'Foo')
self._verifyResult(self._widget.renderItem('Foo', 'foo', 'bar', None),
check_list)
check_list += ('checked="checked"',)
self._verifyResult(
self._widget.renderSelectedItem('Foo', 'foo', 'bar', None),
check_list)
def testRenderItems(self):
check_list = ('type="checkbox"', 'name="field_foo"', 'value="bar1"',
'Bar', 'value="foo1"', 'Foo', 'checked="checked"')
self._verifyResult('\n'.join(self._widget.renderItems('bar1')),
check_list)
def testRender(self):
value = 'bar1'
check_list = ('type="checkbox"', 'name="field_foo"', 'value="bar1"',
'Bar', 'value="foo1"', 'Foo', 'checked="checked"')
self._verifyResult(self._widget.render(value), check_list)
check_list = ('type="hidden"', 'name="field_foo"', 'value="bar1"')
self._verifyResult(self._widget.renderHidden(value), check_list)
check_list = ('style="color: red"',) + check_list
self._widget.extra = 'style="color: red"'
self._verifyResult(self._widget.renderHidden(value), check_list)
def test_suite():
return TestSuite((
makeSuite(MultiCheckBoxWidgetTest),
))
if __name__=='__main__':
main(defaultTest='test_suite')
=== Added File Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testMultiListWidget.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: testMultiListWidget.py,v 1.1 2002/07/16 15:15:55 srichter Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from Zope.App.Forms.Views.Browser.Widget import MultiListWidget
from testBrowserWidget import BrowserWidgetTest
class Field:
"""Field Stub """
id = 'foo'
items = [('Foo', 'foo'), ('Bar', 'bar')]
def get(self, name):
return getattr(self, name)
class MultiListWidgetTest(BrowserWidgetTest):
def setUp(self):
field = Field()
request = {'field_foo': 'Foo Value'}
self._widget = MultiListWidget(field, request)
def testProperties(self):
self.assertEqual(self._widget.getValue('cssClass'), "")
self.assertEqual(self._widget.getValue('hidden'), 0)
self.assertEqual(self._widget.getValue('extra'), '')
self.assertEqual(self._widget.getValue('items'), [])
self.assertEqual(self._widget.getValue('size'), 5)
def testRenderItem(self):
check_list = ('option', 'value="foo"', 'Foo')
self._verifyResult(self._widget.renderItem('Foo', 'foo', 'bar', None),
check_list)
check_list += ('selected="selected"',)
self._verifyResult(
self._widget.renderSelectedItem('Foo', 'foo', 'bar', None),
check_list)
def testRenderItems(self):
check_list = ('option', 'value="foo"', 'Bar',
'value="foo"', 'Foo', 'selected="selected"')
self._verifyResult('\n'.join(self._widget.renderItems('foo')),
check_list)
def testRender(self):
value = 'foo'
check_list = ('select', 'name="field_foo"', 'size="5"',
'option', 'value="foo"', '>Foo<',
'value="foo"', '>Bar<', 'selected="selected"',
'multiple="multiple"')
self._verifyResult(self._widget.render(value), check_list)
check_list = ('type="hidden"', 'name="field_foo"', 'value="foo"')
self._verifyResult(self._widget.renderHidden(value), check_list)
check_list = ('style="color: red"',) + check_list
self._widget.extra = 'style="color: red"'
self._verifyResult(self._widget.renderHidden(value), check_list)
def test_suite():
return TestSuite((
makeSuite(MultiListWidgetTest),
))
if __name__=='__main__':
main(defaultTest='test_suite')
=== Added File Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testPasswordWidget.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: testPasswordWidget.py,v 1.1 2002/07/16 15:15:55 srichter Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from Zope.App.Forms.Views.Browser.Widget import PasswordWidget
from testBrowserWidget import BrowserWidgetTest, Field
class PasswordWidgetTest(BrowserWidgetTest):
def setUp(self):
field = Field()
request = {'field_foo': 'Foo Value'}
self._widget = PasswordWidget(field, request)
def testProperties(self):
self.assertEqual(self._widget.getValue('tag'), 'input')
self.assertEqual(self._widget.getValue('type'), 'password')
self.assertEqual(self._widget.getValue('cssClass'), '')
self.assertEqual(self._widget.getValue('hidden'), 0)
self.assertEqual(self._widget.getValue('extra'), '')
self.assertEqual(self._widget.getValue('default'), '')
self.assertEqual(self._widget.getValue('displayWidth'), 20)
self.assertEqual(self._widget.getValue('displayMaxWidth'), '')
def testRender(self):
value = 'Foo Value'
check_list = ('type="password"', 'name="field_foo"',
'value="Foo Value"', 'size="20"')
self._verifyResult(self._widget.render(value), check_list)
check_list = ('type="hidden"',) + check_list[1:-1]
self._verifyResult(self._widget.renderHidden(value), check_list)
check_list = ('style="color: red"',) + check_list
self._widget.extra = 'style="color: red"'
self._verifyResult(self._widget.renderHidden(value), check_list)
def test_suite():
return TestSuite((
makeSuite(PasswordWidgetTest),
))
if __name__=='__main__':
main(defaultTest='test_suite')
=== Added File Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testRadioWidget.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: testRadioWidget.py,v 1.1 2002/07/16 15:15:55 srichter Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from Zope.App.Forms.Views.Browser.Widget import RadioWidget
from testBrowserWidget import BrowserWidgetTest
class Field:
"""Field Stub """
id = 'foo'
items = [('Foo', 'foo1'), ('Bar', 'bar1')]
def get(self, name):
return getattr(self, name)
class RadioWidgetTest(BrowserWidgetTest):
def setUp(self):
field = Field()
request = {'field_foo': 'Foo Value'}
self._widget = RadioWidget(field, request)
def testProperties(self):
self.assertEqual(self._widget.getValue('cssClass'), "")
self.assertEqual(self._widget.getValue('hidden'), 0)
self.assertEqual(self._widget.getValue('extra'), '')
self.assertEqual(self._widget.getValue('items'), [])
self.assertEqual(self._widget.getValue('firstItem'), 0)
self.assertEqual(self._widget.getValue('orientation'), 'vertical')
def testRenderItem(self):
check_list = ('type="radio"', 'name="field_bar"', 'value="foo"',
'Foo')
self._verifyResult(self._widget.renderItem('Foo', 'foo', 'bar', None),
check_list)
check_list += ('checked="checked"',)
self._verifyResult(
self._widget.renderSelectedItem('Foo', 'foo', 'bar', None),
check_list)
def testRenderItems(self):
check_list = ('type="radio"', 'name="field_foo"', 'value="bar1"',
'Bar', 'value="foo1"', 'Foo', 'checked="checked"')
self._verifyResult('\n'.join(self._widget.renderItems('bar1')),
check_list)
def testRender(self):
value = 'bar1'
check_list = ('type="radio"', 'name="field_foo"', 'value="bar1"',
'Bar', 'value="foo1"', 'Foo', 'checked="checked"')
self._verifyResult(self._widget.render(value), check_list)
check_list = ('type="hidden"', 'name="field_foo"', 'value="bar1"')
self._verifyResult(self._widget.renderHidden(value), check_list)
check_list = ('style="color: red"',) + check_list
self._widget.extra = 'style="color: red"'
self._verifyResult(self._widget.renderHidden(value), check_list)
def test_suite():
return TestSuite((
makeSuite(RadioWidgetTest),
))
if __name__=='__main__':
main(defaultTest='test_suite')
=== Added File Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testTextAreaWidget.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: testTextAreaWidget.py,v 1.1 2002/07/16 15:15:55 srichter Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from Zope.App.Forms.Views.Browser.Widget import TextAreaWidget
from testBrowserWidget import BrowserWidgetTest, Field
class TextAreaWidgetTest(BrowserWidgetTest):
def setUp(self):
field = Field()
request = {'field_foo': 'Foo Value'}
self._widget = TextAreaWidget(field, request)
def testProperties(self):
self.assertEqual(self._widget.getValue('tag'), 'input')
self.assertEqual(self._widget.getValue('type'), 'text')
self.assertEqual(self._widget.getValue('cssClass'), '')
self.assertEqual(self._widget.getValue('hidden'), 0)
self.assertEqual(self._widget.getValue('extra'), '')
# self.assertEqual(self._widget.getValue('default'), "")
self.assertEqual(self._widget.getValue('width'), 80)
self.assertEqual(self._widget.getValue('height'), 15)
def testRender(self):
value = "Foo Value"
check_list = ('rows="15"', 'cols="80"', 'name="field_foo"', 'textarea')
self._verifyResult(self._widget.render(value), check_list)
check_list = ('style="color: red"',) + check_list
self._widget.extra = 'style="color: red"'
self._verifyResult(self._widget.render(value), check_list)
check_list = ('type="hidden"', 'name="field_foo"', 'value="Foo Value"')
self._verifyResult(self._widget.renderHidden(value), check_list)
def test_suite():
return TestSuite((
makeSuite(TextAreaWidgetTest),
))
if __name__=='__main__':
main(defaultTest='test_suite')
=== Added File Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testTextWidget.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: testTextWidget.py,v 1.1 2002/07/16 15:15:55 srichter Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from Zope.App.Forms.Views.Browser.Widget import TextWidget
from testBrowserWidget import BrowserWidgetTest, Field
class TextWidgetTest(BrowserWidgetTest):
def setUp(self):
field = Field()
request = {'field_foo': 'Foo Value'}
self._widget = TextWidget(field, request)
def testProperties(self):
self.assertEqual(self._widget.getValue('tag'), 'input')
self.assertEqual(self._widget.getValue('type'), 'text')
self.assertEqual(self._widget.getValue('cssClass'), '')
self.assertEqual(self._widget.getValue('hidden'), 0)
self.assertEqual(self._widget.getValue('extra'), '')
self.assertEqual(self._widget.getValue('default'), '')
self.assertEqual(self._widget.getValue('displayWidth'), 20)
self.assertEqual(self._widget.getValue('displayMaxWidth'), '')
def testRender(self):
value = 'Foo Value'
check_list = ('type="text"', 'name="field_foo"', 'value="Foo Value"',
'size="20"')
self._verifyResult(self._widget.render(value), check_list)
check_list = ('type="hidden"',) + check_list[1:-1]
self._verifyResult(self._widget.renderHidden(value), check_list)
check_list = ('style="color: red"',) + check_list
self._widget.extra = 'style="color: red"'
self._verifyResult(self._widget.renderHidden(value), check_list)
def test_suite():
return TestSuite((
makeSuite(TextWidgetTest),
))
if __name__=='__main__':
main(defaultTest='test_suite')