Skip to content

Commit

Permalink
Merge pull request #9 from mrmap-community/bugfix/multivalue-query-pa…
Browse files Browse the repository at this point in the history
…rams

fixes #8
  • Loading branch information
jokiefer authored May 25, 2023
2 parents e1832f1 + 7521482 commit 846ae5e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 29 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


[unreleased] - 2023-xx-xx
[v0.3.0] - 2023-05-25
-------------------------

Changed
~~~~~~~

* improves development documentation
* improves development documentation section
* `ogc_query_params` now can handle multi value queryparams and only returns ogc queryparams that are present with a value.

Removed
~~~~~~~

* `params_lower` property from `OGCRequest` model.


[v0.2.0] - 2023-05-17
Expand Down
50 changes: 26 additions & 24 deletions ows_lib/models/ogc_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ class OGCRequest(Request):

def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self._params_lower: dict = {}
self._ogc_query_params: dict = {}
self._ogc_query_params: Dict = {}
self._bbox: GEOSGeometry = None
self._requested_entities: List[str] = []
self._xml_request: XmlObject = None

if self.method == "GET":
self.operation: str = self.params_lower.get("request", "")
self.service_version: str = self.params_lower.get("version", "")
self.service_type: str = self.params_lower.get("service", "")
self.operation: str = self.ogc_query_params.get("REQUEST", "")
self.service_version: str = self.ogc_query_params.get(
"VERSION", "")
self.service_type: str = self.ogc_query_params.get("SERVICE", "")
elif self.method == "POST":
post_request: PostRequest = load_xmlobject_from_string(
string=self.data, xmlclass=PostRequest)
Expand All @@ -49,12 +49,12 @@ def requested_entities(self) -> List[str]:
if not self._requested_entities:
if self.is_wms:
self._requested_entities.extend(
get_requested_layers(params=self.params_lower))
get_requested_layers(params=self.ogc_query_params))
else:
if self.is_get_feature_request:
if self.is_get:
self._requested_entities.extend(
get_requested_feature_types(params=self.params_lower))
get_requested_feature_types(params=self.ogc_query_params))
elif self.is_post:
self._requested_entities.extend(
self.xml_request.requested_feature_types)
Expand Down Expand Up @@ -103,7 +103,7 @@ def is_get_capabilities_request(self) -> bool:
:return: true if this is a get capabilities request
:rtype: bool
"""
return self.operation.lower() == OGCOperationEnum.GET_CAPABILITIES.value.lower()
return self.operation == OGCOperationEnum.GET_CAPABILITIES.value

@property
def is_get_map_request(self) -> bool:
Expand All @@ -112,7 +112,7 @@ def is_get_map_request(self) -> bool:
:return: true if this is a wms get map request
:rtype: bool
"""
return self.operation.lower() == OGCOperationEnum.GET_MAP.value.lower()
return self.operation == OGCOperationEnum.GET_MAP.value

@property
def is_get_feature_info_request(self) -> bool:
Expand All @@ -121,7 +121,7 @@ def is_get_feature_info_request(self) -> bool:
:return: true if this is a wfs tranasction request
:rtype: bool
"""
return self.operation.lower() == OGCOperationEnum.GET_FEATURE_INFO.value.lower()
return self.operation == OGCOperationEnum.GET_FEATURE_INFO.value

@property
def is_get_feature_request(self) -> bool:
Expand All @@ -130,7 +130,7 @@ def is_get_feature_request(self) -> bool:
:return: true if this is a wfs get feature request
:rtype: bool
"""
return self.operation.lower() == OGCOperationEnum.GET_FEATURE.value.lower()
return self.operation == OGCOperationEnum.GET_FEATURE.value

@property
def is_transaction_request(self) -> bool:
Expand All @@ -139,7 +139,7 @@ def is_transaction_request(self) -> bool:
:return: true if this is a wfs tranasction request
:rtype: bool
"""
return self.operation.lower() == OGCOperationEnum.TRANSACTION.value.lower()
return self.operation == OGCOperationEnum.TRANSACTION.value

@property
def bbox(self) -> GEOSGeometry:
Expand All @@ -156,24 +156,16 @@ def bbox(self) -> GEOSGeometry:
if not self._bbox:
try:
self._bbox = construct_polygon_from_bbox_query_param(
get_dict=self.params_lower)
get_dict=self.ogc_query_params)
except (MissingBboxParam, MissingServiceParam):
# only to avoid error while handling sql in service property
self._bbox = GEOSGeometry("POLYGON EMPTY")
return self._bbox

@property
def params_lower(self) -> Dict:
"""Lower case key mapper for paramas
:return: all parameters of the request in lower case key
:rtype: Dict
"""
return {k.lower(): v for k, v in self.params.items()} if not self._params_lower else self._params_lower

@property
def ogc_query_params(self) -> Dict:
""" Parses the GET parameters into all member variables, which can be found in a ogc request.
:return: all ogc query parameters
:rtype: Dict
"""
Expand All @@ -182,8 +174,18 @@ def ogc_query_params(self) -> Dict:
"OUTPUTFORMAT", "SRS", "CRS", "SRSNAME", "WIDTH", "HEIGHT",
"TRANSPARENT", "EXCEPTIONS", "BGCOLOR", "TIME", "ELEVATION",
"QUERY_LAYERS", "INFO_FORMAT", "FEATURE_COUNT", "I", "J"]
self._ogc_query_params = {key: self.params_lower.get(
key, self.params_lower.get(key.lower())) for key in query_keys}

for key in query_keys:
value = self.params.get(key, self.params.get(key.lower(), ""))

if value:
if isinstance(value, list):
# if multiple values are passed in multiple queryparams, we pick the first item
value = value[0]

self._ogc_query_params.update({
key: value
})

return self._ogc_query_params

Expand Down
9 changes: 6 additions & 3 deletions tests/models/tests_ogc_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.test import RequestFactory, SimpleTestCase
from eulxml.xmlmap import load_xmlobject_from_file

from ows_lib.models.ogc_request import OGCRequest
from ows_lib.xml_mapper.xml_requests.wfs.get_feature import GetFeatureRequest
from tests.settings import DJANGO_TEST_ROOT_DIR
Expand All @@ -17,13 +18,14 @@ def test_ogc_request_with_get_map_request(self):

ogc_request: OGCRequest = OGCRequest(
method="GET",
url="/mrmap-proxy/wms/cd16cc1f-3abb-4625-bb96-fbe80dbe23e3/",
params={"REQUEST": "GetMap", "SERVICE": "WMS", "VERSION": "1.3.0", "LAYERS": "somelayer,anotherlayer"})
url="http://mrmap-proxy/wms/cd16cc1f-3abb-4625-bb96-fbe80dbe23e3/",
params={"REQUEST": ["GetMap"], "SERVICE": "WMS", "VERSION": "1.3.0", "LAYERS": "somelayer,anotherlayer"})

self.assertTrue(ogc_request.is_get)
self.assertTrue(ogc_request.is_get_map_request)
self.assertEqual(["somelayer", "anotherlayer"],
ogc_request.requested_entities)
ogc_request.prepare()

def test_ogc_request_with_post_get_feature_request(self):
"""Test that create manager function works correctly for a given GetFeature post request"""
Expand All @@ -35,7 +37,7 @@ def test_ogc_request_with_post_get_feature_request(self):
filename=path, xmlclass=GetFeatureRequest)

ogc_request: OGCRequest = OGCRequest(
url="/mrmap-proxy/wfs/73cf78c9-6605-47fd-ac4f-1be59265df65/",
url="http://mrmap-proxy/wfs/73cf78c9-6605-47fd-ac4f-1be59265df65/",
data=get_feature_request.serializeDocument(),
headers={"content_type": "application/gml+xml; version=3.2"},
method="POST")
Expand All @@ -44,3 +46,4 @@ def test_ogc_request_with_post_get_feature_request(self):
self.assertTrue(ogc_request.is_get_feature_request)
self.assertEqual(["ms:Countries"], ogc_request.requested_entities)
self.assertTrue(isinstance(ogc_request.xml_request, GetFeatureRequest))
ogc_request.prepare()

0 comments on commit 846ae5e

Please sign in to comment.