diff --git a/unittests/test_crawler.py b/unittests/test_crawler.py index 1722ec0fe3291d6e96042870d65af4e249671e82..743a3c64b37ede0abab474f126f4cc078f3415ca 100644 --- a/unittests/test_crawler.py +++ b/unittests/test_crawler.py @@ -84,7 +84,7 @@ NEW_ELEMENT = (db.Record() .add_property(name="result", value="homogeneous")) -def mock_get_entity_by(eid=None, name=None): +def mock_get_entity_by(eid=None, name=None, path=None): if eid is not None: candidates = [el for el in EXAMPLE_SERVER_STATE if el.id == eid] if len(candidates) > 0: @@ -98,6 +98,13 @@ def mock_get_entity_by(eid=None, name=None): return candidates[0] else: raise EmptyUniqueQueryError("") + if path is not None: + candidates = [el for el in EXAMPLE_SERVER_STATE + if (el.path is not None and el.path == path)] + if len(candidates) > 0: + return candidates[0] + else: + raise EmptyUniqueQueryError("") @pytest.fixture(autouse=True) diff --git a/unittests/test_file_identifiables.py b/unittests/test_file_identifiables.py index 8c633189ec0ac0553679981562d65cc10884f6b6..2852b40ffde98180d5dd7b11b9109cc5875502da 100644 --- a/unittests/test_file_identifiables.py +++ b/unittests/test_file_identifiables.py @@ -12,22 +12,14 @@ from caosdb.cached import cache_clear from caosdb.exceptions import EmptyUniqueQueryError from pytest import raises +from test_crawler import mock_get_entity_by + @pytest.fixture(autouse=True) def clear_cache(): cache_clear() -def mock_get_entity_by(eid=None, name=None, path=None): - if eid is not None: - candidates = [el for el in EXAMPLE_SERVER_STATE if el.id == eid] - if len(candidates) > 0: - return candidates[0] - else: - raise EmptyUniqueQueryError("") - raise EmptyUniqueQueryError("") - - @patch("caoscrawler.identifiable_adapters.cached_get_entity_by", new=Mock(side_effect=mock_get_entity_by)) def test_file_identifiable():