From 3d2f0a7a04fce618a2d1f8fcddb16b5deff6c678 Mon Sep 17 00:00:00 2001 From: davidvlaminck <“david.vlaminck@mow.vlaanderen.be”> Date: Wed, 6 Nov 2024 13:33:30 +0100 Subject: [PATCH 1/9] implementation of NaamField --- .../OTLFieldTests/CustomFields/NaamField_test.py | 15 +++++++++++++++ .../Classes/ImplementatieElement/AIMNaamObject.py | 15 ++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 UnitTests/OTLFieldTests/CustomFields/NaamField_test.py diff --git a/UnitTests/OTLFieldTests/CustomFields/NaamField_test.py b/UnitTests/OTLFieldTests/CustomFields/NaamField_test.py new file mode 100644 index 000000000..c23af7a55 --- /dev/null +++ b/UnitTests/OTLFieldTests/CustomFields/NaamField_test.py @@ -0,0 +1,15 @@ +import pytest + +from otlmow_model.OtlmowModel.Classes.ImplementatieElement.AIMNaamObject import NaamField + + +@pytest.mark.parametrize("value, expected, id", [ + ("validName123", True, "valid_alphanumeric"), + ("valid.name-123", True, "valid_with_special_chars"), + ("", True, "empty_string"), + ("a", True, "single_character"), + ("invalid name!", False, "invalid_with_space_and_exclamation"), + ("invalid@name", False, "invalid_with_at_symbol")]) +def test_validate(value, expected, id): + result = NaamField.validate(value, None) + assert result == expected, f"Test case '{id}' failed: expected {expected} but got {result}" diff --git a/otlmow_model/OtlmowModel/Classes/ImplementatieElement/AIMNaamObject.py b/otlmow_model/OtlmowModel/Classes/ImplementatieElement/AIMNaamObject.py index f7a4fd6e8..0a7aa4eb9 100644 --- a/otlmow_model/OtlmowModel/Classes/ImplementatieElement/AIMNaamObject.py +++ b/otlmow_model/OtlmowModel/Classes/ImplementatieElement/AIMNaamObject.py @@ -1,10 +1,23 @@ # coding=utf-8 +import re + from otlmow_model.OtlmowModel.BaseClasses.OTLObject import OTLAttribuut from abc import abstractmethod from ...Classes.ImplementatieElement.AIMObject import AIMObject from otlmow_model.OtlmowModel.BaseClasses.StringField import StringField +class NaamField(StringField): + def __init__(self, naam: str, label: str, objectUri: str, definition: str, owner): + super().__init__(naam, label, objectUri, definition, owner) + + @classmethod + def validate(cls, value, attribuut) -> bool: + if StringField.validate(value, attribuut): + return bool(re.match('^[a-zA-Z0-9.\-_]*$', value)) + else: + return False + # Generated with OTLClassCreator. To modify: extend, do not edit class AIMNaamObject(AIMObject): """Abstracte als de basisklasse voor elk OTL object dat benoemd wordt met een mensleesbare identificator.""" @@ -16,7 +29,7 @@ class AIMNaamObject(AIMObject): def __init__(self): super().__init__() - self._naam = OTLAttribuut(field=StringField, + self._naam = OTLAttribuut(field=NaamField, naam='naam', label='naam', objectUri='https://wegenenverkeer.data.vlaanderen.be/ns/implementatieelement#AIMNaamObject.naam', From 6373eb180f6c7a02b65dfd0f55be6533f6c44ba9 Mon Sep 17 00:00:00 2001 From: github-actions Date: Wed, 6 Nov 2024 12:35:27 +0000 Subject: [PATCH 2/9] Updated coverage.svg --- UnitTests/htmlcov/class_index.html | 38 ++++-- UnitTests/htmlcov/function_index.html | 62 +++++++--- UnitTests/htmlcov/index.html | 27 +++-- UnitTests/htmlcov/status.json | 2 +- ..._2522767e51633479_DtcProfileerlaag_py.html | 18 +-- .../z_74200e1ed41eef67_AIMNaamObject_py.html | 91 ++++++++------ .../z_8cae89af01d0ef8b_NaamField_test_py.html | 112 ++++++++++++++++++ 7 files changed, 265 insertions(+), 85 deletions(-) create mode 100644 UnitTests/htmlcov/z_8cae89af01d0ef8b_NaamField_test_py.html diff --git a/UnitTests/htmlcov/class_index.html b/UnitTests/htmlcov/class_index.html index b8b807a63..cb2a4ffd1 100644 --- a/UnitTests/htmlcov/class_index.html +++ b/UnitTests/htmlcov/class_index.html @@ -55,7 +55,7 @@

coverage.py v7.6.4, - created at 2024-11-05 21:42 +0000 + created at 2024-11-06 12:35 +0000

@@ -352,6 +352,14 @@

0 100% + + UnitTests/OTLFieldTests/CustomFields/NaamField_test.py + (no class) + 6 + 0 + 0 + 100% + UnitTests/OTLFieldTests/DateField_test.py (no class) @@ -3457,8 +3465,16 @@

100% - otlmow_model/OtlmowModel/Classes/ImplementatieElement/AIMNaamObject.py - AIMNaamObject + otlmow_model/OtlmowModel/Classes/ImplementatieElement/AIMNaamObject.py + NaamField + 4 + 2 + 0 + 50% + + + otlmow_model/OtlmowModel/Classes/ImplementatieElement/AIMNaamObject.py + AIMNaamObject 4 2 0 @@ -3467,10 +3483,10 @@

otlmow_model/OtlmowModel/Classes/ImplementatieElement/AIMNaamObject.py (no class) - 13 + 18 0 0 - 100% + 100% otlmow_model/OtlmowModel/Classes/ImplementatieElement/AIMObject.py @@ -17836,9 +17852,9 @@

otlmow_model/OtlmowModel/Datatypes/DtcProfileerlaag.py DtcProfileerlaagWaarden 7 - 7 + 4 0 - 0% + 43% otlmow_model/OtlmowModel/Datatypes/DtcProfileerlaag.py @@ -34325,10 +34341,10 @@

Total   - 55942 - 5829 + 55957 + 5828 0 - 90% + 90% @@ -34340,7 +34356,7 @@

coverage.py v7.6.4, - created at 2024-11-05 21:42 +0000 + created at 2024-11-06 12:35 +0000