entities_validation_svc/validators/test_validators.py

59 lines
1.9 KiB
Python
Raw Normal View History

2020-11-07 19:53:47 +01:00
from validators import mandatory, empty, iso_date, valid_iban, valid_bic, valid_money_amount
2020-11-06 22:23:47 +01:00
def test_mandatory():
assert mandatory("Foo") == True
assert mandatory("Foo Bar") == True
assert mandatory("1970-01-01") == True
assert mandatory("") == False
2020-11-07 13:19:55 +01:00
assert mandatory(None) == False
2020-11-06 22:23:47 +01:00
def test_empty():
2020-11-07 13:19:55 +01:00
assert empty(None) == True
2020-11-06 22:23:47 +01:00
assert empty("") == True
assert empty(" ") == False
assert empty("Foo") == False
assert empty("1970-01-01") == False
def test_iso_date():
assert iso_date("1970-01-01") == True
assert iso_date("1970-1-1") == True
assert iso_date("70-01-01") == False
assert iso_date("1970/01/01") == False
assert iso_date("1.1.1970") == False
assert iso_date("01.01.1970") == False
2020-11-07 13:19:55 +01:00
assert iso_date("") == False
assert iso_date(None) == False
2020-11-06 22:23:47 +01:00
def test_valid_iban():
assert valid_iban("DE89 3704 0044 0532 0130 00") == True
2020-11-07 13:19:55 +01:00
assert valid_iban("DE89370400440532013000") == True
2020-11-06 22:23:47 +01:00
assert valid_iban("DX89 3704 0044 0532 0130 00") == False
assert valid_iban("DE99 3704 0044 0532 0130 00") == False
2020-11-07 13:19:55 +01:00
assert valid_iban("") == False
assert valid_iban(None) == False
assert valid_iban("DE89 3704 0044 0532 0130 00".split()) == False
2020-11-06 22:23:47 +01:00
def test_valid_bic():
assert valid_bic("PBNKDEFFXXX") == True
assert valid_bic("PBNKDXFFXXX") == False
assert valid_bic("PBNKDXFFXXXX") == False
assert valid_bic("PBN1DXFFXXX") == False
2020-11-07 13:19:55 +01:00
assert valid_bic("") == False
assert valid_bic(None) == False
assert valid_bic("PBNKDEFFXXX".split()) == False
2020-11-07 19:53:47 +01:00
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