Compare commits

..

1 commit

Author SHA1 Message Date
d851405b6b add validator functions and tests 2022-08-03 23:37:07 +02:00
5 changed files with 76 additions and 8 deletions

View file

@ -8,7 +8,7 @@ COPY . /git/
RUN find . -type d -name .git -exec git describe --always --dirty > /git-version.txt \;
FROM python:3.13
FROM python:3.8
EXPOSE 8080

View file

@ -1,3 +0,0 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
}

View file

@ -1,4 +1,4 @@
tornado==6.4.1
isodate==0.7.2
pytest==8.3.3
GitPython==3.1.43
tornado==6.0.4
isodate==0.6.0
pytest==5.4.1
GitPython==3.1.12

View file

@ -0,0 +1,37 @@
from validators import mandatory, empty, iso_date, valid_iban, valid_bic
def test_mandatory():
assert mandatory("Foo") == True
assert mandatory("Foo Bar") == True
assert mandatory("1970-01-01") == True
assert mandatory("") == False
def test_empty():
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
def test_valid_iban():
assert valid_iban("DE89 3704 0044 0532 0130 00") == True
assert valid_iban("DX89 3704 0044 0532 0130 00") == False
assert valid_iban("DE99 3704 0044 0532 0130 00") == False
def test_valid_bic():
assert valid_bic("PBNKDEFFXXX") == True
assert valid_bic("PBNKDXFFXXX") == False
assert valid_bic("PBNKDXFFXXXX") == False
assert valid_bic("PBN1DXFFXXX") == False

34
validators/validators.py Normal file
View file

@ -0,0 +1,34 @@
import datetime
from schwifty import IBAN, BIC
def mandatory(field: str) -> bool:
return bool(field)
def empty(field: str) -> bool:
return not bool(field)
def iso_date(field: str) -> bool:
try:
datetime.datetime.strptime(field, "%Y-%m-%d")
return True
except ValueError:
return False
def valid_iban(field: str) -> bool:
try:
IBAN(field)
return True
except ValueError:
return False
def valid_bic(field: str) -> bool:
try:
BIC(field)
return True
except ValueError:
return False