From 251ef6c839263d8af7891a19ac42d370493ee667 Mon Sep 17 00:00:00 2001 From: David Marteau Date: Fri, 20 Sep 2024 11:15:36 +0200 Subject: [PATCH] CI: Fix .gitlab-ci config --- .gitlab-ci.yml | 2 +- pyqgisserver/utils/qgis.py | 2 +- tests/unittests/test_getfeatures.py | 42 +++++++++++++++++++----- tests/unittests/test_getlegendgraphic.py | 33 +++++++++++++++++++ 4 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 tests/unittests/test_getlegendgraphic.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 97b3c4a..e41d53a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -24,7 +24,7 @@ stages: tags: - factory-plain variables: - ASYNC_TEST_TIMEOUT: 20.0 + ASYNC_TEST_TIMEOUT: "20.0" tests:ltr: extends: .tests diff --git a/pyqgisserver/utils/qgis.py b/pyqgisserver/utils/qgis.py index 9f7e464..604f20d 100644 --- a/pyqgisserver/utils/qgis.py +++ b/pyqgisserver/utils/qgis.py @@ -32,7 +32,7 @@ def start_qgis_application( enable_processing: bool = False, verbose: bool = False, cleanup: bool = True, logger: Optional[logging.Logger] = None, - logprefix: str = 'Qgis:' + logprefix: str = 'Qgis:', ) -> qgis.core.QgsApplication: """ Start qgis application diff --git a/tests/unittests/test_getfeatures.py b/tests/unittests/test_getfeatures.py index de78ab0..8f7bf82 100644 --- a/tests/unittests/test_getfeatures.py +++ b/tests/unittests/test_getfeatures.py @@ -18,14 +18,34 @@ def get_app(self) -> None: def test_getfeature_nolimit(self): """ Test getcapabilities hrefs """ - rv = self.client.get("?MAP=france_parts.qgs&SERVICE=WFS&REQUEST=GetFeature&VERSION=1.0.0" - "&TYPENAME=france_parts_bordure") + rv = self.client.get( + "?MAP=france_parts.qgs&SERVICE=WFS&REQUEST=GetFeature&VERSION=1.0.0" + "&TYPENAME=france_parts_bordure", + ) assert rv.status_code == 200 assert rv.headers['Content-Type'].startswith('text/xml;') features = rv.xml.findall(".//gml:featureMember", NAMESPACES) assert len(features) == 4 + def test_getfeature_nolimit_geojson(self): + """ Test getcapabilities hrefs + """ + rv = self.client.get( + "?MAP=france_parts.qgs&SERVICE=WFS&REQUEST=GetFeature&VERSION=1.0.0" + "&TYPENAME=france_parts_bordure" + "&OUTPUTFORMAT=GeoJSON", + ) + assert rv.status_code == 200 + assert rv.headers['Content-Type'].startswith('application/vnd.geo+json;') + + content = rv.json() + + # print("\ntest_getfeature_nolimit_geojson", content) + + assert content.get('type') == "FeatureCollection" + assert len(content["features"]) == 4 + class Tests2(HTTPTestCase): @@ -39,8 +59,10 @@ def test_getfeature_limit(self): assert confservice.getint('server', 'getfeaturelimit') == 2 - rv = self.client.get("?MAP=france_parts.qgs&SERVICE=WFS&REQUEST=GetFeature&VERSION=1.0.0" - "&TYPENAME=france_parts_bordure") + rv = self.client.get( + "?MAP=france_parts.qgs&SERVICE=WFS&REQUEST=GetFeature&VERSION=1.0.0" + "&TYPENAME=france_parts_bordure", + ) assert rv.status_code == 200 assert rv.headers['Content-Type'].startswith('text/xml;') @@ -53,8 +75,10 @@ def test_getfeature_limit_ok(self): assert confservice.getint('server', 'getfeaturelimit') == 2 - rv = self.client.get("?MAP=france_parts.qgs&SERVICE=WFS&REQUEST=GetFeature&VERSION=1.0.0" - "&TYPENAME=france_parts_bordure&MAXFEATURES=1") + rv = self.client.get( + "?MAP=france_parts.qgs&SERVICE=WFS&REQUEST=GetFeature&VERSION=1.0.0" + "&TYPENAME=france_parts_bordure&MAXFEATURES=1", + ) assert rv.status_code == 200 assert rv.headers['Content-Type'].startswith('text/xml;') @@ -66,8 +90,10 @@ def test_getfeature_limit_not_ok(self): """ assert confservice.getint('server', 'getfeaturelimit') == 2 - rv = self.client.get("?MAP=france_parts.qgs&SERVICE=WFS&REQUEST=GetFeature&VERSION=1.0.0" - "&TYPENAME=france_parts_bordure&MAXFEATURES=3") + rv = self.client.get( + "?MAP=france_parts.qgs&SERVICE=WFS&REQUEST=GetFeature&VERSION=1.0.0" + "&TYPENAME=france_parts_bordure&MAXFEATURES=3", + ) assert rv.status_code == 200 assert rv.headers['Content-Type'].startswith('text/xml;') diff --git a/tests/unittests/test_getlegendgraphic.py b/tests/unittests/test_getlegendgraphic.py new file mode 100644 index 0000000..14c2377 --- /dev/null +++ b/tests/unittests/test_getlegendgraphic.py @@ -0,0 +1,33 @@ +""" + Test Getfeature requests +""" +import pytest + +from pyqgisserver.tests import HTTPTestCase + +xlink = "{http://www.w3.org/1999/xlink}" + + +class Tests(HTTPTestCase): + + @pytest.mark.skip(reason="Wait for proper datasource") + def test_getlegendgraphic_xml(self): + """ Test getlegendgraphic + """ + rv = self.client.get( + "?MAP=france_parts.qgs&SERVICE=WFS&REQUEST=GetLegendGraphic&VERSION=1.0.0" + "&FORMAT=image/png&WIDTH=20&HEIGHT=20&LAYER=france_parts_bordure", + ) + assert rv.status_code == 200 + assert rv.headers['Content-Type'].startswith('text/xml;') + + @pytest.mark.skip(reason="Wait for proper datasource") + def test_getlegendgraphic_json(self): + """ Test getlegendgraphic in json format + """ + rv = self.client.get( + "?MAP=france_parts.qgs&SERVICE=WFS&REQUEST=GetLegendGraphic&VERSION=1.0.0" + "&FORMAT=json&WIDTH=20&HEIGHT=20&LAYER=france_parts_bordure", + ) + assert rv.status_code == 200 + assert rv.headers['Content-Type'].startswith('text/xml;')