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

MAINT: do not allow empty identifiables

parent 648782cf
No related branches found
No related tags found
2 merge requests!91Release 0.3,!67MAINT: introduce an identifiable class
Pipeline #30750 passed
......@@ -109,9 +109,11 @@ def crawler_extended(ident):
def test_ambigious_lookup(clear_database, usemodel, crawler, ident):
ins, ups = crawler.synchronize()
proj = db.execute_query("FIND Project WITH identifier='SpeedOfLight'", unique=True)
with pytest.raises(RuntimeError, match=".*unambigiously.*"):
print(crawler.identifiableAdapter.retrieve_identified_record_for_identifiable(
Identifiable(record_type="Measurement")))
Identifiable(properties={'project': proj.id})))
def test_single_insertion(clear_database, usemodel, crawler, ident):
......
......@@ -49,6 +49,10 @@ 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)):
raise ValueError("There is no identifying information. You need to add a path or "
"properties or other identifying attributes.")
self.record_id = record_id
self.path = path
self.record_type = record_type
......
......@@ -8,19 +8,27 @@ import pytest
from pytest import raises
from caoscrawler.identifiable_adapters import LocalStorageIdentifiableAdapter
from caoscrawler.identifiable import Identifiable
def test_file_identifiable():
ident = LocalStorageIdentifiableAdapter()
# Without a path there is no identifying information
with raises(ValueError):
ident.get_identifiable(db.File())
fp = "/test/bla/bla.txt"
file_obj = db.File(path=fp)
identifiable = ident.get_identifiable(file_obj)
# the path is copied to the identifiable
assert fp == identifiable.path
assert isinstance(identifiable, Identifiable)
# __eq__ function is only defined for Identifiable objects
with raises(ValueError):
file_obj != identifiable
assert file_obj.path == identifiable.path
# since the path does not exist in the data in ident, the follwoing functions return None
assert ident.retrieve_identified_record_for_record(file_obj) is None
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment