diff --git a/src/linkahead/common/models.py b/src/linkahead/common/models.py index 12d36179c938ecb3b626c5c34be964b4a55b4349..bfe43b01367c9a8b47768240aa3f47a3cf31354c 100644 --- a/src/linkahead/common/models.py +++ b/src/linkahead/common/models.py @@ -1958,7 +1958,6 @@ class QueryTemplate(): return len(self.get_errors()) > 0 - class Parent(Entity): """The parent entities.""" @@ -2130,7 +2129,6 @@ class Property(Entity): else: return is_reference(self.datatype) - def value_matches_versionid(self): """Returns True if the value matches the pattern <id>@<version>""" return value_matches_versionid(self.value) @@ -2139,6 +2137,7 @@ class Property(Entity): """Returns the ID part of the versionid with the pattern <id>@<version>""" return get_id_from_versionid(self.value) + class Message(object): def __init__( @@ -5684,6 +5683,7 @@ def _filter_entity_list_by_identity(listobject: list[Entity], matches.append(candidate) return matches + def value_matches_versionid(value: Union[int, str]): """Returns True if the value matches the pattern <id>@<version>""" if isinstance(value, int): @@ -5693,6 +5693,7 @@ def value_matches_versionid(value: Union[int, str]): "Did you call value_matches_versionid on a non reference value?") return "@" in value + def get_id_from_versionid(versionid: str): """Returns the ID part of the versionid with the pattern <id>@<version>""" return versionid.split("@")[0] diff --git a/unittests/test_entity.py b/unittests/test_entity.py index 722930b2ad67f1917cdfac4716e790d243806688..2f413717c48f9e5424b6a380127db6a6be9760df 100644 --- a/unittests/test_entity.py +++ b/unittests/test_entity.py @@ -31,7 +31,7 @@ from linkahead import (INTEGER, Entity, Parent, Property, Record, RecordType, configure_connection) import warnings from linkahead.common.models import (SPECIAL_ATTRIBUTES, get_id_from_versionid, -value_matches_versionid) + value_matches_versionid) from linkahead.common.versioning import Version from linkahead.connection.mockup import MockUpServerConnection from lxml import etree @@ -302,7 +302,7 @@ def test_filter_by_identity(): def test_value_matches_versionid(): assert value_matches_versionid(234) is False, "integer is no version id" assert value_matches_versionid("234") is False, ("string that only contains an integer is no " - "version id") + "version id") assert value_matches_versionid("234@bfe1a42cb37aae8ac625a757715d38814c274158") is True, ( "integer is no version id") is True with raises(ValueError): @@ -312,12 +312,14 @@ def test_value_matches_versionid(): p = Property(value="234@bfe1a42cb37aae8ac625a757715d38814c274158") assert p.value_matches_versionid() is True + def test_get_id_from_versionid(): assert get_id_from_versionid("234@bfe1a42cb37aae8ac625a757715d38814c274158") == "234" p = Property(value="234@bfe1a42cb37aae8ac625a757715d38814c274158") assert p.get_id_from_versionid_value() == "234" + def test_get_versionid(): e = Entity(id=234) e.version = Version(id="bfe1a42cb37aae8ac625a757715d38814c274158") - assert e.get_versionid() =="234@bfe1a42cb37aae8ac625a757715d38814c274158" + assert e.get_versionid() == "234@bfe1a42cb37aae8ac625a757715d38814c274158"