Exemple #1
0
def test_postgres_pgservice_fail() -> None:
 
    url = 'postgres:///?service=not_working&project=france_parts'

    cacheservice = QgsCacheManager()

    with pytest.raises(FileNotFoundError):
        cacheservice.lookup(url)
Exemple #2
0
def test_absolute_path_with_alias() -> None:
    """
    """
    cacheservice = QgsCacheManager()

    # Passing an absolute path that is compatible with
    # the scheme base url is ok
    url = cacheservice.resolve_alias('foo:/foobar/france_parts')
    assert url.scheme == 'file'
    assert url.path   == '/foobar/france_parts'

    # But not a path wich does is no a relative path
    # to base url
    with pytest.raises(PathNotAllowedError):
        url = cacheservice.resolve_alias('foo:/france_parts')
Exemple #3
0
def test_get_modified_time(data) -> None:
    """ Test modified time
    """
    cacheservice = QgsCacheManager()

    path = data / 'france_parts.qgs'
    modified_time1 = cacheservice.get_modified_time('file:france_parts.qgs')
    
    # Check that no files is loaded
    assert cacheservice.peek('file:france_parts.qgs') is None

    # Update file
    path.touch()
    modified_time2 = cacheservice.get_modified_time('file:france_parts.qgs')

    assert modified_time2 > modified_time1
Exemple #4
0
def test_postgres_with_pgservice() -> None:
 
    url = 'postgres:///?service=local&project=france_parts'

    cacheservice = QgsCacheManager()

    details = cacheservice.peek(url)
    assert details is None

    project, updated = cacheservice.lookup(url)
    assert updated
    assert isinstance(project,QgsProject)

    details = cacheservice.peek(url)
    assert details is not None
    assert details.project is project
Exemple #5
0
def test_projects_scheme() -> None:
    """ Tetst file protocol handler
    """
    rootpath = Path(confservice.get('projects.cache','rootdir'))

    cacheservice = QgsCacheManager()
    details = cacheservice.peek('test:france_parts')
    assert details is None

    project, updated = cacheservice.lookup('test:france_parts')
    assert updated
    assert project is not None
    assert project.fileName() == str(rootpath / 'france_parts.qgs')

    details = cacheservice.peek('test:france_parts')
    assert details is not None
    assert details.project is project
Exemple #6
0
def test_postgres_cache() -> None:
    """ Test postgres handler
    """
    cacheservice = QgsCacheManager()

    url = 'postgres:///?project=france_parts'

    details = cacheservice.peek(url)
    assert details is None

    project, updated = cacheservice.lookup(url)
    assert updated
    assert project is not None

    details = cacheservice.peek(url)
    assert details is not None
    assert details.project is project
Exemple #7
0
def test_aliases() -> None:
    """ Test alias resolution for file
    """
    rootpath = Path(confservice.get('projects.cache','rootdir'))

    cacheservice = QgsCacheManager()

    url = cacheservice.resolve_alias('france_parts')
    assert url.scheme == 'file'
    assert url.path   == str(rootpath / 'france_parts')
    
    url = cacheservice.resolve_alias('file:france_parts')
    assert url.scheme == 'file'
    assert url.path   == str(rootpath / 'france_parts')

    url = cacheservice.resolve_alias('foo:france_parts')
    assert url.scheme == 'file'
    assert url.path   == '/foobar/france_parts'

    url = cacheservice.resolve_alias('test:france_parts')
    assert url.scheme == ''
    assert url.path   == str(rootpath / 'france_parts')

    url = cacheservice.resolve_alias('bar:france_parts')
    assert url.scheme == 'file'
    assert url.path   == 'foobar'
    assert url.query  == 'data=france_parts'
Exemple #8
0
def test_preload_projects(data) -> None:
    """ Test preloading projects files
    """
    cacheservice = QgsCacheManager()
    path = data / 'preloads.list'

    loaded = preload_projects_file(path, cacheservice)
    assert loaded == 2

    # file:france_parts.qgs
    # project_simple.qgs
    # raster_layer.qgs (invalid layer)

    details = cacheservice.peek('file:france_parts.qgs')
    assert details is not None

    details = cacheservice.peek('project_simple.qgs')
    assert details is not None

    details = cacheservice.peek('raster_layer.qgs')
    assert details is None
Exemple #9
0
def test_preload_projects(data) -> None:
    """ Test preloading projects files
    """
    cacheservice = QgsCacheManager()
    path = data / 'preloads.list'

    loaded = preload_projects_file(path, cacheservice)
    assert loaded == 2

    # file:france_parts.qgs
    # project_simple.qgs
    # raster_layer.qgs (invalid layer)

    # Ensure  that items are in static cache
    items = list(k for k,_ in cacheservice.items(CacheType.STATIC))
    assert "file:france_parts.qgs" in items
    assert "project_simple.qgs" in items

    details = cacheservice.peek('file:france_parts.qgs')
    assert details is not None

    details = cacheservice.peek('project_simple.qgs')
    assert details is not None

    details = cacheservice.peek('raster_layer.qgs')
    assert details is None
Exemple #10
0
def test_invalid_scheme() -> None:
    """ Test non existant file return error
    """
    cacheservice = QgsCacheManager()
    with pytest.raises(FileNotFoundError):    
        cacheservice.lookup('badscheme:///foo')
Exemple #11
0
def test_file_not_found() -> None:
    """ Test non existant file return error
    """
    cacheservice = QgsCacheManager()
    with pytest.raises(FileNotFoundError):    
        cacheservice.lookup('I_do_not_exists')