@@ -102,10 +102,28 @@ async def project_in_db(
102102 yield row
103103
104104
105+ # Create a mock object manually
106+ mock_with_locked_project = MagicMock ()
107+
108+
109+ # The stand-in decorator to replace the original one and record the function call
110+ def mock_decorator (* args , ** kwargs ):
111+ def _decorator (func ):
112+ def wrapper (* args , ** kwargs ):
113+ mock_with_locked_project (* args , ** kwargs ) # Log the call
114+ return func (* args , ** kwargs )
115+
116+ return wrapper
117+
118+ return _decorator
119+
120+
105121@patch ("simcore_service_efs_guardian.services.background_tasks.get_redis_lock_client" )
106- @patch ("simcore_service_efs_guardian.services.background_tasks.lock_project" )
122+ @patch (
123+ "simcore_service_efs_guardian.services.background_tasks.with_locked_project" ,
124+ new = mock_decorator ,
125+ )
107126async def test_efs_removal_policy_task (
108- mock_lock_project : MagicMock ,
109127 mock_get_redis_lock_client : MagicMock ,
110128 faker : Faker ,
111129 app : FastAPI ,
@@ -116,7 +134,7 @@ async def test_efs_removal_policy_task(
116134):
117135 # 1. Nothing should happen
118136 await removal_policy_task (app )
119- assert not mock_lock_project .called
137+ assert not mock_with_locked_project .called
120138
121139 # 2. Lets create some project with data
122140 aws_efs_settings : AwsEfsSettings = app .state .settings .EFS_GUARDIAN_AWS_EFS_SETTINGS
@@ -148,7 +166,7 @@ async def test_efs_removal_policy_task(
148166
149167 # 3. Nothing should happen
150168 await removal_policy_task (app )
151- assert not mock_lock_project .called
169+ assert not mock_with_locked_project .called
152170
153171 # 4. We will artifically change the project last change date
154172 app_settings : ApplicationSettings = app .state .settings
@@ -169,7 +187,7 @@ async def test_efs_removal_policy_task(
169187
170188 # 5. Now removal policy should remove those data
171189 await removal_policy_task (app )
172- assert mock_lock_project .assert_called_once
190+ assert mock_with_locked_project .assert_called_once
173191 assert mock_get_redis_lock_client .assert_called_once
174192 projects_list = await efs_manager .list_projects_across_whole_efs ()
175193 assert projects_list == []
0 commit comments