This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/util/config/validators/test/test_validate_database.py
2017-02-24 12:23:16 -05:00

21 lines
863 B
Python

import pytest
from util.config.validators import ConfigValidationException
from util.config.validators.validate_database import DatabaseValidator
@pytest.mark.parametrize('unvalidated_config,user,user_password,expected', [
(None, None, None, TypeError),
({}, None, None, KeyError),
({'DB_URI': 'sqlite:///:memory:'}, None, None, None),
({'DB_URI': 'invalid:///:memory:'}, None, None, KeyError),
({'DB_NOTURI': 'sqlite:///:memory:'}, None, None, KeyError),
({'DB_URI': 'mysql:///someinvalid'}, None, None, ConfigValidationException),
])
def test_validate_database(unvalidated_config, user, user_password, expected):
validator = DatabaseValidator()
if expected is not None:
with pytest.raises(expected):
validator.validate(unvalidated_config, user, user_password)
else:
validator.validate(unvalidated_config, user, user_password)