Skip to content

Commit

Permalink
FIX: syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
neo-garaix committed Nov 7, 2024
1 parent deaa0ec commit de890bd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
3 changes: 2 additions & 1 deletion lizmap_server/expression_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,8 @@ def virtualFields(params: Dict[str, str], response: QgsServerResponse, project:
req_sorting_field = params.get('SORTING_FIELD', '')

if type(req_sorting_order) is bool :
req.setOrderBy(QgsFeatureRequest.OrderBy([QgsFeatureRequest.OrderByClause(req_sorting_field, req_sorting_order)]))
order_by_clause = QgsFeatureRequest.OrderByClause(req_sorting_field, req_sorting_order)
req.setOrderBy(QgsFeatureRequest.OrderBy([order_by_clause]))

# get filter
req_filter = params.get('FILTER', '')
Expand Down
43 changes: 26 additions & 17 deletions test/test_expression_service_virtualfields.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json

from urllib.parse import quote
from test.utils import _build_query_string, _check_request

__copyright__ = 'Copyright 2019, 3Liz'
__license__ = 'GPL version 3'
Expand Down Expand Up @@ -211,15 +212,19 @@ def test_request_limit(client):
projectfile = "france_parts.qgs"

# Make a request
qs = "?SERVICE=EXPRESSION&REQUEST=VirtualFields&MAP=france_parts.qgs&LAYER=france_parts"
qs += "&VIRTUALS={\"a\":\"%s\", \"b\":\"%s\"}" % (
quote('1', safe=''), quote('1 + 1', safe=''))
qs += "&LIMIT=2"
rv = client.get(qs, projectfile)
assert rv.status_code == 200
assert rv.headers.get('Content-Type', '').find('application/json') == 0
qs = {
"SERVICE": "EXPRESSION",
"REQUEST": "VirtualFields",
"MAP": "france_parts.qgs",
"LAYER": "france_parts",
"VIRTUALS": "{\"a\":\"%s\", \"b\":\"%s\"}" % (
quote('1', safe=''), quote('1 + 1', safe='')),
"LIMIT": "2",
}

rv = client.get(_build_query_string(qs), projectfile)
b = _check_request(rv, http_code=200)

b = json.loads(rv.content.decode('utf-8'))
assert 'type' in b
assert b['type'] == 'FeatureCollection'

Expand Down Expand Up @@ -248,16 +253,20 @@ def test_request_order(client):
projectfile = "france_parts.qgs"

# Make a request
qs = "?SERVICE=EXPRESSION&REQUEST=VirtualFields&MAP=france_parts.qgs&LAYER=france_parts"
qs += "&VIRTUALS={\"a\":\"%s\", \"b\":\"%s\"}" % (
quote('1', safe=''), quote('1 + 1', safe=''))
qs += "&SORTING_ORDER=desc"
qs += "&SORTING_FIELD=NAME_1"
rv = client.get(qs, projectfile)
assert rv.status_code == 200
assert rv.headers.get('Content-Type', '').find('application/json') == 0
qs = {
"SERVICE": "EXPRESSION",
"REQUEST": "VirtualFields",
"MAP": "france_parts.qgs",
"LAYER": "france_parts",
"VIRTUALS": "{\"a\":\"%s\", \"b\":\"%s\"}" % (
quote('1', safe=''), quote('1 + 1', safe='')),
"SORTING_ORDER": "desc",
"SORTING_FIELD": "NAME_1",
}

rv = client.get(_build_query_string(qs), projectfile)
b = _check_request(rv, http_code=200)

b = json.loads(rv.content.decode('utf-8'))
assert 'type' in b
assert b['type'] == 'FeatureCollection'

Expand Down

0 comments on commit de890bd

Please sign in to comment.