/usr/lib/python2.7/dist-packages/zope/formlib/tests/test_functional_checkboxwidget.py is in python-zope.formlib 4.3.0a2-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | ##############################################################################
#
# Copyright (c) 2001, 2002 Zope Foundation 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
"""
import unittest
from zope.interface import Interface, implementer
from zope.schema import Bool
from zope.formlib import form
from zope.publisher.browser import TestRequest
from zope.formlib.tests.support import patternExists
from zope.formlib.widgets import CheckBoxWidget
from zope.formlib.tests.functionalsupport import FunctionalWidgetTestCase
import zope.schema.interfaces
class IBoolTest(Interface):
b1 = Bool(
required=True)
b2 = Bool(
required=False)
@implementer(IBoolTest)
class BoolTest(object):
def __init__(self):
self.b1 = True
self.b2 = False
class Form(form.EditForm):
form_fields = form.fields(IBoolTest)
class Test(FunctionalWidgetTestCase):
widgets = [(zope.schema.interfaces.IBool, CheckBoxWidget)]
def test_display_editform(self):
foo = BoolTest()
request = TestRequest()
html = Form(foo, request)()
# b1 and b2 should be displayed in checkbox input fields
self.assert_(patternExists(
'<input .* checked="checked".* name="form.b1".* ' \
'type="checkbox".* />',
html))
self.assert_(patternExists(
'<input .* name="form.b2".* type="checkbox".* />',
html))
# confirm that b2 is *not* checked
self.assert_(not patternExists(
'<input .* checked="checked".* name="form.b2".* ' \
'type="checkbox".* />',
html))
def test_submit_editform(self):
foo = BoolTest()
request = TestRequest()
request.form['form.b1'] = ''
request.form['form.b2'] = 'on'
request.form['form.actions.apply'] = u''
Form(foo, request)()
# check new values in object
self.assertEqual(foo.b1, False)
self.assertEqual(foo.b2, True)
def test_unexpected_value(self):
foo = BoolTest()
foo.b1 = True
foo.b2 = True
request = TestRequest()
request.form['form.b1'] = 'true'
request.form['form.b2'] = 'foo'
request.form['form.actions.apply'] = u''
Form(foo, request)()
# values other than 'on' should be treated as False
self.assertEqual(foo.b1, False)
self.assertEqual(foo.b2, False)
def test_missing_value(self):
# Note: checkbox widget doesn't support a missing value. This
# test confirms that one cannot set a Bool field to None.
foo = BoolTest()
self.assertEqual(foo.b1, True)
request = TestRequest()
request.form['form.b1'] = CheckBoxWidget._missing
Form(foo, request)()
# confirm b1 is not missing
self.assert_(foo.b1 != Bool.missing_value)
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(Test))
return suite
|