def test_get_publication_layman_status(publ_type, error_params):
    workspace = 'test_get_publication_layman_status_workspace'
    publication = 'test_get_publication_layman_status_publication'

    process_client.publish_workspace_publication(publ_type, workspace, publication, check_response_fn=common.empty_method_returns_true,)

    info = process_client.get_workspace_publication(publ_type, workspace, publication,)
    assert 'layman_metadata' in info, f'info={info}'
    assert 'publication_status' in info['layman_metadata'], f'info={info}'
    assert info['layman_metadata']['publication_status'] == 'UPDATING', f'info={info}'

    process_client.wait_for_publication_status(workspace, publ_type, publication)

    info = process_client.get_workspace_publication(publ_type, workspace, publication, )
    assert 'layman_metadata' in info, f'info={info}'
    assert 'publication_status' in info['layman_metadata'], f'info={info}'
    assert info['layman_metadata']['publication_status'] == 'COMPLETE', f'info={info}'

    if error_params:
        process_client.patch_workspace_publication(publ_type, workspace, publication, **error_params, )
        info = process_client.get_workspace_publication(publ_type, workspace, publication, )
        assert 'layman_metadata' in info, f'info={info}'
        assert 'publication_status' in info['layman_metadata'], f'info={info}'
        assert info['layman_metadata']['publication_status'] == 'INCOMPLETE', f'info={info}'

    process_client.delete_workspace_publication(publ_type, workspace, publication)
Example #2
0
def publish_publications_step(publications_set, step_num):
    done_publications = set()
    write_method = process_client.patch_workspace_publication if step_num > 0 else process_client.publish_workspace_publication
    for workspace, publ_type, publication in publications_set:
        data_def = data.PUBLICATIONS[(workspace, publ_type,
                                      publication)][data.DEFINITION]
        params = data_def[step_num]
        write_method(publ_type,
                     workspace,
                     publication,
                     **params,
                     check_response_fn=empty_method_returns_true)
        if len(data_def) == step_num + 1:
            done_publications.add((workspace, publ_type, publication))
    for workspace, publ_type, publication in publications_set:
        params = data.PUBLICATIONS[(workspace, publ_type,
                                    publication)][data.DEFINITION][step_num]
        headers = params.get('headers')
        try:
            process_client.wait_for_publication_status(
                workspace,
                publ_type,
                publication,
                headers=headers,
                check_response_fn=check_publication_status)
        except AssertionError as ex:
            print(
                f"AssertionError in publication {workspace, publ_type, publication}, step_num={step_num}."
            )
            raise ex
    return done_publications
Example #3
0
def assert_map_thumbnail(workspace, map, expected_thumbnail_path):
    process_client.wait_for_publication_status(workspace,
                                               process_client.MAP_TYPE, map)
    with app.app_context():
        thumbnail_path = thumbnail.get_map_thumbnail_path(workspace, map)
    diffs = test_util.compare_images(expected_thumbnail_path, thumbnail_path)
    assert diffs < 10, expected_thumbnail_path
def test_wfs_bbox(style_file, thumbnail_style_postfix):
    workspace = 'test_wfs_bbox_workspace'
    layer = 'test_wfs_bbox_layer'

    process_client.publish_workspace_layer(
        workspace,
        layer,
        style_file=style_file,
    )

    native_crs = SMALL_LAYER_NATIVE_CRS
    assert_util.assert_all_sources_bbox(
        workspace,
        layer,
        SMALL_LAYER_BBOX,
        expected_native_bbox=SMALL_LAYER_NATIVE_BBOX,
        expected_native_crs=native_crs)

    expected_bbox = (1571000.0, 6268800.0, 1572590.854206196, 6269876.33561699)
    exp_native_bbox = (14.112533113517683, 48.964264493114904, 14.126824,
                       48.970612)
    method_bbox_thumbnail_tuples = [
        (data_wfs.get_wfs20_insert_points, expected_bbox, exp_native_bbox,
         '_bigger'),
        (data_wfs.get_wfs20_delete_point, SMALL_LAYER_BBOX,
         SMALL_LAYER_NATIVE_BBOX, ''),
    ]

    for wfs_method, exp_bbox, exp_native_bbox, thumbnail_bbox_postfix in method_bbox_thumbnail_tuples:
        data_xml = wfs_method(
            workspace,
            layer,
        )

        process_client.post_wfst(data_xml, workspace=workspace)
        process_client.wait_for_publication_status(workspace,
                                                   process_client.LAYER_TYPE,
                                                   layer)

        assert_util.assert_all_sources_bbox(
            workspace,
            layer,
            exp_bbox,
            expected_native_bbox=exp_native_bbox,
            expected_native_crs=native_crs)

        expected_thumbnail_path = f'/code/sample/style/{layer}{thumbnail_style_postfix}{thumbnail_bbox_postfix}.png'
        with app.app_context():
            thumbnail_path = thumbnail.get_layer_thumbnail_path(
                workspace, layer)
        diffs = test_util.compare_images(expected_thumbnail_path,
                                         thumbnail_path)
        assert diffs < 100, expected_thumbnail_path

    process_client.delete_workspace_layer(
        workspace,
        layer,
    )
Example #5
0
def test_map_refresh_after_layer_change():
    workspace = 'test_map_refresh_after_layer_change_workspace'
    layer = 'test_map_refresh_after_layer_change_layer'
    map = 'test_map_refresh_after_layer_change_map'
    bbox = (1571000.0, 6268800.0, 1572590.8542062, 6269876.33561699)

    process_client.publish_workspace_layer(workspace, layer)

    file_path = f'tmp/map_with_internal_layers.json'
    map_data.create_map_with_internal_layers_file([(workspace, layer)],
                                                  file_path=file_path,
                                                  native_extent=bbox,
                                                  native_crs='EPSG:3857')
    process_client.publish_workspace_map(workspace,
                                         map,
                                         file_paths=[file_path])

    assert_map_thumbnail(
        workspace, map,
        f'/code/test_tools/data/thumbnail/map_with_internal_layer_basic.png')

    # Test refresh map thumbnail after layer WFS-T query
    data_xml = data_wfs.get_wfs20_insert_points(
        workspace,
        layer,
    )
    process_client.post_wfst(data_xml)
    process_client.wait_for_publication_status(workspace,
                                               process_client.LAYER_TYPE,
                                               layer)
    assert_map_thumbnail(
        workspace, map,
        f'/code/test_tools/data/thumbnail/map_with_internal_layer_basic_after_wfst.png'
    )

    # Test refresh map thumbnail after patch layer
    process_client.patch_workspace_layer(
        workspace,
        layer,
        file_paths=['sample/layman.layer/small_layer.geojson'])
    process_client.wait_for_publication_status(workspace,
                                               process_client.LAYER_TYPE,
                                               layer)
    assert_map_thumbnail(
        workspace, map,
        f'/code/test_tools/data/thumbnail/map_with_internal_layer_basic.png')

    process_client.delete_workspace_map(workspace, map)
    process_client.delete_workspace_layer(workspace, layer)
Example #6
0
def test_post_layers_chunk(browser):
    relative_file_paths = [
        'tmp/naturalearth/10m/cultural/ne_10m_admin_0_countries.geojson',
    ]
    file_paths = [os.path.join(os.getcwd(), fp) for fp in relative_file_paths]

    for file_path in file_paths:
        assert os.path.isfile(file_path)

    client_url = settings.LAYMAN_CLIENT_URL

    response = requests.get(client_url)
    assert response.status_code == 200

    browser.get(client_url)
    browser.set_window_size(1000, 2000)
    browser.save_screenshot('/code/tmp/artifacts/client-post-layers-1.png')

    button = browser.find_elements_by_xpath('//button[text()="POST"]')
    assert len(button) == 1
    button = button[0]
    button.click()
    browser.save_screenshot('/code/tmp/artifacts/client-post-layers-1.5.png')

    user_input = browser.find_elements_by_name('Workspace')
    assert len(user_input) == 1
    user_input = user_input[0]
    user_input.clear()
    user_input.send_keys(WORKSPACE)

    layername_input = browser.find_elements_by_name('name')
    assert len(layername_input) == 1
    layername_input = layername_input[0]
    layername_input.clear()
    layername_input.send_keys(LAYERNAME)

    file_input = browser.find_elements_by_name('file')
    assert len(file_input) == 1
    file_input = file_input[0]
    for file_path in file_paths:
        file_input.send_keys(file_path)
    browser.save_screenshot('/code/tmp/artifacts/client-post-layers-2.png')

    button = browser.find_elements_by_xpath('//button[@type="submit"]')
    assert len(button) == 1
    button = button[0]
    button.click()

    try:
        process_client.wait_for_publication_status(WORKSPACE,
                                                   process_client.LAYER_TYPE,
                                                   LAYERNAME)
    except Exception as exc:
        browser.save_screenshot(
            '/code/tmp/artifacts/client-post-layers-2.5.png')
        raise exc
    browser.save_screenshot('/code/tmp/artifacts/client-post-layers-3.png')

    positive_response = browser.find_elements_by_xpath(
        '//div[@class="ui positive message"]')
    assert positive_response

    resp_msg_div = browser.find_elements_by_css_selector(
        'div.ui.container > div:nth-child(8) > div.ui.segment > div.ui.positive.message > code'
    )
    assert len(resp_msg_div) == 1
    resp_msg_div = resp_msg_div[0]
    resp_json = json.loads(resp_msg_div.text)
    assert resp_json[0]['name'] == LAYERNAME

    total_chunks_key = input_chunk.get_layer_redis_total_chunks_key(
        WORKSPACE, LAYERNAME)
    assert not settings.LAYMAN_REDIS.exists(total_chunks_key)
def test_patch_after_feature_change_concurrency(publication_type):
    workspace = 'test_wfst_concurrency_workspace'
    publication = 'test_wfst_concurrency_layer'

    process_client.publish_workspace_publication(
        publication_type,
        workspace,
        publication,
    )

    queue = celery.get_run_after_chain_queue(workspace, publication_type,
                                             publication)
    assert not queue
    lock = redis.get_publication_lock(workspace, publication_type, publication)
    assert not lock

    process_client.patch_after_feature_change(workspace, publication_type,
                                              publication)
    queue = celery.get_run_after_chain_queue(workspace, publication_type,
                                             publication)
    assert len(queue) == 0, queue
    lock = redis.get_publication_lock(workspace, publication_type, publication)
    assert lock == common_const.PUBLICATION_LOCK_FEATURE_CHANGE

    process_client.patch_workspace_publication(
        publication_type,
        workspace,
        publication,
        title='New title',
        check_response_fn=empty_method_returns_true)
    queue = celery.get_run_after_chain_queue(workspace, publication_type,
                                             publication)
    assert len(queue) == 0, queue
    lock = redis.get_publication_lock(workspace, publication_type, publication)
    assert lock == common_const.PUBLICATION_LOCK_FEATURE_CHANGE

    process_client.patch_after_feature_change(workspace, publication_type,
                                              publication)
    queue = celery.get_run_after_chain_queue(workspace, publication_type,
                                             publication)
    assert len(queue) == 1, queue
    assert queue == [
        'layman.util::patch_after_feature_change',
    ]
    lock = redis.get_publication_lock(workspace, publication_type, publication)
    assert lock == common_const.PUBLICATION_LOCK_FEATURE_CHANGE

    process_client.patch_after_feature_change(workspace, publication_type,
                                              publication)
    queue = celery.get_run_after_chain_queue(workspace, publication_type,
                                             publication)
    assert len(queue) == 1, queue
    assert queue == [
        'layman.util::patch_after_feature_change',
    ]
    lock = redis.get_publication_lock(workspace, publication_type, publication)
    assert lock == common_const.PUBLICATION_LOCK_FEATURE_CHANGE

    process_client.wait_for_publication_status(workspace, publication_type,
                                               publication)
    queue = celery.get_run_after_chain_queue(workspace, publication_type,
                                             publication)
    assert not queue, queue
    lock = redis.get_publication_lock(workspace, publication_type, publication)
    assert not lock

    process_client.delete_workspace_publication(
        publication_type,
        workspace,
        publication,
    )

    queue = celery.get_run_after_chain_queue(workspace, publication_type,
                                             publication)
    assert not queue, queue
    lock = redis.get_publication_lock(workspace, publication_type, publication)
    assert not lock