Skip to content

Commit 43d5749

Browse files
tests: group fixtures
1 parent 0761445 commit 43d5749

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

services/web/server/tests/unit/with_dbs/02/test_projects_conversations_handlers.py

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# pylint: disable=too-many-statements
77

88

9+
from collections.abc import Callable
910
from http import HTTPStatus
1011
from unittest.mock import MagicMock
1112

@@ -32,33 +33,14 @@
3233

3334

3435
@pytest.fixture
35-
def mocked_notify_conversation_message_created(
36-
mocker: MockerFixture,
37-
) -> MagicMock:
38-
return mocker.patch.object(
39-
simcore_service_webserver.conversations._conversation_message_service,
40-
"notify_conversation_message_created",
41-
)
36+
def mock_notify_function(mocker: MockerFixture) -> Callable[[str], MagicMock]:
37+
def _mock(function_name: str) -> MagicMock:
38+
return mocker.patch.object(
39+
simcore_service_webserver.conversations._conversation_message_service,
40+
function_name,
41+
)
4242

43-
44-
@pytest.fixture
45-
def mocked_notify_conversation_message_updated(
46-
mocker: MockerFixture,
47-
) -> MagicMock:
48-
return mocker.patch.object(
49-
simcore_service_webserver.conversations._conversation_message_service,
50-
"notify_conversation_message_updated",
51-
)
52-
53-
54-
@pytest.fixture
55-
def mocked_notify_conversation_message_deleted(
56-
mocker: MockerFixture,
57-
) -> MagicMock:
58-
return mocker.patch.object(
59-
simcore_service_webserver.conversations._conversation_message_service,
60-
"notify_conversation_message_deleted",
61-
)
43+
return _mock
6244

6345

6446
@pytest.mark.parametrize(
@@ -196,10 +178,18 @@ async def test_project_conversation_messages_full_workflow(
196178
user_project: ProjectDict,
197179
expected: HTTPStatus,
198180
postgres_db: sa.engine.Engine,
199-
mocked_notify_conversation_message_created: MagicMock,
200-
mocked_notify_conversation_message_updated: MagicMock,
201-
mocked_notify_conversation_message_deleted: MagicMock,
181+
mock_notify_function: Callable[[str], MagicMock],
202182
):
183+
mocked_notify_conversation_message_created = mock_notify_function(
184+
"notify_conversation_message_created"
185+
)
186+
mocked_notify_conversation_message_updated = mock_notify_function(
187+
"notify_conversation_message_updated"
188+
)
189+
mocked_notify_conversation_message_deleted = mock_notify_function(
190+
"notify_conversation_message_deleted"
191+
)
192+
203193
base_project_url = client.app.router["list_project_conversations"].url_for(
204194
project_id=user_project["uuid"]
205195
)

0 commit comments

Comments
 (0)