Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace 'import doctest' with 'from zope.testing import doctest'.
- Loading branch information
Showing
15 changed files
with
2,340 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
############################################################################## | ||
# | ||
# Copyright (c) 2005 Zope Corporation and Contributors. | ||
# All Rights Reserved. | ||
# | ||
# This software is subject to the provisions of the Zope Public License, | ||
# Version 2.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. | ||
# | ||
############################################################################## | ||
"""Test form i18n | ||
$Id$ | ||
""" | ||
import unittest | ||
from zope.testing import doctest | ||
from persistent import Persistent | ||
from zope.interface import Interface, implements | ||
from zope.schema import TextLine, Text, Int, List | ||
from zope.i18nmessageid import MessageFactory | ||
from zope.app.testing.functional import FunctionalDocFileSuite | ||
|
||
_ = MessageFactory('formtest') | ||
|
||
__docformat__ = "reStructuredText" | ||
|
||
class IFieldContent(Interface): | ||
|
||
title = TextLine( | ||
title=_(u"Title"), | ||
description=_(u"A short description of the event."), | ||
default=u"", | ||
required=True | ||
) | ||
|
||
description = Text( | ||
title=_(u"Description"), | ||
description=_(u"A long description of the event."), | ||
default=u"", | ||
required=False | ||
) | ||
|
||
somenumber = Int( | ||
title=_(u"Some number"), | ||
default=0, | ||
required=False | ||
) | ||
|
||
somelist = List( | ||
title=_(u"Some List"), | ||
value_type=TextLine(title=_(u"Some item")), | ||
default=[], | ||
required=False | ||
) | ||
|
||
class FieldContent(Persistent): | ||
implements(IFieldContent) | ||
|
||
def test_suite(): | ||
return unittest.TestSuite([ | ||
FunctionalDocFileSuite('i18n.txt', package='zope.app.form.browser', | ||
optionflags=doctest.ELLIPSIS) | ||
]) | ||
|
||
if __name__ == '__main__': | ||
unittest.main(defaultTest='test_suite') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
############################################################################## | ||
# | ||
# 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.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. | ||
# | ||
############################################################################## | ||
"""Test object widget | ||
$Id$ | ||
""" | ||
import unittest | ||
from zope.testing import doctest | ||
from zope.interface import Interface, implements | ||
from zope.publisher.browser import TestRequest | ||
from zope.schema import Object, TextLine | ||
import zope.security.checker | ||
from zope.app.form.browser import ObjectWidget | ||
from zope.app.testing.functional import BrowserTestCase | ||
from zope.app.form.browser.tests import support | ||
|
||
|
||
class ITestContact(Interface): | ||
name = TextLine() | ||
email = TextLine() | ||
|
||
class TestContact(object): | ||
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@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@fred.com') | ||
check_list = ( | ||
'input', 'name="field.foo.name"', 'value="fred"', | ||
'input', 'name="field.foo.email"', 'value="fred@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') | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
############################################################################## | ||
# | ||
# 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.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. | ||
# | ||
############################################################################## | ||
"""Checkbox Widget tests | ||
$Id$ | ||
""" | ||
import unittest | ||
from zope.testing import doctest | ||
from zope.app.form.interfaces import IInputWidget | ||
from zope.app.form.browser import CheckBoxWidget | ||
from zope.publisher.browser import TestRequest | ||
from zope.schema import Bool | ||
from zope.interface.verify import verifyClass | ||
|
||
from zope.app.form.interfaces import MissingInputError | ||
from zope.app.form.browser.tests.test_browserwidget import SimpleInputWidgetTest | ||
|
||
|
||
class CheckBoxWidgetTest(SimpleInputWidgetTest): | ||
"""Documents and tests thec checkbox widget. | ||
>>> verifyClass(IInputWidget, CheckBoxWidget) | ||
True | ||
The checkbox widget works with Bool fields: | ||
>>> field = Bool(__name__='foo', title=u'on') | ||
>>> request = TestRequest() | ||
>>> widget = CheckBoxWidget(field, request) | ||
hasInput returns True when the request contains the field.<name>.used | ||
value: | ||
>>> 'field.foo.used' in request.form | ||
False | ||
>>> widget.hasInput() | ||
False | ||
>>> request.form['field.foo.used'] = '' | ||
>>> widget.hasInput() | ||
True | ||
getInputValue returns True when field.<name> equals (and only equals) 'on': | ||
>>> 'field.foo' in request.form | ||
False | ||
>>> widget.getInputValue() | ||
False | ||
>>> request.form['field.foo'] = 'true' | ||
>>> widget.getInputValue() | ||
False | ||
>>> request.form['field.foo'] = 'on' | ||
>>> widget.getInputValue() | ||
True | ||
Below is HTML output of rendered checkbox widgets. We will first define | ||
a helper method condense the HTML output for display in this test: | ||
>>> def normalize(s): | ||
... return '\\n '.join(s.split()) | ||
Default widget rendering: | ||
>>> print normalize( widget() ) | ||
<input | ||
class="hiddenType" | ||
id="field.foo.used" | ||
name="field.foo.used" | ||
type="hidden" | ||
value="" | ||
/> | ||
<input | ||
class="checkboxType" | ||
checked="checked" | ||
id="field.foo" | ||
name="field.foo" | ||
type="checkbox" | ||
value="on" | ||
/> | ||
Hidden rendering: | ||
>>> print normalize( widget.hidden() ) | ||
<input | ||
class="hiddenType" | ||
id="field.foo" | ||
name="field.foo" | ||
type="hidden" | ||
value="on" | ||
/> | ||
Calling setRenderedValue will change what gets output: | ||
>>> widget.setRenderedValue(False) | ||
>>> print normalize( widget() ) | ||
<input | ||
class="hiddenType" | ||
id="field.foo.used" | ||
name="field.foo.used" | ||
type="hidden" | ||
value="" | ||
/> | ||
<input | ||
class="checkboxType" | ||
id="field.foo" | ||
name="field.foo" | ||
type="checkbox" | ||
value="on" | ||
/> | ||
The checkbox widget does not support None values, so a Bool required | ||
constraint will always be met with checkbox input: | ||
>>> field.required = True | ||
>>> widget.getInputValue() | ||
True | ||
""" | ||
|
||
_FieldFactory = Bool | ||
_WidgetFactory = CheckBoxWidget | ||
|
||
def testProperties(self): | ||
self.assertEqual(self._widget.tag, 'input') | ||
self.assertEqual(self._widget.type, 'checkbox') | ||
self.assertEqual(self._widget.cssClass, '') | ||
self.assertEqual(self._widget.extra, '') | ||
self.assertEqual(self._widget.default, 0) | ||
|
||
def testRender(self): | ||
value = 1 | ||
self._widget.setRenderedValue(value) | ||
check_list = ('type="checkbox"', 'id="field.foo"', | ||
'name="field.foo"', 'checked="checked"') | ||
self.verifyResult(self._widget(), check_list) | ||
value = 0 | ||
self._widget.setRenderedValue(value) | ||
check_list = check_list[:-1] | ||
self.verifyResult(self._widget(), check_list) | ||
check_list = ('type="hidden"',) + check_list[1:-1] | ||
self.verifyResult(self._widget.hidden(), check_list) | ||
check_list = ('style="color: red"',) + check_list | ||
self._widget.extra = 'style="color: red"' | ||
self.verifyResult(self._widget.hidden(), check_list) | ||
|
||
def test_getInputValue(self): | ||
self._widget.request.form['field.foo'] = 'on' | ||
self.assertEqual(self._widget.getInputValue(), True) | ||
self._widget.request.form['field.foo'] = 'positive' | ||
self.assertEqual(self._widget.getInputValue(), False) | ||
del self._widget.request.form['field.foo'] | ||
self._widget.request.form['field.foo.used'] = '' | ||
self.assertEquals(self._widget.getInputValue(), False) | ||
del self._widget.request.form['field.foo.used'] | ||
self.assertRaises(MissingInputError, self._widget.getInputValue) | ||
|
||
|
||
def test_suite(): | ||
return unittest.TestSuite(( | ||
unittest.makeSuite(CheckBoxWidgetTest), | ||
doctest.DocTestSuite(), | ||
)) | ||
|
||
if __name__=='__main__': | ||
unittest.main(defaultTest='test_suite') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.