Ejemplo n.º 1
0
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'})
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
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',
                            {})
Ejemplo n.º 6
0
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', {})
Ejemplo n.º 7
0
def test_storage_fetched_from_factory():
    storage = get_storage('azure_blobs', {"container_name": "my-container", "connection_string": FAKE_CONN_STRING})
    assert isinstance(storage, AzureBlobStorage)