From 8ad589631b20d27fffbcf655d8925d90102881e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com> Date: Mon, 21 Nov 2022 14:13:33 +0100 Subject: [PATCH] MAINT: do not allow name in properties --- src/caoscrawler/identifiable.py | 7 +++++-- unittests/test_identifiable.py | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/caoscrawler/identifiable.py b/src/caoscrawler/identifiable.py index 56c023e2..5b2b2152 100644 --- a/src/caoscrawler/identifiable.py +++ b/src/caoscrawler/identifiable.py @@ -49,10 +49,13 @@ class Identifiable(): def __init__(self, record_id: int = None, path: str = None, record_type: str = None, name: str = None, properties: dict = None, backrefs: list[Union[int, str]] = None): - if (record_id is None and path is None and name is None and backrefs is None and (properties - is None or len(properties) == 0)): + if (record_id is None and path is None and name is None and backrefs is None and ( + properties is None or len(properties) == 0)): raise ValueError("There is no identifying information. You need to add a path or " "properties or other identifying attributes.") + if properties is not None and 'name' in [k.lower() for k in properties.keys()]: + raise ValueError("Please use the separete 'name' keyword instead of the properties " + "dict for name") self.record_id = record_id self.path = path self.record_type = record_type diff --git a/unittests/test_identifiable.py b/unittests/test_identifiable.py index 4c695d6f..c06ef0ec 100644 --- a/unittests/test_identifiable.py +++ b/unittests/test_identifiable.py @@ -24,6 +24,7 @@ test identifiable module """ +import pytest import caosdb as db from caoscrawler.identifiable import Identifiable from caoscrawler.identified_cache import IdentifiedCache @@ -59,6 +60,11 @@ def test_create_hashable_string(): Identifiable(record_type="B", properties={'a': [db.Record()]}))) +def test_name(): + with pytest.raises(ValueError): + Identifiable(properties={"Name": 'li'}) + + def test_equality(): assert Identifiable( record_id=12, properties={"a": 0}) == Identifiable(record_id=12, properties={"a": 1}) -- GitLab