Skip to content

Commit

Permalink
PATCH Workspace Layer returns only short response
Browse files Browse the repository at this point in the history
  • Loading branch information
index-git committed Dec 18, 2024
1 parent b76787d commit 8d023ed
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions doc/rest.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions src/layman/layer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down Expand Up @@ -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'],
}
}

Expand Down
9 changes: 6 additions & 3 deletions src/layman/layer/rest_workspace_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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

Expand Down
14 changes: 7 additions & 7 deletions src/layman/layer/rest_workspace_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()

Expand Down
6 changes: 6 additions & 0 deletions test_tools/process_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8d023ed

Please sign in to comment.