From 6099c65977f03fbd06b5a2b789c42191af27fb7c Mon Sep 17 00:00:00 2001 From: signedav Date: Mon, 24 Jun 2024 13:47:51 +0200 Subject: [PATCH 1/3] Set unique and mandatory constraint on t_ili_tid fields, when an OID is defined somehow in the model. Otherwise not. Resolves parts of https://github.com/opengisch/QgisModelBaker/issues/834 --- modelbaker/dataobjects/fields.py | 15 +- tests/test_projectgen_oids.py | 344 ++++++++++++++++++++++++++++++- 2 files changed, 357 insertions(+), 2 deletions(-) diff --git a/modelbaker/dataobjects/fields.py b/modelbaker/dataobjects/fields.py index 548304d..d0e6835 100644 --- a/modelbaker/dataobjects/fields.py +++ b/modelbaker/dataobjects/fields.py @@ -20,7 +20,7 @@ from typing import TYPE_CHECKING -from qgis.core import QgsDefaultValue, QgsEditorWidgetSetup +from qgis.core import QgsDefaultValue, QgsEditorWidgetSetup, QgsFieldConstraints if TYPE_CHECKING: from modelbaker.dataobjects.layers import Layer @@ -61,3 +61,16 @@ def create(self, layer: Layer) -> None: if self.default_value_expression: default_value = QgsDefaultValue(self.default_value_expression) layer.layer.setDefaultValueDefinition(field_idx, default_value) + + if self.oid_domain: + # if defined, then set not null and unique constraints + layer.layer.setFieldConstraint( + field_idx, + QgsFieldConstraints.ConstraintNotNull, + QgsFieldConstraints.ConstraintStrengthHard, + ) + layer.layer.setFieldConstraint( + field_idx, + QgsFieldConstraints.ConstraintUnique, + QgsFieldConstraints.ConstraintStrengthHard, + ) diff --git a/tests/test_projectgen_oids.py b/tests/test_projectgen_oids.py index ed52775..28ecf34 100644 --- a/tests/test_projectgen_oids.py +++ b/tests/test_projectgen_oids.py @@ -23,7 +23,7 @@ import pathlib import tempfile -from qgis.core import QgsExpressionContextUtils, QgsProject +from qgis.core import QgsExpressionContextUtils, QgsFieldConstraints, QgsProject from qgis.testing import start_app, unittest from modelbaker.dataobjects.project import Project @@ -315,6 +315,15 @@ def _oids_tids_none(self, generator, strategy): assert ( default_value_definition.expression() == expected_other_expression ) + # check if not null and unique constraints are set (shouldn't be) + assert not ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintUnique + ) + assert not ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintNotNull + ) count += 1 # ANYOID if tree_layer.layer().name() in ["BesitzerIn"]: @@ -337,6 +346,27 @@ def _oids_tids_none(self, generator, strategy): assert ( default_value_definition.expression() == expected_other_expression ) + # check if not null and unique constraints are set + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintUnique + ) + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintNotNull + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintUnique + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintNotNull + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) count += 1 # UUIDOID if tree_layer.layer().name() in [ @@ -361,6 +391,27 @@ def _oids_tids_none(self, generator, strategy): default_value_definition = t_ili_tid_field.defaultValueDefinition() assert default_value_definition is not None assert default_value_definition.expression() == expected_uuid_expression + # check if not null and unique constraints are set + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintUnique + ) + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintNotNull + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintUnique + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintNotNull + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) count += 1 # STANARDOID if tree_layer.layer().name() in [ @@ -389,6 +440,27 @@ def _oids_tids_none(self, generator, strategy): default_value_definition.expression() == expected_standard_expression ) + # check if not null and unique constraints are set + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintUnique + ) + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintNotNull + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintUnique + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintNotNull + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) count += 1 # I32OID if tree_layer.layer().name() in ["Wiese", "Spass.Gebaeude"]: @@ -409,6 +481,27 @@ def _oids_tids_none(self, generator, strategy): default_value_definition = t_ili_tid_field.defaultValueDefinition() assert default_value_definition is not None assert default_value_definition.expression() == expected_i32_expression + # check if not null and unique constraints are set + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintUnique + ) + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintNotNull + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintUnique + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintNotNull + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) count += 1 # OIDMadness_V1.TypeID or OIDMadness_V1.TypeIDShort if tree_layer.layer().name() in ["See", "Fluss"]: @@ -434,6 +527,27 @@ def _oids_tids_none(self, generator, strategy): assert ( default_value_definition.expression() == expected_other_expression ) + # check if not null and unique constraints are set + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintUnique + ) + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintNotNull + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintUnique + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintNotNull + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) count += 1 # should find 15 @@ -573,6 +687,15 @@ def _oids_tids_group(self, generator, strategy): assert ( default_value_definition.expression() == expected_other_expression ) + # check if not null and unique constraints are set (shouldn't) + assert not ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintUnique + ) + assert not ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintNotNull + ) count += 1 # ANYOID if tree_layer.layer().name() in ["BesitzerIn"]: @@ -595,6 +718,27 @@ def _oids_tids_group(self, generator, strategy): assert ( default_value_definition.expression() == expected_other_expression ) + # check if not null and unique constraints are set + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintUnique + ) + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintNotNull + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintUnique + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintNotNull + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) count += 1 # UUIDOID if tree_layer.layer().name() in [ @@ -619,6 +763,27 @@ def _oids_tids_group(self, generator, strategy): default_value_definition = t_ili_tid_field.defaultValueDefinition() assert default_value_definition is not None assert default_value_definition.expression() == expected_uuid_expression + # check if not null and unique constraints are set + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintUnique + ) + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintNotNull + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintUnique + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintNotNull + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) count += 1 # STANARDOID if tree_layer.layer().name() in [ @@ -647,6 +812,27 @@ def _oids_tids_group(self, generator, strategy): default_value_definition.expression() == expected_standard_expression ) + # check if not null and unique constraints are set + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintUnique + ) + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintNotNull + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintUnique + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintNotNull + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) count += 1 # I32OID if tree_layer.layer().name() in ["Wiese", "Spass.Gebaeude"]: @@ -667,6 +853,27 @@ def _oids_tids_group(self, generator, strategy): default_value_definition = t_ili_tid_field.defaultValueDefinition() assert default_value_definition is not None assert default_value_definition.expression() == expected_i32_expression + # check if not null and unique constraints are set + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintUnique + ) + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintNotNull + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintUnique + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintNotNull + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) count += 1 # OIDMadness_V1.TypeID or OIDMadness_V1.TypeIDShort if tree_layer.layer().name() in ["See", "Fluss"]: @@ -692,6 +899,27 @@ def _oids_tids_group(self, generator, strategy): assert ( default_value_definition.expression() == expected_other_expression ) + # check if not null and unique constraints are set + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintUnique + ) + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintNotNull + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintUnique + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintNotNull + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) count += 1 # should find 15 @@ -832,6 +1060,15 @@ def _oids_tids_hide(self, generator, strategy): assert ( default_value_definition.expression() == expected_other_expression ) + # check if not null and unique constraints are set (shouldn't) + assert not ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintUnique + ) + assert not ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintNotNull + ) count += 1 # ANYOID if tree_layer.layer().name() in ["BesitzerIn"]: @@ -854,6 +1091,27 @@ def _oids_tids_hide(self, generator, strategy): assert ( default_value_definition.expression() == expected_other_expression ) + # check if not null and unique constraints are set + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintUnique + ) + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintNotNull + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintUnique + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintNotNull + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) count += 1 # UUIDOID if tree_layer.layer().name() in ["Quartier.Gebaeude", "Wald"]: @@ -874,6 +1132,27 @@ def _oids_tids_hide(self, generator, strategy): default_value_definition = t_ili_tid_field.defaultValueDefinition() assert default_value_definition is not None assert default_value_definition.expression() == expected_uuid_expression + # check if not null and unique constraints are set + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintUnique + ) + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintNotNull + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintUnique + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintNotNull + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) count += 1 # STANARDOID if tree_layer.layer().name() in [ @@ -902,6 +1181,27 @@ def _oids_tids_hide(self, generator, strategy): default_value_definition.expression() == expected_standard_expression ) + # check if not null and unique constraints are set + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintUnique + ) + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintNotNull + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintUnique + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintNotNull + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) count += 1 # I32OID if tree_layer.layer().name() in ["Wiese", "Spass.Gebaeude"]: @@ -922,6 +1222,27 @@ def _oids_tids_hide(self, generator, strategy): default_value_definition = t_ili_tid_field.defaultValueDefinition() assert default_value_definition is not None assert default_value_definition.expression() == expected_i32_expression + # check if not null and unique constraints are set + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintUnique + ) + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintNotNull + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintUnique + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintNotNull + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) count += 1 # OIDMadness_V1.TypeID or OIDMadness_V1.TypeIDShort if tree_layer.layer().name() in ["See", "Fluss"]: @@ -947,6 +1268,27 @@ def _oids_tids_hide(self, generator, strategy): assert ( default_value_definition.expression() == expected_other_expression ) + # check if not null and unique constraints are set + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintUnique + ) + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintNotNull + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintUnique + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintNotNull + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) count += 1 # should find 14 From 2fe7bb43dbb2e0d1b8127aa967396fd5744c48ef Mon Sep 17 00:00:00 2001 From: signedav Date: Mon, 24 Jun 2024 15:10:33 +0200 Subject: [PATCH 2/3] provide set and unset of t_ili_tid constraints as oid_settings in QgisProjectUtils --- modelbaker/utils/qgis_utils.py | 62 ++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/modelbaker/utils/qgis_utils.py b/modelbaker/utils/qgis_utils.py index 9e473a3..9489984 100644 --- a/modelbaker/utils/qgis_utils.py +++ b/modelbaker/utils/qgis_utils.py @@ -22,6 +22,7 @@ QgsAttributeEditorField, QgsDefaultValue, QgsExpressionContextUtils, + QgsFieldConstraints, QgsLayerTreeLayer, QgsLayerTreeNode, QgsMapLayer, @@ -147,6 +148,8 @@ def get_oid_settings(self): "interlis_topic" : "OIDMadness_V1", "default_value_expression": "uuid()", "in_form": True + "not_null": True, + "unique": True, "layer": QgsVectorLayer } } @@ -198,6 +201,17 @@ def get_oid_settings(self): oid_setting["in_form"] = bool( self._found_tilitid(root_container) is not None ) + + # get the constraints + oid_setting["not_null"] = bool( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintNotNull + ) + oid_setting["unique"] = bool( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintUnique + ) + oid_settings[tree_layer.layer().name()] = oid_setting return oid_settings @@ -250,6 +264,54 @@ def set_oid_settings(self, oid_settings): continue found_container.addChildElement(child.clone(found_container)) + # set the constraints if not yet set and set it strong + if ( + not bool( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintNotNull + ) + and oid_setting["not_null"] + ): + layer.setFieldConstraint( + field_idx, + QgsFieldConstraints.ConstraintNotNull, + QgsFieldConstraints.ConstraintStrengthHard, + ) + if ( + bool( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintNotNull + ) + and not oid_setting["not_null"] + ): + layer.removeFieldConstraint( + field_idx, + QgsFieldConstraints.ConstraintNotNull, + ) + if ( + not bool( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintUnique + ) + and oid_setting["unique"] + ): + layer.setFieldConstraint( + field_idx, + QgsFieldConstraints.ConstraintUnique, + QgsFieldConstraints.ConstraintStrengthHard, + ) + if ( + bool( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintUnique + ) + and not oid_setting["unique"] + ): + layer.removeFieldConstraint( + field_idx, + QgsFieldConstraints.ConstraintUnique, + ) + def _found_tilitid(self, container): """Recursive function to dig into the form containers for the t_ili_tid returning true on success.""" for element in container.children(): From bc4f80069ba87ef33889699bd6e81c4c51c9b0eb Mon Sep 17 00:00:00 2001 From: signedav Date: Thu, 27 Jun 2024 11:20:23 +0200 Subject: [PATCH 3/3] optimized test checks --- tests/test_projectgen_oids.py | 337 ++++------------------------------ 1 file changed, 37 insertions(+), 300 deletions(-) diff --git a/tests/test_projectgen_oids.py b/tests/test_projectgen_oids.py index 28ecf34..fe563a7 100644 --- a/tests/test_projectgen_oids.py +++ b/tests/test_projectgen_oids.py @@ -347,26 +347,7 @@ def _oids_tids_none(self, generator, strategy): default_value_definition.expression() == expected_other_expression ) # check if not null and unique constraints are set - assert ( - t_ili_tid_field.constraints().constraints() - & QgsFieldConstraints.ConstraintUnique - ) - assert ( - t_ili_tid_field.constraints().constraints() - & QgsFieldConstraints.ConstraintNotNull - ) - assert ( - t_ili_tid_field.constraints().constraintStrength( - QgsFieldConstraints.ConstraintUnique - ) - == QgsFieldConstraints.ConstraintStrengthHard - ) - assert ( - t_ili_tid_field.constraints().constraintStrength( - QgsFieldConstraints.ConstraintNotNull - ) - == QgsFieldConstraints.ConstraintStrengthHard - ) + self._check_t_ili_tid_field_constraints(t_ili_tid_field) count += 1 # UUIDOID if tree_layer.layer().name() in [ @@ -392,26 +373,7 @@ def _oids_tids_none(self, generator, strategy): assert default_value_definition is not None assert default_value_definition.expression() == expected_uuid_expression # check if not null and unique constraints are set - assert ( - t_ili_tid_field.constraints().constraints() - & QgsFieldConstraints.ConstraintUnique - ) - assert ( - t_ili_tid_field.constraints().constraints() - & QgsFieldConstraints.ConstraintNotNull - ) - assert ( - t_ili_tid_field.constraints().constraintStrength( - QgsFieldConstraints.ConstraintUnique - ) - == QgsFieldConstraints.ConstraintStrengthHard - ) - assert ( - t_ili_tid_field.constraints().constraintStrength( - QgsFieldConstraints.ConstraintNotNull - ) - == QgsFieldConstraints.ConstraintStrengthHard - ) + self._check_t_ili_tid_field_constraints(t_ili_tid_field) count += 1 # STANARDOID if tree_layer.layer().name() in [ @@ -441,26 +403,7 @@ def _oids_tids_none(self, generator, strategy): == expected_standard_expression ) # check if not null and unique constraints are set - assert ( - t_ili_tid_field.constraints().constraints() - & QgsFieldConstraints.ConstraintUnique - ) - assert ( - t_ili_tid_field.constraints().constraints() - & QgsFieldConstraints.ConstraintNotNull - ) - assert ( - t_ili_tid_field.constraints().constraintStrength( - QgsFieldConstraints.ConstraintUnique - ) - == QgsFieldConstraints.ConstraintStrengthHard - ) - assert ( - t_ili_tid_field.constraints().constraintStrength( - QgsFieldConstraints.ConstraintNotNull - ) - == QgsFieldConstraints.ConstraintStrengthHard - ) + self._check_t_ili_tid_field_constraints(t_ili_tid_field) count += 1 # I32OID if tree_layer.layer().name() in ["Wiese", "Spass.Gebaeude"]: @@ -482,26 +425,7 @@ def _oids_tids_none(self, generator, strategy): assert default_value_definition is not None assert default_value_definition.expression() == expected_i32_expression # check if not null and unique constraints are set - assert ( - t_ili_tid_field.constraints().constraints() - & QgsFieldConstraints.ConstraintUnique - ) - assert ( - t_ili_tid_field.constraints().constraints() - & QgsFieldConstraints.ConstraintNotNull - ) - assert ( - t_ili_tid_field.constraints().constraintStrength( - QgsFieldConstraints.ConstraintUnique - ) - == QgsFieldConstraints.ConstraintStrengthHard - ) - assert ( - t_ili_tid_field.constraints().constraintStrength( - QgsFieldConstraints.ConstraintNotNull - ) - == QgsFieldConstraints.ConstraintStrengthHard - ) + self._check_t_ili_tid_field_constraints(t_ili_tid_field) count += 1 # OIDMadness_V1.TypeID or OIDMadness_V1.TypeIDShort if tree_layer.layer().name() in ["See", "Fluss"]: @@ -528,26 +452,7 @@ def _oids_tids_none(self, generator, strategy): default_value_definition.expression() == expected_other_expression ) # check if not null and unique constraints are set - assert ( - t_ili_tid_field.constraints().constraints() - & QgsFieldConstraints.ConstraintUnique - ) - assert ( - t_ili_tid_field.constraints().constraints() - & QgsFieldConstraints.ConstraintNotNull - ) - assert ( - t_ili_tid_field.constraints().constraintStrength( - QgsFieldConstraints.ConstraintUnique - ) - == QgsFieldConstraints.ConstraintStrengthHard - ) - assert ( - t_ili_tid_field.constraints().constraintStrength( - QgsFieldConstraints.ConstraintNotNull - ) - == QgsFieldConstraints.ConstraintStrengthHard - ) + self._check_t_ili_tid_field_constraints(t_ili_tid_field) count += 1 # should find 15 @@ -719,26 +624,7 @@ def _oids_tids_group(self, generator, strategy): default_value_definition.expression() == expected_other_expression ) # check if not null and unique constraints are set - assert ( - t_ili_tid_field.constraints().constraints() - & QgsFieldConstraints.ConstraintUnique - ) - assert ( - t_ili_tid_field.constraints().constraints() - & QgsFieldConstraints.ConstraintNotNull - ) - assert ( - t_ili_tid_field.constraints().constraintStrength( - QgsFieldConstraints.ConstraintUnique - ) - == QgsFieldConstraints.ConstraintStrengthHard - ) - assert ( - t_ili_tid_field.constraints().constraintStrength( - QgsFieldConstraints.ConstraintNotNull - ) - == QgsFieldConstraints.ConstraintStrengthHard - ) + self._check_t_ili_tid_field_constraints(t_ili_tid_field) count += 1 # UUIDOID if tree_layer.layer().name() in [ @@ -764,26 +650,7 @@ def _oids_tids_group(self, generator, strategy): assert default_value_definition is not None assert default_value_definition.expression() == expected_uuid_expression # check if not null and unique constraints are set - assert ( - t_ili_tid_field.constraints().constraints() - & QgsFieldConstraints.ConstraintUnique - ) - assert ( - t_ili_tid_field.constraints().constraints() - & QgsFieldConstraints.ConstraintNotNull - ) - assert ( - t_ili_tid_field.constraints().constraintStrength( - QgsFieldConstraints.ConstraintUnique - ) - == QgsFieldConstraints.ConstraintStrengthHard - ) - assert ( - t_ili_tid_field.constraints().constraintStrength( - QgsFieldConstraints.ConstraintNotNull - ) - == QgsFieldConstraints.ConstraintStrengthHard - ) + self._check_t_ili_tid_field_constraints(t_ili_tid_field) count += 1 # STANARDOID if tree_layer.layer().name() in [ @@ -813,26 +680,7 @@ def _oids_tids_group(self, generator, strategy): == expected_standard_expression ) # check if not null and unique constraints are set - assert ( - t_ili_tid_field.constraints().constraints() - & QgsFieldConstraints.ConstraintUnique - ) - assert ( - t_ili_tid_field.constraints().constraints() - & QgsFieldConstraints.ConstraintNotNull - ) - assert ( - t_ili_tid_field.constraints().constraintStrength( - QgsFieldConstraints.ConstraintUnique - ) - == QgsFieldConstraints.ConstraintStrengthHard - ) - assert ( - t_ili_tid_field.constraints().constraintStrength( - QgsFieldConstraints.ConstraintNotNull - ) - == QgsFieldConstraints.ConstraintStrengthHard - ) + self._check_t_ili_tid_field_constraints(t_ili_tid_field) count += 1 # I32OID if tree_layer.layer().name() in ["Wiese", "Spass.Gebaeude"]: @@ -854,26 +702,7 @@ def _oids_tids_group(self, generator, strategy): assert default_value_definition is not None assert default_value_definition.expression() == expected_i32_expression # check if not null and unique constraints are set - assert ( - t_ili_tid_field.constraints().constraints() - & QgsFieldConstraints.ConstraintUnique - ) - assert ( - t_ili_tid_field.constraints().constraints() - & QgsFieldConstraints.ConstraintNotNull - ) - assert ( - t_ili_tid_field.constraints().constraintStrength( - QgsFieldConstraints.ConstraintUnique - ) - == QgsFieldConstraints.ConstraintStrengthHard - ) - assert ( - t_ili_tid_field.constraints().constraintStrength( - QgsFieldConstraints.ConstraintNotNull - ) - == QgsFieldConstraints.ConstraintStrengthHard - ) + self._check_t_ili_tid_field_constraints(t_ili_tid_field) count += 1 # OIDMadness_V1.TypeID or OIDMadness_V1.TypeIDShort if tree_layer.layer().name() in ["See", "Fluss"]: @@ -900,26 +729,7 @@ def _oids_tids_group(self, generator, strategy): default_value_definition.expression() == expected_other_expression ) # check if not null and unique constraints are set - assert ( - t_ili_tid_field.constraints().constraints() - & QgsFieldConstraints.ConstraintUnique - ) - assert ( - t_ili_tid_field.constraints().constraints() - & QgsFieldConstraints.ConstraintNotNull - ) - assert ( - t_ili_tid_field.constraints().constraintStrength( - QgsFieldConstraints.ConstraintUnique - ) - == QgsFieldConstraints.ConstraintStrengthHard - ) - assert ( - t_ili_tid_field.constraints().constraintStrength( - QgsFieldConstraints.ConstraintNotNull - ) - == QgsFieldConstraints.ConstraintStrengthHard - ) + self._check_t_ili_tid_field_constraints(t_ili_tid_field) count += 1 # should find 15 @@ -1092,26 +902,7 @@ def _oids_tids_hide(self, generator, strategy): default_value_definition.expression() == expected_other_expression ) # check if not null and unique constraints are set - assert ( - t_ili_tid_field.constraints().constraints() - & QgsFieldConstraints.ConstraintUnique - ) - assert ( - t_ili_tid_field.constraints().constraints() - & QgsFieldConstraints.ConstraintNotNull - ) - assert ( - t_ili_tid_field.constraints().constraintStrength( - QgsFieldConstraints.ConstraintUnique - ) - == QgsFieldConstraints.ConstraintStrengthHard - ) - assert ( - t_ili_tid_field.constraints().constraintStrength( - QgsFieldConstraints.ConstraintNotNull - ) - == QgsFieldConstraints.ConstraintStrengthHard - ) + self._check_t_ili_tid_field_constraints(t_ili_tid_field) count += 1 # UUIDOID if tree_layer.layer().name() in ["Quartier.Gebaeude", "Wald"]: @@ -1133,26 +924,7 @@ def _oids_tids_hide(self, generator, strategy): assert default_value_definition is not None assert default_value_definition.expression() == expected_uuid_expression # check if not null and unique constraints are set - assert ( - t_ili_tid_field.constraints().constraints() - & QgsFieldConstraints.ConstraintUnique - ) - assert ( - t_ili_tid_field.constraints().constraints() - & QgsFieldConstraints.ConstraintNotNull - ) - assert ( - t_ili_tid_field.constraints().constraintStrength( - QgsFieldConstraints.ConstraintUnique - ) - == QgsFieldConstraints.ConstraintStrengthHard - ) - assert ( - t_ili_tid_field.constraints().constraintStrength( - QgsFieldConstraints.ConstraintNotNull - ) - == QgsFieldConstraints.ConstraintStrengthHard - ) + self._check_t_ili_tid_field_constraints(t_ili_tid_field) count += 1 # STANARDOID if tree_layer.layer().name() in [ @@ -1182,26 +954,7 @@ def _oids_tids_hide(self, generator, strategy): == expected_standard_expression ) # check if not null and unique constraints are set - assert ( - t_ili_tid_field.constraints().constraints() - & QgsFieldConstraints.ConstraintUnique - ) - assert ( - t_ili_tid_field.constraints().constraints() - & QgsFieldConstraints.ConstraintNotNull - ) - assert ( - t_ili_tid_field.constraints().constraintStrength( - QgsFieldConstraints.ConstraintUnique - ) - == QgsFieldConstraints.ConstraintStrengthHard - ) - assert ( - t_ili_tid_field.constraints().constraintStrength( - QgsFieldConstraints.ConstraintNotNull - ) - == QgsFieldConstraints.ConstraintStrengthHard - ) + self._check_t_ili_tid_field_constraints(t_ili_tid_field) count += 1 # I32OID if tree_layer.layer().name() in ["Wiese", "Spass.Gebaeude"]: @@ -1223,26 +976,7 @@ def _oids_tids_hide(self, generator, strategy): assert default_value_definition is not None assert default_value_definition.expression() == expected_i32_expression # check if not null and unique constraints are set - assert ( - t_ili_tid_field.constraints().constraints() - & QgsFieldConstraints.ConstraintUnique - ) - assert ( - t_ili_tid_field.constraints().constraints() - & QgsFieldConstraints.ConstraintNotNull - ) - assert ( - t_ili_tid_field.constraints().constraintStrength( - QgsFieldConstraints.ConstraintUnique - ) - == QgsFieldConstraints.ConstraintStrengthHard - ) - assert ( - t_ili_tid_field.constraints().constraintStrength( - QgsFieldConstraints.ConstraintNotNull - ) - == QgsFieldConstraints.ConstraintStrengthHard - ) + self._check_t_ili_tid_field_constraints(t_ili_tid_field) count += 1 # OIDMadness_V1.TypeID or OIDMadness_V1.TypeIDShort if tree_layer.layer().name() in ["See", "Fluss"]: @@ -1269,26 +1003,7 @@ def _oids_tids_hide(self, generator, strategy): default_value_definition.expression() == expected_other_expression ) # check if not null and unique constraints are set - assert ( - t_ili_tid_field.constraints().constraints() - & QgsFieldConstraints.ConstraintUnique - ) - assert ( - t_ili_tid_field.constraints().constraints() - & QgsFieldConstraints.ConstraintNotNull - ) - assert ( - t_ili_tid_field.constraints().constraintStrength( - QgsFieldConstraints.ConstraintUnique - ) - == QgsFieldConstraints.ConstraintStrengthHard - ) - assert ( - t_ili_tid_field.constraints().constraintStrength( - QgsFieldConstraints.ConstraintNotNull - ) - == QgsFieldConstraints.ConstraintStrengthHard - ) + self._check_t_ili_tid_field_constraints(t_ili_tid_field) count += 1 # should find 14 @@ -1369,6 +1084,28 @@ def _oids_tids_hide(self, generator, strategy): QgsProject.instance().clear() + def _check_t_ili_tid_field_constraints(self, t_ili_tid_field): + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintUnique + ) + assert ( + t_ili_tid_field.constraints().constraints() + & QgsFieldConstraints.ConstraintNotNull + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintUnique + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) + assert ( + t_ili_tid_field.constraints().constraintStrength( + QgsFieldConstraints.ConstraintNotNull + ) + == QgsFieldConstraints.ConstraintStrengthHard + ) + def _set_pg_naming(self, is_pg=True): if is_pg: self.tilitid_fieldname = "t_ili_tid"