1212
1313import pytest
1414import simcore_service_webserver .conversations ._conversation_message_service
15+ import simcore_service_webserver .conversations ._conversation_service
1516import sqlalchemy as sa
1617from aiohttp .test_utils import TestClient
1718from models_library .api_schemas_webserver .projects_conversations import (
3334
3435
3536@pytest .fixture
36- def mock_notify_function (mocker : MockerFixture ) -> Callable [[str ], MagicMock ]:
37- def _mock (function_name : str ) -> MagicMock :
37+ def mock_notify_function (mocker : MockerFixture ) -> Callable [[object , str ], MagicMock ]:
38+ def _mock (target : object , function_name : str ) -> MagicMock :
3839 return mocker .patch .object (
39- simcore_service_webserver . conversations . _conversation_message_service ,
40+ target ,
4041 function_name ,
4142 )
4243
@@ -81,7 +82,21 @@ async def test_project_conversations_full_workflow(
8182 logged_user : UserInfoDict ,
8283 user_project : ProjectDict ,
8384 expected : HTTPStatus ,
85+ mock_notify_function : Callable [[object , str ], MagicMock ],
8486):
87+ mocked_notify_conversation_created = mock_notify_function (
88+ simcore_service_webserver .conversations ._conversation_service ,
89+ "notify_conversation_created" ,
90+ )
91+ mocked_notify_conversation_updated = mock_notify_function (
92+ simcore_service_webserver .conversations ._conversation_service ,
93+ "notify_conversation_updated" ,
94+ )
95+ mocked_notify_conversation_deleted = mock_notify_function (
96+ simcore_service_webserver .conversations ._conversation_service ,
97+ "notify_conversation_deleted" ,
98+ )
99+
85100 base_url = client .app .router ["list_project_conversations" ].url_for (
86101 project_id = user_project ["uuid" ]
87102 )
@@ -106,6 +121,12 @@ async def test_project_conversations_full_workflow(
106121 assert ConversationRestGet .model_validate (data )
107122 _first_conversation_id = data ["conversationId" ]
108123
124+ assert mocked_notify_conversation_created .call_count == 1
125+ kwargs = mocked_notify_conversation_created .call_args .kwargs
126+
127+ assert f"{ kwargs ['project_id' ]} " == user_project ["uuid" ]
128+ assert kwargs ["conversation" ].name == "My first conversation"
129+
109130 # Now we will create second conversation
110131 body = {"name" : "My conversation" , "type" : "PROJECT_ANNOTATION" }
111132 resp = await client .post (f"{ base_url } " , json = body )
@@ -115,6 +136,12 @@ async def test_project_conversations_full_workflow(
115136 )
116137 assert ConversationRestGet .model_validate (data )
117138
139+ assert mocked_notify_conversation_created .call_count == 2
140+ kwargs = mocked_notify_conversation_created .call_args .kwargs
141+
142+ assert f"{ kwargs ['project_id' ]} " == user_project ["uuid" ]
143+ assert kwargs ["conversation" ].name == "My conversation"
144+
118145 # Now we will list all conversations for the project
119146 resp = await client .get (f"{ base_url } " )
120147 data , _ , meta , links = await assert_status (
@@ -145,13 +172,24 @@ async def test_project_conversations_full_workflow(
145172 )
146173 assert data ["name" ] == updated_name
147174
175+ assert mocked_notify_conversation_updated .call_count == 1
176+ kwargs = mocked_notify_conversation_updated .call_args .kwargs
177+
178+ assert f"{ kwargs ['project_id' ]} " == user_project ["uuid" ]
179+ assert kwargs ["conversation" ].name == updated_name
180+
148181 # Now we will delete the first conversation
149182 resp = await client .delete (f"{ base_url } /{ _first_conversation_id } " )
150183 data , _ = await assert_status (
151184 resp ,
152185 status .HTTP_204_NO_CONTENT ,
153186 )
154187
188+ assert mocked_notify_conversation_deleted .call_count == 1
189+ kwargs = mocked_notify_conversation_deleted .call_args .kwargs
190+
191+ assert kwargs ["conversation" ].conversation_id == _first_conversation_id
192+
155193 # Now we will list all conversations for the project
156194 resp = await client .get (f"{ base_url } " )
157195 data , _ , meta = await assert_status (
@@ -178,16 +216,19 @@ async def test_project_conversation_messages_full_workflow(
178216 user_project : ProjectDict ,
179217 expected : HTTPStatus ,
180218 postgres_db : sa .engine .Engine ,
181- mock_notify_function : Callable [[str ], MagicMock ],
219+ mock_notify_function : Callable [[object , str ], MagicMock ],
182220):
183221 mocked_notify_conversation_message_created = mock_notify_function (
184- "notify_conversation_message_created"
222+ simcore_service_webserver .conversations ._conversation_message_service ,
223+ "notify_conversation_message_created" ,
185224 )
186225 mocked_notify_conversation_message_updated = mock_notify_function (
187- "notify_conversation_message_updated"
226+ simcore_service_webserver .conversations ._conversation_message_service ,
227+ "notify_conversation_message_updated" ,
188228 )
189229 mocked_notify_conversation_message_deleted = mock_notify_function (
190- "notify_conversation_message_deleted"
230+ simcore_service_webserver .conversations ._conversation_message_service ,
231+ "notify_conversation_message_deleted" ,
191232 )
192233
193234 base_project_url = client .app .router ["list_project_conversations" ].url_for (
0 commit comments