Compare commits
3 commits
25a0f902ab
...
0082ee2bad
Author | SHA1 | Date | |
---|---|---|---|
0082ee2bad | |||
fee14d9349 | |||
6758bb5a44 |
5 changed files with 51 additions and 43 deletions
|
@ -66,7 +66,7 @@ def validate(entity):
|
|||
'email': {
|
||||
'type': 'string',
|
||||
'required': True,
|
||||
'regex': '^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$'},
|
||||
'check_with': valid_email},
|
||||
'fullname': {
|
||||
'type': 'string',
|
||||
'required': True},
|
||||
|
|
|
@ -2,4 +2,5 @@ tornado==6.0.4
|
|||
isodate==0.6.0
|
||||
pytest==5.4.1
|
||||
schwifty==2020.11.0
|
||||
Cerberus==1.3.2
|
||||
Cerberus==1.3.2
|
||||
validator-collection==1.5.0
|
42
test.py
42
test.py
|
@ -58,49 +58,11 @@ class TestValidation(tornado.testing.AsyncHTTPTestCase):
|
|||
self.assertFalse(validation_result['valid'], "Validation result is expected to be valid==false")
|
||||
|
||||
def test_valid_entity(self):
|
||||
entity = {
|
||||
'finanzdaten':
|
||||
{
|
||||
'bic': 'PBNKDEFFXXX',
|
||||
'holder': '',
|
||||
'iban': 'DE89370400440532013000',
|
||||
'issuance': '2012-01-01',
|
||||
'reference': '0042',
|
||||
'scan-sepa-mandate': ''
|
||||
},
|
||||
'mitgliederdaten':
|
||||
{
|
||||
'bis': '',
|
||||
'mitgliedsbeitrag': '30',
|
||||
'scan-antrag': '',
|
||||
'schliessberechtigung': 'Ja',
|
||||
'spendenbeitrag': '0',
|
||||
'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'
|
||||
}
|
||||
entity_file = json.load(open('test_cases/valid/valid.json','r'))
|
||||
|
||||
response = self.fetch('/v0/validate',
|
||||
method='POST',
|
||||
body=json.dumps(entity))
|
||||
body=json.dumps(entity_file))
|
||||
|
||||
self.assertEqual(200, response.code, "Validation must always return 200")
|
||||
|
||||
|
|
36
test_cases/valid/valid.json
Normal file
36
test_cases/valid/valid.json
Normal file
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
"finanzdaten": {
|
||||
"bic": "PBNKDEFFXXX",
|
||||
"holder": "",
|
||||
"iban": "DE89370400440532013000",
|
||||
"issuance": "2012-01-01",
|
||||
"reference": "0042",
|
||||
"scan-sepa-mandate": ""
|
||||
},
|
||||
"mitgliederdaten": {
|
||||
"bis": "",
|
||||
"mitgliedsbeitrag": "30",
|
||||
"scan-antrag": "",
|
||||
"schliessberechtigung": "Ja",
|
||||
"spendenbeitrag": "0",
|
||||
"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"
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
from schwifty import IBAN, BIC
|
||||
import datetime
|
||||
from validator_collection import validators, errors
|
||||
|
||||
def valid_iban(field, value, error):
|
||||
try:
|
||||
|
@ -24,7 +25,15 @@ def iso_date(field, value, error):
|
|||
|
||||
def valid_money_amount(field, value, error):
|
||||
try:
|
||||
# value is string, check formatting by parsing as float
|
||||
float(value)
|
||||
return True
|
||||
except (ValueError, TypeError):
|
||||
error(field, 'not a valid money value')
|
||||
error(field, 'not a valid money value')
|
||||
|
||||
def valid_email(field, value, error):
|
||||
try:
|
||||
validators.email(value)
|
||||
return True
|
||||
except errors.InvalidEmailError:
|
||||
error(field, 'not a valid email')
|
Loading…
Reference in a new issue