def test_blank_radio(self): f = Form('login') el1 = f.add_radio('radio1', 'Radio 1', 1, 'rgroup1', selected=True) el2 = f.add_radio('radio2', 'Radio 2', 2, 'rgroup1') assert 'checked="checked"' in el1() assert 'checked="checked"' not in el2() post = {'login-submit-flag': 'submitted'} f.set_submitted(post) assert not f.get_values()['rgroup1'] # should unset on re-post after a blank submit assert 'selected="selected"' not in el1() assert 'selected="selected"' not in el2()
def test_radio(): no_value = '<span class="radio static" id="f-f"> </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"> </span>' value1 = '<span class="radio static" id="f-f1">foo</span>' no_value2 = '<span class="radio static" id="f-f2"> </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()