test implementation
This commit is contained in:
parent
c9b1208236
commit
1cc05cd5e6
2 changed files with 78 additions and 0 deletions
|
@ -1,3 +1,5 @@
|
|||
tornado==6.0.4
|
||||
isodate==0.6.0
|
||||
pytest==5.4.1
|
||||
schwifty==2020.11.0
|
||||
Cerberus==1.3.2
|
76
test_cerberus.py
Normal file
76
test_cerberus.py
Normal file
|
@ -0,0 +1,76 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import cerberus
|
||||
from schwifty import IBAN, BIC
|
||||
import datetime
|
||||
|
||||
def valid_iban(field, value, error):
|
||||
try:
|
||||
IBAN(value)
|
||||
return True
|
||||
except ValueError:
|
||||
error(field, 'not a valid IBAN')
|
||||
|
||||
def valid_bic(field, value, error):
|
||||
try:
|
||||
BIC(value)
|
||||
return True
|
||||
except ValueError:
|
||||
error(field, 'not a valid BIC')
|
||||
|
||||
def iso_date(field, value, error):
|
||||
try:
|
||||
datetime.datetime.strptime(value, "%Y-%m-%d")
|
||||
return True
|
||||
except ValueError:
|
||||
error(field, 'not a valid IDO 8601 date')
|
||||
|
||||
document = {
|
||||
'finanzdaten':
|
||||
{
|
||||
'bic': 'PBNKDEFFXXX',
|
||||
'holder': '',
|
||||
'iban': 'DE89370400440532013000',
|
||||
'issuance': '2012-01-01',
|
||||
'reference': '0042',
|
||||
'scan-sepa-mandate': ''
|
||||
},
|
||||
'mitgliederdaten':
|
||||
{
|
||||
'bis': '',
|
||||
'mitgliedsbeitrag': '30',
|
||||
'scan-antrag': '',
|
||||
'schliessberechtigung': 'Ja',
|
||||
'spendenbeitrag': '',
|
||||
'status': 'V',
|
||||
'von': '2012-01-01'
|
||||
},
|
||||
'stammdaten':
|
||||
{
|
||||
'address_code': '39104',
|
||||
'address_country': 'DE',
|
||||
'address_label': 'Max Hackerberg\nLeibnizstr. 32\n39104 Magdeburg',
|
||||
'address_locality': 'Magdeburg',
|
||||
'address_region': '',
|
||||
'address_street': 'Leibnizstr. 32',
|
||||
'birth_date': '1970-01-01',
|
||||
'birth_location': 'Hackstadt',
|
||||
'email': 'max.hackerberg@netz39.de',
|
||||
'fullname': 'Max Hackerberg',
|
||||
'nickname': 'maxH',
|
||||
'pgp-key': '',
|
||||
'ssh-key': ''
|
||||
},
|
||||
'timestamp': '2020-03-25T23:58:11',
|
||||
'id': '6af68'
|
||||
}
|
||||
|
||||
schema_fin={'bic': {'type': 'string', 'check_with': valid_bic},
|
||||
'iban': {'type': 'string', 'check_with': valid_iban},
|
||||
'issuance': {'type': 'string', 'check_with': iso_date},
|
||||
'reference': {'type': 'string'},
|
||||
'scan-sepa-mandate': {'type': 'string'},
|
||||
'holder': {'type': 'string'}}
|
||||
|
||||
v = cerberus.Validator()
|
||||
v.validate(document['finanzdaten'], schema_fin)
|
Loading…
Reference in a new issue