WIP: validators #3

Closed
dkdent wants to merge 6 commits from validators into master
2 changed files with 19 additions and 1 deletions
Showing only changes of commit 652d1445a8 - Show all commits

View file

@ -1,4 +1,4 @@
from validators import mandatory, empty, iso_date, valid_iban, valid_bic
from validators import mandatory, empty, iso_date, valid_iban, valid_bic, valid_money_amount
def test_mandatory():
@ -48,3 +48,12 @@ def test_valid_bic():
assert valid_bic("PBNKDEFFXXX".split()) == False
def test_valid_money_amount():
assert valid_money_amount(None) == False
assert valid_money_amount("") == False
assert valid_money_amount("0,00") == False
assert valid_money_amount("13,37") == False
assert valid_money_amount("0") == True
assert valid_money_amount("0.00") == True
assert valid_money_amount("13") == True
assert valid_money_amount("13.37") == True

View file

@ -42,3 +42,12 @@ def valid_bic(field: str) -> bool:
return True
except ValueError:
return False
def valid_money_amount(field: str) -> bool:
if not field:
return False
try:
float(field)
return True
except (ValueError, TypeError):
return False