From 8d023ed8dd0568f7bc7be5d1b4bed843883a5731 Mon Sep 17 00:00:00 2001 From: index-git Date: Tue, 17 Dec 2024 12:22:19 +0100 Subject: [PATCH] PATCH Workspace Layer returns only short response --- CHANGELOG.md | 1 + doc/rest.md | 3 +-- src/layman/layer/__init__.py | 5 +++++ src/layman/layer/rest_workspace_layer.py | 9 ++++++--- src/layman/layer/rest_workspace_test.py | 14 +++++++------- test_tools/process_client.py | 6 ++++++ 6 files changed, 26 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04c499d90..a18f56aa2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ #### Schema migrations #### Data migrations ### Changes +- [#1009](https://github.com/LayerManager/layman/issues/1009) [PATCH Workspace Layer](doc/rest.md#patch-workspace-layer) returns same response as [POST Workspace Layers](doc/rest.md#post-workspace-layers) with only `name`, `uuid`, `url` and optional `files_to_upload` keys. - [#1028](https://github.com/LayerManager/layman/issues/1028) Upgrade Node.js of Laymen Test Client from v18 to v22 and dependencies: - eslint-config-next 13 -> 14 - next 13 -> 14 diff --git a/doc/rest.md b/doc/rest.md index 185ae8641..e20b75500 100644 --- a/doc/rest.md +++ b/doc/rest.md @@ -429,8 +429,7 @@ Body parameters: #### Response Content-Type: `application/json` -JSON object, same as in case of [GET Workspace Layer](#get-workspace-layer), possibly extended with one extra property: -- *files_to_upload*: List of objects. It's present only if **file** parameter contained file names. See [POST Workspace Layers](#post-workspace-layers) response to find out more. +JSON object, same as in case of [POST Workspace Layer](#post-workspace-layers). ### DELETE Workspace Layer Delete existing layer and all associated sources except external DB table published using `external_table_uri`. So it deletes e.g. data file, vector internal DB table or normalized raster file. The currently running [asynchronous tasks](async-tasks.md) of affected layer are aborted. diff --git a/src/layman/layer/__init__.py b/src/layman/layer/__init__.py index 9b86c9e5b..81ff51807 100644 --- a/src/layman/layer/__init__.py +++ b/src/layman/layer/__init__.py @@ -29,6 +29,10 @@ def get_layer_info_keys(*, geodata_type, original_data_source): return result +def get_layer_patch_keys(): + return get_layer_type_def()['patch_keys'] + + LAYER_REST_PATH_NAME = "layers" @@ -131,6 +135,7 @@ def get_layer_info_keys(*, geodata_type, original_data_source): }, }, 'multi_info_keys_to_remove': [], + 'patch_keys': ['name', 'uuid', 'url', 'files_to_upload'], } } diff --git a/src/layman/layer/rest_workspace_layer.py b/src/layman/layer/rest_workspace_layer.py index 5f1c0e49e..7903e14d3 100644 --- a/src/layman/layer/rest_workspace_layer.py +++ b/src/layman/layer/rest_workspace_layer.py @@ -6,11 +6,11 @@ from layman.common import rest as rest_util from layman.common.prime_db_schema import publications from layman.http import LaymanError -from layman.util import check_workspace_name_decorator +from layman.util import check_workspace_name_decorator, url_for from layman import settings, authn, util as layman_util from layman.authn import authenticate from layman.authz import authorize_workspace_publications_decorator -from . import util, LAYER_REST_PATH_NAME, LAYER_TYPE +from . import util, LAYER_REST_PATH_NAME, LAYER_TYPE, get_layer_patch_keys from .filesystem import input_file, input_style, input_chunk, util as fs_util bp = Blueprint('rest_workspace_layer', __name__) @@ -262,8 +262,11 @@ def patch(workspace, layername): ) app.logger.info('PATCH Layer changes done') - info = util.get_complete_layer_info(workspace, layername, x_forwarded_items=x_forwarded_items) + patch_keys = get_layer_patch_keys() + info = util.get_layer_info(workspace, layername, context={'keys': patch_keys, 'x_forwarded_items': x_forwarded_items}) + info['url'] = layman_util.get_workspace_publication_url(info['type'], workspace, layername, x_forwarded_items=x_forwarded_items), info.update(layer_result) + info = {key: value for key, value in info.items() if key in patch_keys} return jsonify(info), 200 diff --git a/src/layman/layer/rest_workspace_test.py b/src/layman/layer/rest_workspace_test.py index a18eece0b..67fea686a 100644 --- a/src/layman/layer/rest_workspace_test.py +++ b/src/layman/layer/rest_workspace_test.py @@ -657,9 +657,9 @@ def test_patch_layer_title(client): chain_info = util.get_layer_chain(workspace, layername) assert chain_info is not None and celery_util.is_chain_ready(chain_info) - resp_json = response.get_json() - assert resp_json['title'] == new_title - assert resp_json['description'] == new_description + get_json = client.get(rest_path).get_json() + assert get_json['title'] == new_title + assert get_json['description'] == new_description with app.app_context(): expected_md_values = { @@ -716,8 +716,8 @@ def test_patch_layer_style(client): flask_client.wait_till_layer_ready(workspace, layername) # last_task['last'].get() - resp_json = response.get_json() - assert resp_json['title'] == "countries in blue" + get_json = client.get(rest_path).get_json() + assert get_json['title'] == "countries in blue" wms_url = geoserver_wms.get_wms_url(workspace) wms = wms_proxy(wms_url) @@ -772,10 +772,10 @@ def test_patch_layer_data(client): chain_info = util.get_layer_chain(workspace, layername) assert chain_info is not None and not celery_util.is_chain_ready(chain_info) - resp_json = response.get_json() + get_json = client.get(rest_path).get_json() keys_to_check = ['db', 'wms', 'wfs', 'thumbnail', 'metadata'] for key_to_check in keys_to_check: - assert 'status' in resp_json[key_to_check] + assert 'status' in get_json[key_to_check] flask_client.wait_till_layer_ready(workspace, layername) # last_task['last'].get() diff --git a/test_tools/process_client.py b/test_tools/process_client.py index bb40b515a..94e5c34ee 100644 --- a/test_tools/process_client.py +++ b/test_tools/process_client.py @@ -296,6 +296,12 @@ def patch_workspace_publication(publication_type, ) raise_layman_error(response) + assert response.json()['name'] == name or not name, f'name={name}, response.name={response.json()[0]["name"]}' + expected_resp_keys = ['name', 'uuid', 'url'] + if with_chunks: + expected_resp_keys.append('files_to_upload') + assert all(key in response.json() for key in expected_resp_keys), f'name={name}, response.name={response.json()[0]["name"]}' + if with_chunks and not do_not_upload_chunks: upload_file_chunks(publication_type, workspace,