def test_get_backend_invalid_custom_name(): """Test that loading backend fails with specific error if name is invalid """ with pytest.raises(ValueError): storage.get_storage('ckanext.asset_storage.storage.local.LocalStorage', {'storage_path': '/tmp'}) with pytest.raises(ValueError): storage.get_storage('ckanext.asset_storage.storage:local:LocalStorage', {'storage_path': '/tmp'})
def test_get_backend_with_custom_backend(): """Test that loading a custom storage backend works """ backend = storage.get_storage( 'ckanext.asset_storage.storage.local:LocalStorage', {'storage_path': '/tmp'}) assert isinstance(backend, LocalStorage)
def get_configured_storage(): # type: () -> StorageBackend backend_type = toolkit.config.get(CONF_BACKEND_TYPE) config = toolkit.config.get(CONF_BACKEND_CONFIG, {}) if not backend_type: backend_type = 'local' if backend_type == 'local' and not config: config = {'storage_path': toolkit.config.get('ckan.storage_path')} return get_storage(backend_type=backend_type, backend_config=config)
def test_get_backend_with_named_backend(): """Test that loading a named storage backend works """ backend = storage.get_storage('local', {'storage_path': '/tmp'}) assert isinstance(backend, LocalStorage)
def test_get_backend_nonexisting_callable(): """Test that loading backend fails with specific error if callable is unknown """ with pytest.raises(ValueError): storage.get_storage('ckanext.asset_storage:storage:SomeMadeUpStorage', {})
def test_get_backend_nonexisting_module(): """Test that loading backend fails with specific error if backend module is unknown """ with pytest.raises(ValueError): storage.get_storage( 'ckanext.asset_storage.storage.madeupstorage:Storage', {})
def test_storage_fetched_from_factory(): storage = get_storage('azure_blobs', {"container_name": "my-container", "connection_string": FAKE_CONN_STRING}) assert isinstance(storage, AzureBlobStorage)