diff --git a/src/caoscrawler/identifiable.py b/src/caoscrawler/identifiable.py index 56c023e25d4ff319de61db2989a6cf1d27f5631a..5b2b215263b0edc7817c18ad9eecf85ad648f10f 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 4c695d6f8ea7f3887972833dd75be5c7071dace3..c06ef0ec4b0ab7a91e0397884d95a9e496240df2 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})