7df8ed4a60
Change SecScanAPI to use a uri creation func instead of test context Pass config provider through validator context Remove app config dependency for validators
34 lines
1.3 KiB
Python
34 lines
1.3 KiB
Python
import pytest
|
|
import redis
|
|
|
|
from mock import patch
|
|
|
|
from mockredis import mock_strict_redis_client
|
|
|
|
from util.config.validator import ValidatorContext
|
|
from util.config.validators import ConfigValidationException
|
|
from util.config.validators.validate_redis import RedisValidator
|
|
|
|
from test.fixtures import *
|
|
from util.morecollections import AttrDict
|
|
|
|
|
|
@pytest.mark.parametrize('unvalidated_config,user,user_password,use_mock,expected', [
|
|
({}, None, None, False, ConfigValidationException),
|
|
({'BUILDLOGS_REDIS': {}}, None, None, False, ConfigValidationException),
|
|
({'BUILDLOGS_REDIS': {'host': 'somehost'}}, None, None, False, redis.ConnectionError),
|
|
({'BUILDLOGS_REDIS': {'host': 'localhost'}}, None, None, True, None),
|
|
])
|
|
def test_validate_redis(unvalidated_config, user, user_password, use_mock, expected, app):
|
|
with patch('redis.StrictRedis' if use_mock else 'redis.None', mock_strict_redis_client):
|
|
validator = RedisValidator()
|
|
unvalidated_config = ValidatorContext(unvalidated_config)
|
|
|
|
unvalidated_config.user = AttrDict(dict(username=user))
|
|
unvalidated_config.user_password = user_password
|
|
|
|
if expected is not None:
|
|
with pytest.raises(expected):
|
|
validator.validate(unvalidated_config)
|
|
else:
|
|
validator.validate(unvalidated_config)
|