Allow retrieving extra properties in oracle provider (#1544)
* Implement extra_properties in oracle Provider These can be used to configure additional database-computed fields in the config file which are returned on `get` and `query` calls * Allow mandating properties which are not part of the output Previously, properties which were not requested for the output were not part of `fields`, which means that they were not passed in to the provider as filter properties for e.g. `query()`. This commit adds them there and introduces a new variable `filtered_fields`, which is used for limiting the output of queries. There is also some minor refactoring, but the existing and also the newly written tests should avoid regressions. * Restore previous behavior for default arguments
This commit is contained in:
committed by
GitHub
parent
34d595accf
commit
8d377072b9
@@ -32,6 +32,7 @@
|
||||
|
||||
import os
|
||||
import pytest
|
||||
from pygeoapi.provider.base import ProviderInvalidQueryError
|
||||
from pygeoapi.provider.oracle import OracleProvider
|
||||
|
||||
USERNAME = os.environ.get("PYGEOAPI_ORACLE_USER", "geo_test")
|
||||
@@ -202,6 +203,14 @@ def config_properties(config):
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def config_extra_properties(config):
|
||||
return {
|
||||
**config,
|
||||
"extra_properties": ["'Here the name is ' || name || '!' as tooltip"],
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def create_geojson():
|
||||
return {
|
||||
@@ -332,15 +341,18 @@ def test_get_fields_properties(config_properties):
|
||||
Test get_fields with subset of columns.
|
||||
Test of property configuration.
|
||||
"""
|
||||
# NOTE: properties does not influence fields because
|
||||
# the fields are also used for filtering
|
||||
expected_fields = {
|
||||
"id": {"type": "NUMBER"},
|
||||
"name": {"type": "VARCHAR2"},
|
||||
"wiki_link": {"type": "VARCHAR2"},
|
||||
"area": {"type": "NUMBER"},
|
||||
"volume": {"type": "NUMBER"},
|
||||
}
|
||||
|
||||
provider = OracleProvider(config_properties)
|
||||
provided_fields = provider.get_fields()
|
||||
print(provided_fields)
|
||||
|
||||
assert provided_fields == expected_fields
|
||||
assert provider.fields == expected_fields
|
||||
@@ -356,6 +368,15 @@ def test_query_with_property_filter(config):
|
||||
assert features[0].get("id") == 12
|
||||
|
||||
|
||||
def test_query_with_extra_properties(config_extra_properties):
|
||||
p = OracleProvider(config_extra_properties)
|
||||
|
||||
feature_collection = p.query(properties=[("name", "Aral Sea")])
|
||||
features = feature_collection.get("features")
|
||||
|
||||
assert features[0]["properties"]["tooltip"] == "Here the name is Aral Sea!"
|
||||
|
||||
|
||||
def test_query_bbox(config):
|
||||
"""Test query with a specified bounding box"""
|
||||
p = OracleProvider(config)
|
||||
@@ -407,6 +428,17 @@ def test_get(config):
|
||||
assert result.get("next") == 6
|
||||
|
||||
|
||||
def test_get_with_extra_properties(config_extra_properties):
|
||||
"""Test simple get"""
|
||||
p = OracleProvider(config_extra_properties)
|
||||
result = p.get(5)
|
||||
|
||||
assert (
|
||||
result["properties"]["tooltip"] ==
|
||||
"Here the name is L. Erie!"
|
||||
)
|
||||
|
||||
|
||||
def test_create(config, create_geojson):
|
||||
"""Test simple create"""
|
||||
p = OracleProvider(config)
|
||||
@@ -557,3 +589,30 @@ def test_create_point(config, create_point_geojson):
|
||||
data = p.get(28)
|
||||
|
||||
assert data.get("geometry").get("type") == "Point"
|
||||
|
||||
|
||||
def test_query_can_mandate_properties_which_are_not_returned(config):
|
||||
config = {
|
||||
**config,
|
||||
# 'name' has to be filtered, but only 'wiki_link' is returned
|
||||
"properties": ["id", "wiki_link"],
|
||||
"mandatory_properties": ["name"]
|
||||
}
|
||||
|
||||
p = OracleProvider(config)
|
||||
result = p.query(properties=[("name", "Aral Sea")])
|
||||
|
||||
(feature,) = result['features']
|
||||
# id is handled separately, so only wiki link and not name must be here
|
||||
assert feature['properties'].keys() == {"wiki_link"}
|
||||
|
||||
|
||||
def test_query_mandatory_properties_must_be_specified(config):
|
||||
config = {
|
||||
**config,
|
||||
"mandatory_properties": ["name"]
|
||||
}
|
||||
|
||||
p = OracleProvider(config)
|
||||
with pytest.raises(ProviderInvalidQueryError):
|
||||
p.query(properties=[("id", "123")])
|
||||
|
||||
Reference in New Issue
Block a user