from turbogears import validators

def test_booleanstrings():
    """'False', 'false', 'True', 'true' should be proper boolean values"""
    b = validators.StringBoolean()
    assert 'false' == b.from_python(False)
    assert 'true' == b.from_python(True)
    assert 'false' == b.from_python(0)
    assert 'true' == b.from_python(1)
    assert b.to_python("True") is True
    assert b.to_python("False") is False
    assert b.to_python("true") is True
    assert b.to_python("false") is False
    assert b.to_python("") is False
    assert b.to_python(None) is False
    
    try:
        b.to_python("foobar")
        assert False, "random strings should fail validation"
    except validators.Invalid:
        pass