From 4f59a39f1c04131db69e99f666d9d03124a2a0b3 Mon Sep 17 00:00:00 2001 From: tobiasraabe Date: Wed, 30 Aug 2017 12:54:27 +0200 Subject: [PATCH] Fix validators. --- tests/test_prompts_validators.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/tests/test_prompts_validators.py b/tests/test_prompts_validators.py index 043ecd6..4d2f677 100644 --- a/tests/test_prompts_validators.py +++ b/tests/test_prompts_validators.py @@ -9,16 +9,18 @@ from ovmm.prompts import validators +CTX = None +PARAM = None PASSWORD_LENGTH = os.environ.get('OVMM_PASSWORD_LENGTH') -@pytest.mark.parametrize('parse_func,input', [ - (getattr(validators, 'validate_user_name'), 'usern'), - (getattr(validators, 'validate_user_name'), '_username'), - (getattr(validators, 'validate_user_name'), '1username'), - (getattr(validators, 'validate_user_name'), 'UserName'), - (getattr(validators, 'validate_user_name'), 'us-ername'), - (getattr(validators, 'validate_user_name'), 'user name'), +@pytest.mark.parametrize('val_func,input', [ + (getattr(validators, 'validate_user_name'), [CTX, PARAM, 'usern']), + (getattr(validators, 'validate_user_name'), [CTX, PARAM, '_username']), + (getattr(validators, 'validate_user_name'), [CTX, PARAM, '1username']), + (getattr(validators, 'validate_user_name'), [CTX, PARAM, 'UserName']), + (getattr(validators, 'validate_user_name'), [CTX, PARAM, 'us-ername']), + (getattr(validators, 'validate_user_name'), [CTX, PARAM, 'user name']), (getattr(validators, 'validate_email'), 'user@name'), (getattr(validators, 'validate_email'), 'user@.de'), (getattr(validators, 'validate_email'), 'user.de'), @@ -27,12 +29,12 @@ (getattr(validators, 'validate_password'), 'AbCdEf G'), (getattr(validators, 'validate_password'), 'password'), ]) -def test_parser_error(parse_func, input): +def test_validator_error(val_func, input): with pytest.raises(click.BadParameter): - parse_func(input) + val_func(input) -@pytest.mark.parametrize('parse_func,input', [ +@pytest.mark.parametrize('val_func,input', [ (getattr(validators, 'validate_user_name'), 'username'), (getattr(validators, 'validate_user_name'), 'user_name'), (getattr(validators, 'validate_user_name'), 'user_1'), @@ -45,5 +47,5 @@ def test_parser_error(parse_func, input): (getattr(validators, 'validate_password'), 'UserName1'), (getattr(validators, 'validate_telephone'), '67512635') ]) -def test_parser_check(parse_func, input): - assert parse_func(input) == input +def test_validator_check(val_func, input): + assert val_func(input) == input