def build_storage_service(
            study_factory=Mock(),
            exporter=Mock(),
            session=Mock(),
            path_studies=Path(),
            path_resources=Path(),
            user_service=Mock(),
    ) -> StorageService:

        config = Config(
            resources_path=path_resources,
            security=SecurityConfig(disabled=True),
            storage=StorageConfig(
                workspaces={
                    DEFAULT_WORKSPACE_NAME: WorkspaceConfig(path=path_studies)
                }),
        )

        return build_storage(
            application=Mock(),
            config=config,
            session=session,
            user_service=user_service,
            study_factory=study_factory,
            exporter=exporter,
        )
def test_exporter_file(tmp_path: Path, sta_mini_zip_path: Path):

    path_studies = tmp_path / "studies"

    with ZipFile(sta_mini_zip_path) as zip_output:
        zip_output.extractall(path=path_studies)

    config = Config(
        resources_path=Path(),
        security=SecurityConfig(disabled=True),
        storage=StorageConfig(
            workspaces={
                DEFAULT_WORKSPACE_NAME: WorkspaceConfig(path=path_studies)
            }
        ),
    )

    md = RawStudy(
        id="STA-mini",
        workspace=DEFAULT_WORKSPACE_NAME,
        path=str(path_studies / "STA-mini"),
    )
    repo = Mock()
    repo.get.return_value = md

    service = build_storage(
        application=Mock(),
        config=config,
        session=Mock(),
        user_service=Mock(),
        metadata_repository=repo,
    )

    data = assert_url_content(service, url="/studies/STA-mini/export")
    assert_data(data)
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"]),
        }))
Exemple #4
0
def storage_service(tmp_path: str, project_path: Path,
                    sta_mini_zip_path: Path) -> StorageService:

    path_studies = Path(tmp_path) / "studies"

    path_resources = project_path / "resources"

    with ZipFile(sta_mini_zip_path) as zip_output:
        zip_output.extractall(path=path_studies)

    md = RawStudy(
        id="STA-mini",
        workspace=DEFAULT_WORKSPACE_NAME,
        path=str(path_studies / "STA-mini"),
    )
    repo = Mock()
    repo.get.side_effect = lambda name: RawStudy(
        id=name,
        workspace=DEFAULT_WORKSPACE_NAME,
        path=str(path_studies / name),
    )
    repo.get_all.return_value = [md]

    config = Config(
        resources_path=path_resources,
        security=SecurityConfig(disabled=True),
        storage=StorageConfig(
            workspaces={
                DEFAULT_WORKSPACE_NAME: WorkspaceConfig(path=path_studies)
            }),
    )

    storage_service = build_storage(
        application=Mock(),
        session=Mock(),
        user_service=Mock(),
        config=config,
        metadata_repository=repo,
    )

    return storage_service
Exemple #5
0
def build_config(study_path: Path):
    return Config(storage=StorageConfig(
        workspaces={DEFAULT_WORKSPACE_NAME: WorkspaceConfig(path=study_path)}))
from antarest import __version__
from antarest.common.config import (
    Config,
    SecurityConfig,
    StorageConfig,
    WorkspaceConfig,
)
from antarest.storage.main import build_storage
from antarest.storage.model import DEFAULT_WORKSPACE_NAME


CONFIG = Config(
    resources_path=Path(),
    security=SecurityConfig(disabled=True),
    storage=StorageConfig(
        workspaces={DEFAULT_WORKSPACE_NAME: WorkspaceConfig(path=Path())}
    ),
)


@pytest.mark.unit_test
def test_version() -> None:

    mock_storage_service = Mock()
    mock_storage_service.study_service.path_resources = Path("/")

    app = Flask(__name__)
    build_storage(
        app,
        storage_service=mock_storage_service,
        session=Mock(),