This file is indexed.

/usr/lib/python2.7/dist-packages/zope/formlib/tests/test_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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
##############################################################################
#
# 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
import doctest
from zope.formlib.interfaces import IInputWidget
from zope.formlib.widgets import CheckBoxWidget
from zope.publisher.browser import TestRequest
from zope.schema import Bool
from zope.interface.verify import verifyClass

from zope.formlib.interfaces import MissingInputError
from zope.formlib.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_required(self):
        # checkbox widgets are never required, since there's no way to
        # set it to "no value"
        self.failIf(self._widget.required)
        self.assert_(self._widget.context.required)


def test_suite():
    return unittest.TestSuite((
        unittest.makeSuite(CheckBoxWidgetTest),
        doctest.DocTestSuite(),
        ))

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