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_storage.py

39 lines
1.4 KiB
Python
Raw Normal View History

2017-02-15 18:11:16 +00:00
import moto
import pytest
from util.config.validator import ValidatorContext
from util.config.validators import ConfigValidationException
2017-02-15 16:52:08 +00:00
from util.config.validators.validate_storage import StorageValidator
from test.fixtures import *
@pytest.mark.parametrize('unvalidated_config, expected', [
({}, ConfigValidationException),
({'DISTRIBUTED_STORAGE_CONFIG': {}}, ConfigValidationException),
({'DISTRIBUTED_STORAGE_CONFIG': {'local': None}}, ConfigValidationException),
({'DISTRIBUTED_STORAGE_CONFIG': {'local': ['FakeStorage', {}]}}, None),
])
def test_validate_storage(unvalidated_config, expected, app):
validator = StorageValidator()
if expected is not None:
with pytest.raises(expected):
validator.validate(ValidatorContext(unvalidated_config))
else:
validator.validate(ValidatorContext(unvalidated_config))
2017-02-15 18:11:16 +00:00
def test_validate_s3_storage(app):
2017-02-15 18:11:16 +00:00
validator = StorageValidator()
with moto.mock_s3():
with pytest.raises(ConfigValidationException) as ipe:
validator.validate(ValidatorContext({
2017-02-15 18:11:16 +00:00
'DISTRIBUTED_STORAGE_CONFIG': {
'default': ('S3Storage', {
's3_access_key': 'invalid',
's3_secret_key': 'invalid',
's3_bucket': 'somebucket',
'storage_path': ''
}),
}
}))
2017-02-15 18:11:16 +00:00
assert ipe.value.message == 'Invalid storage configuration: default: S3ResponseError: 404 Not Found'