mirror of
https://github.com/LukeHagar/connexion.git
synced 2025-12-09 12:27:46 +00:00
Case insensitive check for boolean validation
This commit is contained in:
@@ -131,9 +131,9 @@ def boolean(s):
|
|||||||
>>> boolean('false')
|
>>> boolean('false')
|
||||||
False
|
False
|
||||||
'''
|
'''
|
||||||
if s in ['true', 'True']:
|
if s.lower() == 'true':
|
||||||
return True
|
return True
|
||||||
elif s in ['false', 'False']:
|
elif s.lower() == 'false':
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
raise ValueError('Invalid boolean value')
|
raise ValueError('Invalid boolean value')
|
||||||
|
|||||||
@@ -34,8 +34,10 @@ def test_get_function_from_name_for_class_method():
|
|||||||
def test_boolean():
|
def test_boolean():
|
||||||
assert utils.boolean('true')
|
assert utils.boolean('true')
|
||||||
assert utils.boolean('True')
|
assert utils.boolean('True')
|
||||||
|
assert utils.boolean('TRUE')
|
||||||
assert not utils.boolean('false')
|
assert not utils.boolean('false')
|
||||||
assert not utils.boolean('False')
|
assert not utils.boolean('False')
|
||||||
|
assert not utils.boolean('FALSE')
|
||||||
|
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
utils.boolean('foo')
|
utils.boolean('foo')
|
||||||
|
|||||||
Reference in New Issue
Block a user