Skip to content

Commit

Permalink
Use wait_for_publication_status if waiting for asynchronous tasks end
Browse files Browse the repository at this point in the history
  • Loading branch information
index-git committed May 14, 2021
1 parent 6f7ccfd commit f0b9e3c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 38 deletions.
16 changes: 4 additions & 12 deletions src/layman/rest_publication_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from test import process_client, util
from functools import partial
from test import process_client
import pytest

from layman import LaymanError, settings, common, app
from layman import LaymanError, settings, common
from layman.common.micka import util as micka_util

db_schema = settings.LAYMAN_PRIME_SCHEMA
Expand Down Expand Up @@ -126,22 +125,15 @@ def test_get_publication_layman_status(publ_type, error_params):
assert 'publication_status' in info['layman_metadata'], f'info={info}'
assert info['layman_metadata']['publication_status'] == 'UPDATING', f'info={info}'

publication_type_def = process_client.PUBLICATION_TYPES_DEF[publ_type]
with app.app_context():
url = util.url_for(publication_type_def.get_workspace_publication_url,
workspace=workspace,
**{publication_type_def.url_param_name: publication})
check_response_fn = partial(process_client.check_response_keys, publication_type_def.keys_to_check)
process_client.wait_for_rest(url, 30, 0.5, check_response_fn)
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:
check_response_fail = partial(process_client.wait_for_failure, publication_type_def.keys_to_check)
process_client.patch_workspace_publication(publ_type, workspace, publication, **error_params, check_response_fn=check_response_fail, )
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}'
Expand Down
28 changes: 2 additions & 26 deletions test/process_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,6 @@
}


def check_response_keys(keys_to_check, response):
if any(response.json()[k].get('status') == 'FAILURE' for k in keys_to_check):
error_keys = [k for k in keys_to_check if response.json()[k].get('status') == 'FAILURE']
logger.error(f"failed_keys={error_keys}")
raise Exception('Some step failed!')
return response.status_code == 200 and all(
'status' not in response.json()[k] for k in keys_to_check
)


def wait_for_failure(keys_to_check, response):
return any(response.json()[k].get('status') == 'FAILURE' for k in keys_to_check)


def wait_for_rest(url, max_attempts, sleeping_time, check_response, headers=None):
headers = headers or None
r = requests.get(url, headers=headers, timeout=5)
Expand Down Expand Up @@ -130,7 +116,6 @@ def patch_workspace_publication(publication_type,
headers = headers or {}
file_paths = file_paths or []
publication_type_def = PUBLICATION_TYPES_DEF[publication_type]
check_response_fn = check_response_fn or partial(check_response_keys, publication_type_def.keys_to_check)
if style_file:
assert publication_type == LAYER_TYPE

Expand Down Expand Up @@ -163,11 +148,7 @@ def patch_workspace_publication(publication_type,
for fp in files:
fp[1][1].close()

with app.app_context():
url = url_for(publication_type_def.get_workspace_publication_url,
workspace=workspace,
**{publication_type_def.url_param_name: name})
wait_for_rest(url, 30, 0.5, check_response_fn, headers=headers)
wait_for_publication_status(workspace, publication_type, name, check_response_fn=check_response_fn, headers=headers)
wfs.clear_cache(workspace)
wms.clear_cache(workspace)
return r.json()
Expand Down Expand Up @@ -224,7 +205,6 @@ def publish_workspace_publication(publication_type,
headers = headers or {}
publication_type_def = PUBLICATION_TYPES_DEF[publication_type]
file_paths = file_paths or [publication_type_def.source_path, ]
check_response_fn = check_response_fn or partial(check_response_keys, publication_type_def.keys_to_check)
if style_file:
assert publication_type == LAYER_TYPE

Expand Down Expand Up @@ -258,11 +238,7 @@ def publish_workspace_publication(publication_type,
for fp in files:
fp[1][1].close()

with app.app_context():
url = url_for(publication_type_def.get_workspace_publication_url,
workspace=workspace,
**{publication_type_def.url_param_name: name})
wait_for_rest(url, 30, 0.5, check_response_fn, headers=headers)
wait_for_publication_status(workspace, publication_type, name, check_response_fn=check_response_fn, headers=headers)
return r.json()[0]


Expand Down

0 comments on commit f0b9e3c

Please sign in to comment.