示例#1
0
 def test_default(self):
     f = Form('login')
     f.add_text('username', 'User Name')
     f.add_file('file')
     filesub = DumbObject(filename='text.txt',
                          content_type='text/plain',
                          content_length=10)
     f.set_defaults({'username': '******', 'file': filesub})
     self.assertEqual(
         '<input class="text" id="login-username" name="username" type="text" value="test1" />',
         str(f.elements.username.render()))
示例#2
0
 def test_submit(self):
     f = Form('login')
     f.add_text('username', 'User Name')
     f.set_defaults({'username': '******'})
     post = {'login-submit-flag': 'submitted', 'username': '******'}
     f.set_submitted(post)
     self.assertEqual(
         '<input class="text" id="login-username" name="username" type="text" value="test2" />',
         str(f.elements.username.render()))
     assert f.get_values() == {
         'username': '******',
         'login-submit-flag': 'submitted'
     }
def test_radio():
    no_value = '<span class="radio static" id="f-f">&nbsp;</span>'
    el = Form('f', static=True).add_radio('f', 'label', group='thegroup')
    assert el() == no_value, el()
    el = Form('f', static=True).add_radio('f',
                                          'label',
                                          group='thegroup',
                                          selected=True)
    assert el() == no_value, el()
    el = Form('f', static=True).add_radio('f', 'label', group='thegroup')
    assert el(selected='selected') == no_value, el(selected='selected')

    value = '<span class="radio static" id="f-f">foo</span>'
    el = Form('f', static=True).add_radio('f',
                                          'label',
                                          defaultval='foo',
                                          group='thegroup')
    assert el() == no_value, el()
    el = Form('f', static=True).add_radio('f',
                                          'label',
                                          defaultval='foo',
                                          group='thegroup',
                                          selected=True)
    assert el() == value, el()
    el = Form('f', static=True).add_radio('f',
                                          'label',
                                          defaultval='foo',
                                          group='thegroup')
    assert el(checked='checked') == value, el(selected='selected')

    # test the elements getting chosen by setting form defaults
    no_value1 = '<span class="radio static" id="f-f1">&nbsp;</span>'
    value1 = '<span class="radio static" id="f-f1">foo</span>'
    no_value2 = '<span class="radio static" id="f-f2">&nbsp;</span>'
    f = Form('f', static=True)
    el1 = f.add_radio('f1', 'label', 'foo', 'thegroup')
    el2 = f.add_radio('f2', 'label', 'bar', 'thegroup')
    assert el1() == no_value1, el1()
    assert el2() == no_value2, el2()
    f.set_defaults({'thegroup': 'foo'})
    assert el1() == value1, el1()
    assert el2() == no_value2, el2()