From 3f722aad7c480a59ba73273f4dba1d87dd95ca0b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com>
Date: Sun, 13 Nov 2022 16:26:39 +0100
Subject: [PATCH] tests

---
 src/caoscrawler/identifiable_adapters.py |  3 --
 unittests/test_file_identifiables.py     | 51 +++++-------------------
 2 files changed, 11 insertions(+), 43 deletions(-)

diff --git a/src/caoscrawler/identifiable_adapters.py b/src/caoscrawler/identifiable_adapters.py
index 29dd97ff..d06d5ca5 100644
--- a/src/caoscrawler/identifiable_adapters.py
+++ b/src/caoscrawler/identifiable_adapters.py
@@ -229,9 +229,6 @@ class IdentifiableAdapter(metaclass=ABCMeta):
         """
         identifiable = self.get_identifiable(record)
 
-        if identifiable is None:
-            return None
-
         if identifiable.path is not None:
             return self.get_file(identifiable)
 
diff --git a/unittests/test_file_identifiables.py b/unittests/test_file_identifiables.py
index 19796ffe..caa2572d 100644
--- a/unittests/test_file_identifiables.py
+++ b/unittests/test_file_identifiables.py
@@ -10,62 +10,33 @@ from pytest import raises
 from caoscrawler.identifiable_adapters import LocalStorageIdentifiableAdapter
 
 
-@pytest.mark.xfail()
 def test_file_identifiable():
     ident = LocalStorageIdentifiableAdapter()
-    file_obj = db.File()
 
+    fp = "/test/bla/bla.txt"
+    file_obj = db.File(path=fp)
     identifiable = ident.get_identifiable(file_obj)
-    identifiable2 = ident.get_identifiable(file_obj)
 
-    # these are two different objects:
-    assert identifiable != identifiable2
-    assert file_obj != identifiable
-    # ... but the path is equal:
-    assert identifiable.path == identifiable2.path
-    # ... and very boring:
-    assert identifiable.path is None
-    # Test functionality of retrieving the files:
-    identified_file = ident.get_file(identifiable)
-    identified_file2 = ident.get_file(file_obj)
-    # The both should be None currently as there are no files in the local store yet:
-    assert identified_file is None
-    assert identified_file2 is None
-
-    # Let's make it more interesting:
-    file_obj.path = "/test/bla/bla.txt"
-    file_obj._checksum = "abcd"
-    identifiable = ident.get_identifiable(file_obj)
+    # the path is copied to the identifiable
     assert file_obj != identifiable
     assert file_obj.path == identifiable.path
-    # Checksum is not part of the identifiable:
-    assert file_obj.checksum != identifiable.checksum
 
-    # This is the wrong method, so it should definitely return None:
-    identified_file = ident.retrieve_identified_record_for_identifiable(
-        identifiable)
-    assert identified_file is None
-    # This is the correct method to use:
-    identified_file = ident.get_file(identifiable)
-    # or directly using:
-    identified_file2 = ident.get_file(file_obj)
-    # The both should be None currently as there are no files in the local store yet:
-    assert identified_file is None
-    assert identified_file2 is None
+    # 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
+    assert ident.get_file(identifiable) is None
 
     # Try again with actual files in the store:
     records = ident.get_records()
-    test_record_wrong_path = db.File(
-        path="/bla/bla/test.txt")
-    test_record_correct_path = db.File(
-        path="/test/bla/bla.txt")
-    test_record_alsocorrect_path = db.File(
-        path="/test/bla/bla.txt")
+    test_record_wrong_path = db.File(path="/bla/bla/test.txt")
+    test_record_correct_path = db.File(path="/test/bla/bla.txt")
+    test_record_alsocorrect_path = db.File(path="/test/bla/bla.txt")
     records.append(test_record_wrong_path)
+    # Now, there is a file, but still wrong path -> result is still None
     identified_file = ident.get_file(file_obj)
     assert identified_file is None
 
     records.append(test_record_correct_path)
+    # now there is a match
     identified_file = ident.get_file(file_obj)
     assert identified_file is not None
     assert identified_file.path == file_obj.path
-- 
GitLab