Skip to content
Snippets Groups Projects
Commit f2a24be0 authored by Alexander Schlemmer's avatar Alexander Schlemmer
Browse files

TST: added unit test for file identifiables

parent a9cfd002
No related branches found
No related tags found
1 merge request!53Release 0.1
......@@ -214,6 +214,8 @@ class IdentifiableAdapter(metaclass=ABCMeta):
This function will return None if there is either no identifiable registered
or no corresponding identified record in the database for a given record.
Warning: this function is not expected to work correctly for file identifiables.
"""
pass
......@@ -253,6 +255,9 @@ class LocalStorageIdentifiableAdapter(IdentifiableAdapter):
def get_records(self):
return self._records
def get_file(self, identifiable: db.File):
raise NotImplementedError()
def store_state(self, filename):
with open(filename, "w") as f:
f.write(db.common.utils.xml2str(db.Container().extend(self._records).to_xml()))
......@@ -331,7 +336,7 @@ class LocalStorageIdentifiableAdapter(IdentifiableAdapter):
return False
return True
def retrieve_identified_record(self, identifiable: db.Record):
def retrieve_identified_record_for_identifiable(self, identifiable: db.Record):
candidates = []
for record in self._records:
if self.check_record(record, identifiable):
......
#!/bin/python
# Tests for file identifiables
# A. Schlemmer, 06/2021
import caosdb as db
import pytest
from pytest import raises
from newcrawler.identifiable_adapters import LocalStorageIdentifiableAdapter
def test_file_identifiable():
ident = LocalStorageIdentifiableAdapter()
file_obj = db.File()
identifiable = ident.get_identifiable(file_obj)
identifiable2 = ident.get_identifiable_for_file(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
# TODO: test for corresponding retrieval "get_file"
# Let's make it more interesting:
file_obj.path = "/test/bla/bla.txt"
file_obj._checksum = "abcd"
identifiable = ident.get_identifiable(file_obj)
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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment