Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test info #428

Merged
merged 5 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/layman/geoserver_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from geoserver.util import reset as gs_reset
from layman import authn, authz, settings, util as layman_util
from layman.authn import authenticate, is_user_with_name
from layman.layer import db, LAYER_TYPE, util as layer_util
from layman.layer import db, LAYER_TYPE
from layman.layer.qgis import wms as qgis_wms
from layman.layer.util import LAYERNAME_PATTERN, ATTRNAME_PATTERN, patch_after_feature_change
from layman.util import USERNAME_ONLY_PATTERN
Expand Down Expand Up @@ -67,7 +67,7 @@ def ensure_wfs_t_attributes(attribs):
if created_attributes:
changed_layers = {(workspace, layer) for workspace, layer, _ in created_attributes}
qgis_changed_layers = {(workspace, layer) for workspace, layer in changed_layers
if layer_util.get_layer_info(workspace, layer, context={'keys': ['style_type'], })['style_type'] == 'qml'}
if layman_util.get_publication_info(workspace, LAYER_TYPE, layer, context={'keys': ['style_type'], })['style_type'] == 'qml'}
for workspace, layer in qgis_changed_layers:
qgis_wms.save_qgs_file(workspace, layer)
gs_reset(settings.LAYMAN_GS_AUTH)
Expand Down
6 changes: 3 additions & 3 deletions src/layman/geoserver_proxy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import pytest

from geoserver.error import Error as GS_Error
from layman import app, settings
from layman.layer import db, util as layer_util
from layman import app, settings, util as layman_util
from layman.layer import db
from layman.layer.filesystem import thumbnail
from layman.layer.geoserver import wfs as geoserver_wfs
from layman.layer.qgis import util as qgis_util, wms as qgis_wms
Expand Down Expand Up @@ -112,7 +112,7 @@ def test_missing_attribute(style_file, ):
)

with app.app_context():
style_type = layer_util.get_layer_info(username, layername, context={'keys': ['style_type'], })['style_type']
style_type = layman_util.get_publication_info(username, process_client.LAYER_TYPE, layername, context={'keys': ['style_type'], })['style_type']

def wfs_post(workspace, attr_names_list, data_xml):
with app.app_context():
Expand Down
8 changes: 6 additions & 2 deletions src/layman/layer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,12 @@ def get_layer_info_keys(file_type):
'wms_url',
}
},
'info_keys': {settings.FILE_TYPE_VECTOR: ['wms', 'wfs', 'thumbnail', 'file', 'db_table', 'metadata', 'style', ],
settings.FILE_TYPE_RASTER: ['wms', 'thumbnail', 'file', 'metadata', 'style', ],
'info_keys': {settings.FILE_TYPE_VECTOR: {'name', 'uuid', 'layman_metadata', 'url', 'title', 'description', 'updated_at',
'wms', 'wfs', 'thumbnail', 'file', 'db_table', 'metadata', 'style', 'sld',
'access_rights', 'bounding_box', },
settings.FILE_TYPE_RASTER: {'name', 'uuid', 'layman_metadata', 'url', 'title', 'description', 'updated_at',
'wms', 'thumbnail', 'file', 'metadata', 'style', 'sld', 'access_rights',
'bounding_box', },
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/layman/layer/filesystem/gdal.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def get_layer_info(workspace, layer):
gdal_gs_path = get_normalized_raster_layer_main_filepath(workspace, layer, geoserver=True)
if os.path.exists(gdal_path):
return {
'layername': layer,
'name': layer,
'_file': {
'normalized_file': {
'path': gdal_path,
Expand Down
4 changes: 2 additions & 2 deletions src/layman/layer/geoserver/wms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from layman.cache import mem_redis
from layman.common import geoserver as gs_common, empty_method_returns_none, empty_method
from layman.layer.util import is_layer_chain_ready
from layman.layer import LAYER_TYPE, util as layer_util
from layman.layer import LAYER_TYPE
from .util import get_gs_proxy_base_url

FLASK_PROXY_KEY = f'{__name__}:PROXY:{{username}}'
Expand All @@ -29,7 +29,7 @@ def get_flask_proxy_key(username):

def patch_layer(workspace, layername, title, description, access_rights=None):
geoserver_workspace = get_geoserver_workspace(workspace)
info = layer_util.get_layer_info(workspace, layername, context={'keys': ['style_type'], })
info = layman_util.get_publication_info(workspace, LAYER_TYPE, layername, context={'keys': ['style_type'], })
if info['style_type'] == 'sld':
gs_util.patch_feature_type(geoserver_workspace, layername, title=title, description=description, auth=settings.LAYMAN_GS_AUTH)
clear_cache(workspace)
Expand Down
4 changes: 2 additions & 2 deletions src/layman/layer/rest_workspace_layers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

del sys.modules['layman']

from layman import app, settings, LaymanError
from layman import app, settings, LaymanError, util as layman_util
from layman.layer import util as layer_util
from layman.layer.filesystem import input_style
from test_tools import process_client, util as test_util
Expand Down Expand Up @@ -68,7 +68,7 @@ def test_style_correctly_saved(source_style_file_path,
style_file=source_style_file_path)
assert_style_file(workspace, layer, expected_style_file)
with app.app_context():
info = layer_util.get_layer_info(workspace, layer, context={'keys': ['style_type', 'style'], })
info = layman_util.get_publication_info(workspace, process_client.LAYER_TYPE, layer, context={'keys': ['style_type', 'style'], })
assert info['style_type'] == expected_style_type

process_client.delete_workspace_layer(workspace, layer)
Expand Down
2 changes: 1 addition & 1 deletion src/layman/layer/rest_workspace_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ def wait_for_db_finish(response):

process_client.publish_workspace_layer(workspace, layername, file_paths=file_paths, check_response_fn=wait_for_db_finish)

layer_info = util.get_layer_info(workspace, layername, context={'keys': ['db_table']})
layer_info = util.get_layer_info(workspace, layername)
assert layer_info['db_table']['status'] == 'FAILURE', f'layer_info={layer_info}'
assert layer_info['db_table']['error']['code'] == 28, f'layer_info={layer_info}'

Expand Down
24 changes: 14 additions & 10 deletions src/layman/layer/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ def get_layer_info(workspace, layername, context=None):
if chain_info is None or celery_util.is_chain_successful(chain_info):
return partial_info

file_type = partial_info['file']['file_type']
item_keys = get_layer_info_keys(file_type)

failed = False
for res in chain_info['by_order']:
task_name = next(k for k, v in chain_info['by_name'].items() if v == res)
Expand All @@ -98,7 +101,8 @@ def get_layer_info(workspace, layername, context=None):
continue
for layerinfo_key in TASKS_TO_LAYER_INFO_KEYS[task_name]:
if layerinfo_key not in partial_info:
partial_info[layerinfo_key] = source_state
if layerinfo_key in item_keys:
partial_info[layerinfo_key] = source_state
elif not res.successful():
partial_info[layerinfo_key].update(source_state)

Expand All @@ -117,24 +121,24 @@ def get_complete_layer_info(username=None, layername=None, cached=False):
file_type = partial_info['file']['file_type']
item_keys = get_layer_info_keys(file_type)

complete_info = {
complete_info = dict()
for key in item_keys:
complete_info[key] = {'status': 'NOT_AVAILABLE'}

complete_info.update({
'name': layername,
'url': url_for('rest_workspace_layer.get', layername=layername, workspace=username),
'title': layername,
'description': '',
}

for key in item_keys:
complete_info[key] = {'status': 'NOT_AVAILABLE'}
})

complete_info.update(partial_info)
complete_info['sld'] = complete_info['style']
complete_info = clear_publication_info(complete_info)

complete_info.pop('layman_metadata')
complete_info['layman_metadata'] = {'publication_status': layman_util.get_publication_status(username, LAYER_TYPE, layername,
complete_info, item_keys)}

complete_info = clear_publication_info(complete_info)

complete_info['sld'] = complete_info['style']
return complete_info


Expand Down
2 changes: 1 addition & 1 deletion src/layman/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ def get_publication_status(workspace, publication_type, publication_name, comple

if (chain_info and not celery_util.is_chain_ready(chain_info)) or current_lock:
publication_status = 'UPDATING'
elif any(complete_info.get(v, dict()).get('status') for v in item_keys):
elif any(complete_info.get(v, dict()).get('status') for v in item_keys if isinstance(complete_info.get(v, dict()), dict)):
publication_status = 'INCOMPLETE'
else:
publication_status = 'COMPLETE'
Expand Down
18 changes: 7 additions & 11 deletions tests/static_publications/single_publication/layers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from layman import settings, app, util as layman_util
from layman.common import bbox as bbox_util, geoserver as gs_common
from layman.common.micka import util as micka_common_util
from layman.layer import util as layer_util, db as layer_db
from layman.layer import util as layer_util, db as layer_db, get_layer_info_keys
from layman.layer.geoserver.wms import DEFAULT_WMS_QGIS_STORE_PREFIX, VERSION
from layman.layer.micka import csw
from layman.layer.qgis import util as qgis_util
Expand Down Expand Up @@ -42,19 +42,15 @@ def test_info(workspace, publ_type, publication):
expected_style_url = url_for('rest_workspace_layer_style.get', workspace=workspace, layername=publication,
internal=False)

file_type = info_internal['file']['file_type']
item_keys = get_layer_info_keys(file_type)

assert set(info.keys()) == item_keys, f'info={info}'
assert info['wms'].get('url') == wms_url, f'r_json={info}, wms_url={wms_url}'
assert 'wms' in info, f'info={info}'
assert 'url' in info['wms'], f'info={info}'

if data.PUBLICATIONS[(workspace, publ_type, publication)][data.TEST_DATA].get('file_type') == settings.FILE_TYPE_VECTOR:
assert info.get('file', dict()).get('file_type') == settings.FILE_TYPE_VECTOR, info
assert 'wfs' in info, f'info={info}'
assert 'url' in info['wms'], f'info={info}'
assert info.get('file', dict()).get('file_type') == data.PUBLICATIONS[(workspace, publ_type, publication)][data.TEST_DATA].get('file_type')
if 'wfs' in info:
assert info['wfs'].get('url') == wfs_url, f'r_json={info}, wfs_url={wfs_url}'
elif data.PUBLICATIONS[(workspace, publ_type, publication)][data.TEST_DATA].get('file_type') == settings.FILE_TYPE_RASTER:
assert info.get('file', dict()).get('file_type') == settings.FILE_TYPE_RASTER, info
assert 'wfs' not in info, f'info={info}'
assert 'db_table' not in info, f'info={info}'

assert info_internal['style_type'] == style, f'info_internal={info_internal}'
assert info['style']['type'] == style, info.get('style')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ def test_info(workspace, publ_type, publication):
with app.app_context():
info = process_client.get_workspace_publication(publ_type, workspace, publication, headers)

assert 'layman_metadata' in info, f'info={info}'
assert info['layman_metadata']['publication_status'] == 'COMPLETE', f'info={info}'

# Items
assert {'name', 'title', 'access_rights', 'uuid', 'metadata', 'file'}.issubset(set(info)), info

Expand Down