From 648782cf1854c1549e456bd6133c3bb5affb6c36 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 10:57:32 +0100
Subject: [PATCH] TST: teset ambigious identifiable query

---
 integrationtests/basic_example/test_basic.py |  8 ++++++++
 unittests/test_identifiable.py               | 17 +++++++++++++++++
 unittests/test_identified_cache.py           |  3 ---
 unittests/test_tool.py                       |  9 ++++-----
 4 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/integrationtests/basic_example/test_basic.py b/integrationtests/basic_example/test_basic.py
index a4261cd9..dbc506ef 100755
--- a/integrationtests/basic_example/test_basic.py
+++ b/integrationtests/basic_example/test_basic.py
@@ -33,6 +33,7 @@ import argparse
 import sys
 from argparse import RawTextHelpFormatter
 from caoscrawler import Crawler, SecurityMode
+from caoscrawler.identifiable import Identifiable
 import caosdb as db
 from caoscrawler.identifiable_adapters import CaosDBIdentifiableAdapter
 import pytest
@@ -106,6 +107,13 @@ def crawler_extended(ident):
     return cr
 
 
+def test_ambigious_lookup(clear_database, usemodel, crawler, ident):
+    ins, ups = crawler.synchronize()
+    with pytest.raises(RuntimeError, match=".*unambigiously.*"):
+        print(crawler.identifiableAdapter.retrieve_identified_record_for_identifiable(
+            Identifiable(record_type="Measurement")))
+
+
 def test_single_insertion(clear_database, usemodel, crawler, ident):
     ins, ups = crawler.synchronize()
 
diff --git a/unittests/test_identifiable.py b/unittests/test_identifiable.py
index ab33edea..4c695d6f 100644
--- a/unittests/test_identifiable.py
+++ b/unittests/test_identifiable.py
@@ -57,3 +57,20 @@ def test_create_hashable_string():
             Identifiable(record_type="B", properties={'a': [db.Record()]})
         ) != Identifiable._create_hashable_string(
             Identifiable(record_type="B", properties={'a': [db.Record()]})))
+
+
+def test_equality():
+    assert Identifiable(
+        record_id=12, properties={"a": 0}) == Identifiable(record_id=12, properties={"a": 1})
+    assert Identifiable(
+        record_id=12, properties={"a": 0}) != Identifiable(record_id=13, properties={"a": 0})
+    assert Identifiable(
+        record_id=12, properties={"a": 0}) == Identifiable(properties={"a": 0})
+    assert Identifiable(
+        path="a", properties={"a": 0}) != Identifiable(path="b", properties={"a": 0})
+    assert Identifiable(
+        path="a", properties={"a": 0}) == Identifiable(path="a", properties={"a": 1})
+    assert Identifiable(
+        path="a", properties={"a": 0}) == Identifiable(properties={"a": 0})
+    assert Identifiable(properties={"a": 0}) == Identifiable(properties={"a": 0})
+    assert Identifiable(properties={"a": 0}) != Identifiable(properties={"a": 1})
diff --git a/unittests/test_identified_cache.py b/unittests/test_identified_cache.py
index f6edbdfa..4ed7c55c 100644
--- a/unittests/test_identified_cache.py
+++ b/unittests/test_identified_cache.py
@@ -32,9 +32,6 @@ from caoscrawler.identifiable import Identifiable
 from caoscrawler.identified_cache import IdentifiedCache
 
 
-def test_create_hash():
-
-
 def test_IdentifiedCache():
     ident = Identifiable(name="A", record_type="B")
     record = db.Record("A").add_parent("B").add_property('b', 5)
diff --git a/unittests/test_tool.py b/unittests/test_tool.py
index f81ee2fa..429265f5 100755
--- a/unittests/test_tool.py
+++ b/unittests/test_tool.py
@@ -334,6 +334,10 @@ def test_provenance_debug_data(crawler):
     assert check_key_count("Person") == 14
 
 
+def test_split_into_inserts_and_updates_trivial(crawler):
+    crawler.split_into_inserts_and_updates([])
+
+
 def basic_retrieve_by_name_mock_up(rec, known):
     """ returns a stored Record if rec.name is an existing key, None otherwise """
     if rec.name in known:
@@ -358,11 +362,6 @@ def crawler_mocked_identifiable_retrieve(crawler):
     return crawler
 
 
-def test_split_into_inserts_and_updates_trivial(crawler):
-    # Try trivial argument
-    crawler.split_into_inserts_and_updates([])
-
-
 def test_split_into_inserts_and_updates_single(crawler_mocked_identifiable_retrieve):
     crawler = crawler_mocked_identifiable_retrieve
     identlist = [Identifiable(name="A", record_type="C"), Identifiable(name="B", record_type="C")]
-- 
GitLab