From 5f13230b336f85ae326d300d9f62cc2929ee9082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A8le=20Ferotin?= Date: Thu, 18 Dec 2025 16:30:37 +0100 Subject: [PATCH 1/2] Add integration test for feature edition with missing field --- tests/django_oapif_tests/tests/ogc.py | 4 +-- tests/integration/test_integration_qgis.py | 39 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/tests/django_oapif_tests/tests/ogc.py b/tests/django_oapif_tests/tests/ogc.py index 67008a60..c62cab1e 100644 --- a/tests/django_oapif_tests/tests/ogc.py +++ b/tests/django_oapif_tests/tests/ogc.py @@ -1,14 +1,14 @@ from django_oapif import OAPIF -from django_oapif.handler import DjangoModelPermissions, DjangoModelPermissionsOrAnonReadOnly +from django_oapif.handler import DjangoModelPermissions from .models import ( Line_2056_10fields, + MandatoryField, NoGeom_10fields, NoGeom_100fields, Point_2056_10fields, Polygon_2056, SecretLayer, - MandatoryField, ) ogc_api = OAPIF() diff --git a/tests/integration/test_integration_qgis.py b/tests/integration/test_integration_qgis.py index 72534d66..1885dda3 100644 --- a/tests/integration/test_integration_qgis.py +++ b/tests/integration/test_integration_qgis.py @@ -1,6 +1,7 @@ import requests from qgis.core import ( QgsDataSourceUri, + QgsEditError, QgsFeature, QgsPoint, QgsProject, @@ -25,6 +26,12 @@ def setUpClass(cls): cls.user = "admin" cls.password = "123" + def assertEndsWith(self, s, suffix, msg=None): + """Check that the expression is true.""" + if not s.endswith(suffix): + msg = self._formatMessage(msg, f"{unittest.util.safe_repr(s)} does not ends with '{suffix}'") + raise self.failureException(msg) + def test_endpoint_ok(self): root_response = requests.get(ROOT_URL) collections_response = requests.get(COLLECTIONS_URL) @@ -95,3 +102,35 @@ def test_load_and_edit_with_basic_auth(self): f = next(layer.getFeatures("field_str_0='Super Green'")) self.assertIsInstance(f, QgsFeature) self.assertEqual(geom.asWkt(), f.geometry().asWkt()) + + def test_load_and_edit_with_missing_field(self): + uri = QgsDataSourceUri() + uri.setParam("service", "wfs") + uri.setParam("typename", "tests.mandatoryfield") + uri.setParam("url", ROOT_URL) + uri.setUsername("admin") + uri.setPassword("123") + + layer = QgsVectorLayer(uri.uri(), "point", "OAPIF") + self.assertTrue(layer.isValid()) + layer = self.project.addMapLayer(layer) + self.assertIsNotNone(layer) + + self.assertTrue(bool(layer.dataProvider().capabilities() & QgsVectorDataProvider.Capability.AddFeatures)) + + f = QgsFeature() + f.setFields(layer.fields()) + f.setGeometry(QgsPoint(2345678.0, 1234567.0)) + f["text_mandatory_field"] = None + error = None + try: + with edit(layer): + layer.addFeature(f) + except QgsEditError as e: + error = e + + self.assertIsNotNone(error) + self.assertEndsWith(str(error), "server replied: Unprocessable Entity']") + + f = next(layer.getFeatures()) + self.assertIsInstance(f, QgsFeature) From ca84d383de28088a0ca28b9efc13563bddcd0770 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A8le=20Ferotin?= Date: Thu, 18 Dec 2025 16:50:57 +0100 Subject: [PATCH 2/2] Update qgis image --- tests/docker-compose.dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/docker-compose.dev.yml b/tests/docker-compose.dev.yml index d98a85b8..0d377e60 100644 --- a/tests/docker-compose.dev.yml +++ b/tests/docker-compose.dev.yml @@ -38,7 +38,7 @@ services: command: ["/bin/sh", "-c", "/build/run/run.sh"] integration_tests: - image: qgis/qgis:3.42.3-bookworm + image: qgis/qgis:3.44-noble command: sh -c 'xvfb-run python3 -m unittest discover' tty: true volumes: