Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle committed Dec 20, 2024
1 parent 29f872c commit 6a2274a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
1 change: 0 additions & 1 deletion antarest/study/storage/explorer_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# This file is part of the Antares project.

import logging
import os
from typing import List

from antarest.core.config import Config
Expand Down
34 changes: 22 additions & 12 deletions tests/storage/business/test_explorer_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# This file is part of the Antares project.

from pathlib import Path
from unittest.mock import patch

import pytest

Expand All @@ -23,17 +24,9 @@ def build_config(root: Path) -> Config:
return Config(
storage=StorageConfig(
workspaces={
DEFAULT_WORKSPACE_NAME: WorkspaceConfig(path=root / DEFAULT_WORKSPACE_NAME, groups=["toto"]),
"diese": WorkspaceConfig(
path=root / "diese",
groups=["tata"],
filter_out=["to_skip.*"],
),
"test": WorkspaceConfig(
path=root / "test",
groups=["toto"],
filter_out=["to_skip.*"],
),
DEFAULT_WORKSPACE_NAME: WorkspaceConfig(path=root / DEFAULT_WORKSPACE_NAME),
"diese": WorkspaceConfig(path=root / "diese"),
"test": WorkspaceConfig(path=root / "test"),
}
)
)
Expand Down Expand Up @@ -74,6 +67,14 @@ def config_scenario_a(tmp_path: Path) -> Config:
(f / "AW_NO_SCAN").touch()
(f / "study.antares").touch()

d = diese / ".git"
d.mkdir(parents=True)
(d / "config.txt").touch()

d = diese / "$RECYCLE.bin"
d.mkdir(parents=True)
(d / "trash").touch()

config = build_config(tmp_path)

return config
Expand All @@ -84,7 +85,7 @@ def test_list_dir_empty_string(config_scenario_a: Config):
explorer = Explorer(config_scenario_a)
result = explorer.list_dir("diese", "")

assert len(result) == 1
assert len(result) == 1 # we don't want to see the .git folder or the $RECYCLE.BIN
assert result[0] == NonStudyFolderDTO(path=Path("folder"), workspace="diese", name="folder")


Expand All @@ -108,6 +109,15 @@ def test_list_dir_in_empty_folder(config_scenario_a: Config):
assert len(result) == 0


@pytest.mark.unit_test
def test_list_dir_with_permission_error(config_scenario_a: Config):
explorer = Explorer(config_scenario_a)
with patch("os.listdir", side_effect=PermissionError("Permission denied")):
# asserts the endpoint doesn't fail but rather returns an empty list
result = explorer.list_dir("diese", "folder")
assert len(result) == 0


@pytest.mark.unit_test
def test_list_workspaces(tmp_path: Path):
config = build_config(tmp_path)
Expand Down

0 comments on commit 6a2274a

Please sign in to comment.