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

MAINT: reuse code

parent 8404dd9e
No related branches found
No related tags found
2 merge requests!123REL: Release v0.6.0,!113F refactor test tool
Pipeline #36644 passed
......@@ -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)
......
......@@ -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():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment