Skip to content
Snippets Groups Projects
Commit 8ad58963 authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

MAINT: do not allow name in properties

parent 4edb80e6
No related branches found
No related tags found
2 merge requests!91Release 0.3,!67MAINT: introduce an identifiable class
Pipeline #30764 passed
...@@ -49,10 +49,13 @@ class Identifiable(): ...@@ -49,10 +49,13 @@ class Identifiable():
def __init__(self, record_id: int = None, path: str = None, record_type: str = None, def __init__(self, record_id: int = None, path: str = None, record_type: str = None,
name: str = None, properties: dict = None, name: str = None, properties: dict = None,
backrefs: list[Union[int, str]] = 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 if (record_id is None and path is None and name is None and backrefs is None and (
is None or len(properties) == 0)): properties is None or len(properties) == 0)):
raise ValueError("There is no identifying information. You need to add a path or " raise ValueError("There is no identifying information. You need to add a path or "
"properties or other identifying attributes.") "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.record_id = record_id
self.path = path self.path = path
self.record_type = record_type self.record_type = record_type
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
test identifiable module test identifiable module
""" """
import pytest
import caosdb as db import caosdb as db
from caoscrawler.identifiable import Identifiable from caoscrawler.identifiable import Identifiable
from caoscrawler.identified_cache import IdentifiedCache from caoscrawler.identified_cache import IdentifiedCache
...@@ -59,6 +60,11 @@ def test_create_hashable_string(): ...@@ -59,6 +60,11 @@ def test_create_hashable_string():
Identifiable(record_type="B", properties={'a': [db.Record()]}))) Identifiable(record_type="B", properties={'a': [db.Record()]})))
def test_name():
with pytest.raises(ValueError):
Identifiable(properties={"Name": 'li'})
def test_equality(): def test_equality():
assert Identifiable( assert Identifiable(
record_id=12, properties={"a": 0}) == Identifiable(record_id=12, properties={"a": 1}) record_id=12, properties={"a": 0}) == Identifiable(record_id=12, properties={"a": 1})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment