This file is indexed.

/usr/share/pyshared/zope/formlib/tests/test_functional_selectwidget.py is in python-zope.formlib 4.0.5-0ubuntu5.

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
##############################################################################
#
# 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.
#
##############################################################################
"""RadioWidget Tests
"""
import unittest

from zope.interface import Interface, implements
from zope.schema import Choice
from zope.formlib import form
from zope.publisher.browser import TestRequest
from zope.formlib.tests.support import patternExists
from zope.formlib.widgets import (
    TextWidget,
    DropdownWidget, ChoiceInputWidget)
from zope.formlib.tests.functionalsupport import FunctionalWidgetTestCase
import zope.schema.interfaces

class IRadioTest(Interface):

    s3 = Choice(
        required=False,
        values=(u'Bob', u'is', u'Your', u'Uncle'))

    s4 = Choice(
        required=True,
        values=(u'1', u'2', u'3'))

class RadioTest(object):

    implements(IRadioTest)

    def __init__(self):
        self.s3 = None
        self.s4 = u'1'

class Form(form.EditForm):
    form_fields = form.fields(IRadioTest)
    
class Test(FunctionalWidgetTestCase):
    widgets = [
        (zope.schema.interfaces.ITextLine, TextWidget),
        (zope.schema.interfaces.IChoice, ChoiceInputWidget),
        ((zope.schema.interfaces.IChoice, zope.schema.interfaces.IVocabularyTokenized),
         DropdownWidget)]

    def test_display_editform(self):
        foo = RadioTest()
        request = TestRequest()

        # display edit view
        html = Form(foo, request)()
        
        # S3
        self.assert_(patternExists(
            '<select .* name="form.s3".*>',
            html))
        self.assert_(patternExists(
            '<option selected="selected" value="">',
            html))
        self.assert_(patternExists(
            '<option value="Bob">',
            html))
        self.assert_(patternExists(
            '<option value="is">',
            html))
        self.assert_(patternExists(
            '<option value="Your">',
            html))
        self.assert_(patternExists(
            '<option value="Uncle">',
            html))

        # S4
        joined_body = "".join(html.split("\n"))
        self.failIf(patternExists(
            '<select.*name="form.s4".*>.*<option.*value="".*>',
            joined_body))
        self.assert_(patternExists(
            '<select .* name="form.s4".*>',
            html))
        self.assert_(patternExists(
            '<option selected="selected" value="1">',
            html))
        self.assert_(patternExists(
            '<option value="2">',
            html))
        self.assert_(patternExists(
            '<option value="3">',
            html))

        request = TestRequest()
        request.form['form.s3'] = u'Bob'
        request.form['form.s4'] = u'2'
        request.form['form.actions.apply'] = u''
        
        # display edit view
        html = Form(foo, request)()

        self.assert_(patternExists(
            '<option selected="selected" value="Bob">',
            html))
        self.assert_(patternExists(
            '<option selected="selected" value="2">',
            html))

        
        html = Form(foo, request)()
        self.assert_(patternExists(
            '<option selected="selected" value="Bob">',
            html))
        self.assert_(patternExists(
            '<option selected="selected" value="2">',
            html))

        request = TestRequest()
        request.form['form.s3'] = u''
        request.form['form.actions.apply'] = u''
        
        html = Form(foo, request)()
        self.assert_(patternExists(
            '<option selected="selected" value="">',
            html))
        self.assert_(patternExists(
            '<option selected="selected" value="2">',
            html))

        request = TestRequest()
        html = Form(foo, request)()

        self.assert_(patternExists(
            '<option selected="selected" value="">',
            html))

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