2017-02-15 18:11:16 +00:00
|
|
|
import moto
|
2017-01-31 20:56:25 +00:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from util.config.validators import ConfigValidationException
|
2017-02-15 16:52:08 +00:00
|
|
|
from util.config.validators.validate_storage import StorageValidator
|
2017-01-31 20:56:25 +00:00
|
|
|
|
2017-04-24 18:52:30 +00:00
|
|
|
from test.fixtures import *
|
|
|
|
|
2017-01-31 20:56:25 +00:00
|
|
|
@pytest.mark.parametrize('unvalidated_config, expected', [
|
|
|
|
({}, ConfigValidationException),
|
|
|
|
({'DISTRIBUTED_STORAGE_CONFIG': {}}, ConfigValidationException),
|
|
|
|
({'DISTRIBUTED_STORAGE_CONFIG': {'local': None}}, ConfigValidationException),
|
|
|
|
({'DISTRIBUTED_STORAGE_CONFIG': {'local': ['FakeStorage', {}]}}, None),
|
|
|
|
])
|
2017-04-24 18:52:30 +00:00
|
|
|
def test_validate_storage(unvalidated_config, expected, app):
|
2017-01-31 20:56:25 +00:00
|
|
|
validator = StorageValidator()
|
|
|
|
if expected is not None:
|
|
|
|
with pytest.raises(expected):
|
|
|
|
validator.validate(unvalidated_config, None, None)
|
|
|
|
else:
|
|
|
|
validator.validate(unvalidated_config, None, None)
|
2017-02-15 18:11:16 +00:00
|
|
|
|
2017-04-24 18:52:30 +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({
|
|
|
|
'DISTRIBUTED_STORAGE_CONFIG': {
|
|
|
|
'default': ('S3Storage', {
|
|
|
|
's3_access_key': 'invalid',
|
|
|
|
's3_secret_key': 'invalid',
|
|
|
|
's3_bucket': 'somebucket',
|
|
|
|
'storage_path': ''
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
}, None, None)
|
|
|
|
|
|
|
|
assert ipe.value.message == 'Invalid storage configuration: default: S3ResponseError: 404 Not Found'
|