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

CI - Some refactoring on annotations #75

Merged
merged 1 commit into from
May 3, 2024
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
21 changes: 14 additions & 7 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,28 @@ stages:
- deploy
- release

qgis-server:
.tests:
image: ${REGISTRY_URL}/factory-ci-runner:qgis-${QGIS_FLAVOR}
stage: test
script:
- source ~/.bashrc
- make install-tests FLAVOR=$QGIS_FLAVOR
- pip list -l
- make test FLAVOR=$QGIS_FLAVOR
tags:
- factory


qgis-server:
extends: .tests
parallel:
matrix:
- QGIS_VERSION: [
"3.16",
- QGIS_FLAVOR: [
"3.22",
"3.28",
"3.34",
"nightly-release",
]
script:
- make tests FLAVOR=${QGIS_VERSION}
tags:
- infrav3

linter:
image: ${REGISTRY_URL}/factory-ci-runner:qgis-ltr
Expand Down
2 changes: 1 addition & 1 deletion lizmap_server/tooltip.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def create_popup_node_item_from_form(
alias = field.alias()
name = field.name()
fname = alias if alias else name
fname = fname.replace("'", "’") # noqa RUF001
fname = fname.replace("'", "’")

# adapt the view depending on the field type
field_widget_setup = field.editorWidgetSetup()
Expand Down
1 change: 1 addition & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ mypy
mypy-extensions
pipdeptree
xmldiff
Pillow
20 changes: 10 additions & 10 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@
; .local/lib,
; ./test/.local/lib
;
; [isort]
; multi_line_output = 3
; include_trailing_comma = True
; use_parentheses = True
; ensure_newline_before_comments = True
; lines_between_types = 1
; skip =
; .venv,
; .local/,
; .cache/,
[isort]
multi_line_output = 3
include_trailing_comma = True
use_parentheses = True
ensure_newline_before_comments = True
lines_between_types = 1
skip =
.venv,
.local/,
.cache/,

[qgis-plugin-ci]
plugin_path = lizmap_server
Expand Down
69 changes: 17 additions & 52 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
import sys
import warnings

import lxml.etree
import pytest

from qgis.PyQt import Qt

from typing import Any, Dict, Generator, Optional

import pytest

from qgis.core import Qgis, QgsApplication, QgsFontUtils, QgsProject
from qgis.PyQt import Qt
from qgis.server import (
QgsBufferServerRequest,
QgsBufferServerResponse,
QgsServer,
QgsServerRequest,
QgsServerInterface,
QgsServerRequest,
)

from .utils import OWSResponse

with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
from osgeo import gdal
Expand Down Expand Up @@ -82,50 +82,6 @@ def pytest_sessionstart(session):
# del qgis_application


NAMESPACES = {
'xlink': "http://www.w3.org/1999/xlink",
'wms': "http://www.opengis.net/wms",
'wfs': "http://www.opengis.net/wfs",
'wcs': "http://www.opengis.net/wcs",
'ows': "http://www.opengis.net/ows/1.1",
'gml': "http://www.opengis.net/gml",
'xsi': "http://www.w3.org/2001/XMLSchema-instance",
}


class OWSResponse:

def __init__(self, resp: QgsBufferServerResponse) -> None:
self._resp = resp
self._xml = None

@property
def xml(self) -> 'xml':
if self._xml is None and self._resp.headers().get('Content-Type','').find('text/xml')==0:
self._xml = lxml.etree.fromstring(self.content)
return self._xml

@property
def content(self) -> bytes:
return bytes(self._resp.body())

@property
def status_code(self) -> int:
return self._resp.statusCode()

@property
def headers(self) -> Dict[str,str]:
return self._resp.headers()

def xpath(self, path: str) -> lxml.etree.Element:
assert self.xml is not None
return self.xml.xpath(path, namespaces=NAMESPACES)

def xpath_text(self, path: str) -> str:
assert self.xml is not None
return ' '.join(e.text for e in self.xpath(path))


@pytest.fixture(scope='session')
def client(request):
""" Return a qgis server instance
Expand Down Expand Up @@ -163,7 +119,12 @@ def get_project(self, name: str) -> QgsProject:
raise ValueError("Error reading project '%s':" % projectpath.strpath)
return qgsproject

def get(self, query: str, project: Optional[str] = None, headers: Optional[Dict[str, str]] = None) -> OWSResponse:
def get(
self,
query: str,
project: Optional[str] = None,
headers: Optional[Dict[str, str]] = None,
) -> OWSResponse:
""" Return server response from query
"""
if headers is None:
Expand All @@ -177,7 +138,11 @@ def get(self, query: str, project: Optional[str] = None, headers: Optional[Dict[
self.server.handleRequest(server_request, response, project=qgsproject)
return OWSResponse(response)

def get_with_project(self, query: str, project: QgsProject, headers: Optional[Dict[str, str]] = None) -> OWSResponse:
def get_with_project(
self, query: str,
project: QgsProject,
headers: Optional[Dict[str, str]] = None,
) -> OWSResponse:
""" Return server response from query
"""
if headers is None:
Expand Down
52 changes: 51 additions & 1 deletion test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,60 @@
import json
import xml.etree.ElementTree as ET

from typing import Dict, Union

import lxml.etree

from PIL import Image
from qgis.server import QgsBufferServerResponse

__copyright__ = 'Copyright 2024, 3Liz'
__license__ = 'GPL version 3'
__email__ = '[email protected]'

NAMESPACES = {
'xlink': "http://www.w3.org/1999/xlink",
'wms': "http://www.opengis.net/wms",
'wfs': "http://www.opengis.net/wfs",
'wcs': "http://www.opengis.net/wcs",
'ows': "http://www.opengis.net/ows/1.1",
'gml': "http://www.opengis.net/gml",
'xsi': "http://www.w3.org/2001/XMLSchema-instance",
}


class OWSResponse:

def __init__(self, resp: QgsBufferServerResponse) -> None:
self._resp = resp
self._xml = None

@property
def xml(self) -> 'xml':
if self._xml is None and self._resp.headers().get('Content-Type', '').find('text/xml') == 0:
self._xml = lxml.etree.fromstring(self.content)
return self._xml

@property
def content(self) -> bytes:
return bytes(self._resp.body())

@property
def status_code(self) -> int:
return self._resp.statusCode()

@property
def headers(self) -> Dict[str, str]:
return self._resp.headers()

def xpath(self, path: str) -> lxml.etree.Element:
assert self.xml is not None
return self.xml.xpath(path, namespaces=NAMESPACES)

def xpath_text(self, path: str) -> str:
assert self.xml is not None
return ' '.join(e.text for e in self.xpath(path))


def _build_query_string(params: dict) -> str:
""" Build a query parameter from a dictionary. """
Expand All @@ -17,7 +65,9 @@ def _build_query_string(params: dict) -> str:
return query_string


def _check_request(result, content_type: str = 'application/json', http_code: int = 200): # noqa ANN401
def _check_request(
result: OWSResponse, content_type: str = 'application/json', http_code: int = 200,
) -> Union[dict, ET.Element, Image.Image]:
""" Check the output and return the content. """
assert result.status_code == http_code, f'HTTP code {result.status_code}, expected {http_code}'
assert result.headers.get('Content-Type', '').lower().find(content_type) == 0, f'Headers {result.headers}'
Expand Down