Пример #1
0
    def test_use_default_for_not_selected(self):
        # test use_default_for_not_selected = True
        request = TestRequest()
        # the default selection shoud be the the option field which has the
        # value of None
        field = Union(
            (zc.form.field.TextLine(
                title=u"New Password", missing_value=u'',
                default_getter=lambda x: u'secret password'),
             zc.form.field.Option(
                title=u"No Change", value='no change')),
            title=u"Change Password",
            missing_value=u'',
            use_default_for_not_selected=True,
            __name__='identifier')
        widget = UnionWidget(field, request)
        widget.setPrefix('field')
        output = widget()
        # remove double whitespaces
        normalized_output = " ".join(output.split())

        # the value of the textline field should be the default_getter's
        # result
        value_attr_of_textline = re.search(
            '<input.*id="field.identifier.unioned_00".*(value=".*").*></div>',
            normalized_output).groups()[0]
        self.assertIn('secret password', value_attr_of_textline)

        # the radio button of the option field should be selected
        radio_option_field = re.search(
            '<input.*id="field.identifier-01"(.*)/> </td>',
            normalized_output).groups()[0]
        self.assertIn('checked="checked"', radio_option_field)
Пример #2
0
    def test_use_default_for_not_selected(self):
        # test use_default_for_not_selected = True
        request = TestRequest()
        # the default selection shoud be the the option field which has the
        # value of None
        field = Union(
            (zc.form.field.TextLine(
                    title=u"New Password", missing_value=u'',
                    default_getter=lambda x: u'secret password'),
             zc.form.field.Option(
                    title=u"No Change", value_getter=lambda x: None)),
            title=u"Change Password",
            missing_value=u'',
            use_default_for_not_selected=True,
            __name__='identifier')
        widget = UnionWidget(field, request)
        widget.setPrefix('field')
        output = widget()
        # remove double whitespaces
        normalized_output = " ".join(output.split())

        # the value of the textline field should be the default_getter's
        # result
        value_attr_of_textline = re.search(
            '<input.*id="field.identifier.unioned_00".*(value=".*").*></div>',
            normalized_output).groups()[0]
        self.failUnless('secret password' in value_attr_of_textline)

        # the radio button of the option field should be selected
        radio_option_field = re.search(
            '<input.*id="field.identifier-01"(.*)/> </td>',
            normalized_output).groups()[0]
        self.failUnless('checked="checked"' in radio_option_field)
Пример #3
0
 def test_render(self):
     request = TestRequest()
     field = Union(
         (TextLine(title=u"Name", min_length=5),
          Int(title=u"Age", min=0)),
         title=u"Simple Identifier",
         __name__='identifier')
     widget = UnionWidget(field, request)
     widget.setPrefix('field')
     output = widget()
     self.assertIn('<table', output)
     self.assertIn('Age', output)
     self.assertIn('Name', output)
     self.assertRegex(output, r'''type=['"]radio['"]''')
     self.assertRegex(output, r'''name=['"]field.identifier['"]''')
     self.assertRegex(output, r'''id=["']field.identifier-00['"]''')
     self.assertRegex(output, r'''id=["']field.identifier-01['"]''')
     self.assertRegex(
         output, r'''name=["']field.identifier.unioned_00['"]''')
     self.assertRegex(
         output, r'''name=["']field.identifier.unioned_01['"]''')
     self.assertNotRegex(output, r'''id=["']field.identifier-02['"]''')
     self.assertNotRegex(output, r'''checked\s*=\s*['"]checked['"]''')
     field = Union(
         (TextLine(title=u"Name", min_length=5),
          Int(title=u"Age", min=0)),
         title=u"Simple Identifier",
         __name__='identifier',
         required=False)
     widget = UnionWidget(field, request)
     widget.setPrefix('field')
     output = widget()
     self.assertRegex(output, r'''id=["']field.identifier-02['"]''')
     self.assertRegex(output, r'''checked\s*=\s*['"]checked['"]''')
Пример #4
0
 def test_evaluate(self):
     request = TestRequest()
     request.form.update({
         'field.identifier-marker': 'x',
         'field.identifier.unioned_00': u'Foo Bar',
         'field.identifier': '0'})
     field = Union(
         (TextLine(title=u"Name", min_length=5),
          Int(title=u"Age", min=0)),
         title=u"Simple Identifier",
         __name__='identifier')
     widget = UnionWidget(field, request)
     widget.setPrefix('field')
     self.assertEqual(widget.loadValueFromRequest(), u'Foo Bar')
Пример #5
0
 def test_evaluate(self):
     request = TestRequest()
     request.form.update({
         'field.identifier-marker':'x',
         'field.identifier.unioned_00':u'Foo Bar',
         'field.identifier':'0'})
     field = Union(
         (TextLine(title=u"Name", min_length=5),
          Int(title=u"Age", min=0)),
         title=u"Simple Identifier",
         __name__='identifier')
     widget = UnionWidget(field, request)
     widget.setPrefix('field')
     output = widget() # to initialize
     self.assertEquals(widget.loadValueFromRequest(), u'Foo Bar')
Пример #6
0
 def test_render(self):
     request = TestRequest()
     field = Union(
         (TextLine(title=u"Name", min_length=5),
          Int(title=u"Age", min=0)),
         title=u"Simple Identifier",
         __name__='identifier')
     widget = UnionWidget(field, request)
     widget.setPrefix('field')
     output = widget()
     self.failUnless('<table' in output)
     self.failUnless('Age' in output)
     self.failUnless('Name' in output)
     self.failUnless(re.search(
         '''type=['"]radio['"]''', output))
     self.failUnless(re.search(
         '''name=['"]field.identifier['"]''', output))
     self.failUnless(re.search(
         '''id=["']field.identifier-00['"]''', output))
     self.failUnless(re.search(
         '''id=["']field.identifier-01['"]''', output))
     self.failUnless(re.search(
         '''name=["']field.identifier.unioned_00['"]''', output))
     self.failUnless(re.search(
         '''name=["']field.identifier.unioned_01['"]''', output))
     self.failIf(re.search(
         '''id=["']field.identifier-02['"]''', output))
     self.failIf(re.search(
         '''checked\s*=\s*['"]checked['"]''', output))
     field = Union(
         (TextLine(title=u"Name", min_length=5),
          Int(title=u"Age", min=0)),
         title=u"Simple Identifier",
         __name__='identifier',
         required=False)
     widget = UnionWidget(field, request)
     widget.setPrefix('field')
     output = widget()
     self.failUnless(re.search(
         '''id=["']field.identifier-02['"]''', output))
     self.failUnless(re.search(
         '''checked\s*=\s*['"]checked['"]''', output))