Skip to content

Commit

Permalink
implementation of NaamField
Browse files Browse the repository at this point in the history
  • Loading branch information
davidvlaminck committed Nov 6, 2024
1 parent 15c8877 commit 3d2f0a7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
15 changes: 15 additions & 0 deletions UnitTests/OTLFieldTests/CustomFields/NaamField_test.py
Original file line number Diff line number Diff line change
@@ -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}"
Original file line number Diff line number Diff line change
@@ -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."""
Expand All @@ -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',
Expand Down

0 comments on commit 3d2f0a7

Please sign in to comment.