Skip to content

Commit

Permalink
test(backends): exception when deleting outside localbackend dir
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlougheed committed Apr 16, 2024
1 parent 7d4a1d2 commit 41b6985
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
15 changes: 10 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,20 @@ def client_minio() -> FlaskClient:


@pytest.fixture
def client_local() -> FlaskClient:
def local_volume():
local_test_volume = (pathlib.Path(__file__).parent / "data").absolute()
local_test_volume.mkdir(parents=True, exist_ok=True)

yield local_test_volume

# clear test volume
shutil.rmtree(local_test_volume)


@pytest.fixture
def client_local(local_volume: pathlib.Path) -> FlaskClient:
os.environ["BENTO_AUTHZ_SERVICE_URL"] = AUTHZ_URL
os.environ["DATA"] = str(local_test_volume)
os.environ["DATA"] = str(local_volume)

from chord_drs.app import application, db

Expand All @@ -93,9 +101,6 @@ def client_local() -> FlaskClient:
db.session.remove()
db.drop_all()

# clear test volume
shutil.rmtree(local_test_volume)


@pytest.fixture(params=[lazy_fixture("client_minio"), lazy_fixture("client_local")])
def client(request) -> FlaskClient:
Expand Down
24 changes: 24 additions & 0 deletions tests/test_backends.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import pathlib
import pytest

from chord_drs.backends.local import LocalBackend


def test_local_backend(local_volume):
backend = LocalBackend({"SERVICE_DATA": str(local_volume)})

file_to_ingest = pathlib.Path(__file__).parent / "dummy_file.txt"

backend.save(file_to_ingest, "dummy_file.txt")
assert (local_volume / "dummy_file.txt").exists()

backend.delete(local_volume / "dummy_file.txt")
assert not (local_volume / "dummy_file.txt").exists()


def test_local_backend_raises(local_volume):
backend = LocalBackend({"SERVICE_DATA": str(local_volume)})

with pytest.raises(ValueError):
# before we can even figure out file does not exist, this is not a local volume subpath:
backend.delete("/tmp/does_not_exist.txt")

0 comments on commit 41b6985

Please sign in to comment.