Skip to content

Commit 179ac90

Browse files
author
Andrei Neagu
committed
fixed test
1 parent 696ff79 commit 179ac90

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

services/dynamic-scheduler/tests/unit/api_frontend/conftest.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import subprocess
66
from collections.abc import AsyncIterable
77
from contextlib import suppress
8+
from typing import Final
9+
from unittest.mock import AsyncMock
810

911
import pytest
1012
from fastapi import FastAPI, status
@@ -16,15 +18,36 @@
1618
from pytest_simcore.helpers.typing_env import EnvVarsDict
1719
from settings_library.rabbit import RabbitSettings
1820
from settings_library.redis import RedisSettings
21+
from settings_library.utils_service import DEFAULT_FASTAPI_PORT
1922
from simcore_service_dynamic_scheduler.core.application import create_app
2023
from tenacity import AsyncRetrying, stop_after_delay, wait_fixed
2124

25+
_MODULE: Final["str"] = "simcore_service_dynamic_scheduler"
26+
2227

2328
@pytest.fixture
2429
def disable_status_monitor_background_task(mocker: MockerFixture) -> None:
2530
mocker.patch(
26-
"simcore_service_dynamic_scheduler.services.status_monitor._monitor.Monitor._worker_check_services_require_status_update"
31+
f"{_MODULE}.services.status_monitor._monitor.Monitor._worker_check_services_require_status_update"
32+
)
33+
34+
35+
@pytest.fixture
36+
def mock_stop_dynamic_service(mocker: MockerFixture) -> AsyncMock:
37+
async_mock = AsyncMock()
38+
mocker.patch(
39+
f"{_MODULE}.api.frontend.routes._service.stop_dynamic_service", async_mock
40+
)
41+
return async_mock
42+
43+
44+
@pytest.fixture
45+
def mock_remove_tracked_service(mocker: MockerFixture) -> AsyncMock:
46+
async_mock = AsyncMock()
47+
mocker.patch(
48+
f"{_MODULE}.api.frontend.routes._service.remove_tracked_service", async_mock
2749
)
50+
return async_mock
2851

2952

3053
@pytest.fixture
@@ -40,7 +63,7 @@ def app_environment(
4063

4164
@pytest.fixture
4265
def server_host_port() -> str:
43-
return "127.0.0.1:7456"
66+
return f"127.0.0.1:{DEFAULT_FASTAPI_PORT}"
4467

4568

4669
@pytest.fixture

services/dynamic-scheduler/tests/unit/api_frontend/test_api_frontend_routes_index.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# pylint:disable=unused-argument
33

44
from collections.abc import Callable
5+
from unittest.mock import AsyncMock
56
from uuid import uuid4
67

78
import pytest
@@ -21,6 +22,7 @@
2122
set_request_as_running,
2223
set_request_as_stopped,
2324
)
25+
from tenacity import AsyncRetrying, stop_after_delay, wait_fixed
2426

2527
pytest_simcore_core_services_selection = [
2628
"rabbit",
@@ -89,6 +91,7 @@ async def test_main_page(
8991
service_status: NodeGet | DynamicServiceGet,
9092
not_initialized_app: FastAPI,
9193
get_dynamic_service_start: Callable[[NodeID], DynamicServiceStart],
94+
mock_stop_dynamic_service: AsyncMock,
9295
):
9396
await async_page.goto(server_host_port)
9497

@@ -124,6 +127,11 @@ async def test_main_page(
124127
await assert_contains_text(
125128
async_page, "The service will be stopped and its data will be saved"
126129
)
127-
await click_on_text(async_page, "Stop Now")
128130

129-
# TODO: assert called on backend
131+
mock_stop_dynamic_service.assert_not_awaited()
132+
await click_on_text(async_page, "Stop Now")
133+
async for attempt in AsyncRetrying(
134+
reraise=True, wait=wait_fixed(0.1), stop=stop_after_delay(3)
135+
):
136+
with attempt:
137+
mock_stop_dynamic_service.assert_awaited_once()

0 commit comments

Comments
 (0)