From 5f0e15af7c046eb99910972d3c3c82d2ed23d101 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Tue, 25 Jul 2023 11:45:48 +0200 Subject: [PATCH] feat(watcher): scanning a managed workspace only logs a warning msg --- antarest/study/storage/rawstudy/watcher.py | 5 +++- tests/integration/test_integration_watcher.py | 30 +++++++++++++------ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/antarest/study/storage/rawstudy/watcher.py b/antarest/study/storage/rawstudy/watcher.py index 0d6e85045b..05ff203d88 100644 --- a/antarest/study/storage/rawstudy/watcher.py +++ b/antarest/study/storage/rawstudy/watcher.py @@ -179,7 +179,10 @@ def oneshot_scan( """ def scan_task(notifier: TaskUpdateNotifier) -> TaskResult: - self.scan(workspace, path) + try: + self.scan(workspace, path) + except CannotScanInternalWorkspace as e: + logger.warning(e) return TaskResult(success=True, message="Scan completed") return self.task_service.add_task( diff --git a/tests/integration/test_integration_watcher.py b/tests/integration/test_integration_watcher.py index b5da0a2d18..ac115755ce 100644 --- a/tests/integration/test_integration_watcher.py +++ b/tests/integration/test_integration_watcher.py @@ -1,20 +1,32 @@ from fastapi import FastAPI from starlette.testclient import TestClient +from antarest.core.tasks.model import TaskStatus -def test_integration_xpansion(app: FastAPI, tmp_path: str): - client = TestClient(app, raise_server_exceptions=False) + +def test_integration_watcher(app: FastAPI, tmp_path: str): + client = TestClient(app) res = client.post( "/v1/login", json={"username": "admin", "password": "admin"} ) admin_credentials = res.json() headers = {"Authorization": f'Bearer {admin_credentials["access_token"]}'} - client.post( - f"/v1/watcher/_scan", - headers=headers, - ) - client.post( - f"/v1/watcher/_scan?path=/tmp", + res = client.post("/v1/watcher/_scan", headers=headers) + assert res.status_code == 422 + assert res.json() == { + "description": "field required", + "exception": "RequestValidationError", + "body": None, + } + + task_id = client.post( + "/v1/watcher/_scan?path=/default", headers=headers, - ) + ).json() + + # asserts that scanning default workspace doesn't fail + res = client.get( + f"v1/tasks/{task_id}?wait_for_completion=true", headers=headers + ).json() + assert res["status"] == TaskStatus.COMPLETED.value