ソースを参照

Fix unit tests

mock.has_calls is not a valid assertion, Python 3.12 now
rejects it. We'll use the proper "assert_has_calls"
method.

Note that a few "assert_has_calls" assertion fail because
the magic mocks returned by "mock.patch.object" are also recording
accessed attributes of returned values, e.g.:
    a = mock.Mock()
    b = a()
    b.id  # Recorded as a().id call unless we use mock.Mock
Lucian Petrut 1 ヶ月 前
コミット
917d9c3ee4

+ 1 - 1
coriolis/tests/api/v1/test_endpoint_destination_minion_pool_options.py

@@ -57,7 +57,7 @@ class EndpointDestinationMinionPoolOptionsControllerTestCase(
 
         mock_context.can.assert_called_once_with(
             'migration:endpoints:list_destination_minion_pool_options')
-        mock_decode_base64_param.has_calls(expected_calls)
+        mock_decode_base64_param.assert_has_calls(expected_calls)
         (mock_get_endpoint_destination_minion_pool_options.
             assert_called_once_with)(
                 mock_context, endpoint_id,

+ 1 - 1
coriolis/tests/api/v1/test_endpoint_instances.py

@@ -120,7 +120,7 @@ class EndpointInstanceControllerTestCase(test_base.CoriolisBaseTestCase):
 
         mock_context.can.assert_called_once_with(
             'migration:endpoints:get_instance')
-        mock_decode_base64_param.has_calls(expected_calls)
+        mock_decode_base64_param.assert_has_calls(expected_calls)
         mock_get_endpoint_instance.assert_called_once_with(
             mock_context, endpoint_id,
             env,

+ 1 - 1
coriolis/tests/api/v1/test_endpoint_source_minion_pool_options.py

@@ -52,7 +52,7 @@ class EndpointSourceMinionPoolOptionsControllerTestCase(
 
         mock_context.can.assert_called_once_with(
             'migration:endpoints:list_source_minion_pool_options')
-        mock_decode_base64_param.has_calls(expected_calls)
+        mock_decode_base64_param.assert_has_calls(expected_calls)
         (mock_get_endpoint_source_minion_pool_options.
             assert_called_once_with)(
                 mock_context, endpoint_id,

+ 1 - 1
coriolis/tests/api/v1/test_endpoint_source_options.py

@@ -48,7 +48,7 @@ class EndpointSourceOptionsControllerTestCase(test_base.CoriolisBaseTestCase):
 
         mock_context.can.assert_called_once_with(
             'migration:endpoints:list_source_options')
-        mock_decode_base64_param.has_calls(expected_calls)
+        mock_decode_base64_param.assert_has_calls(expected_calls)
         mock_get_endpoint_source_options.assert_called_once_with(
             mock_context, endpoint_id,
             env=env,

+ 4 - 4
coriolis/tests/conductor/rpc/test_server.py

@@ -5358,7 +5358,7 @@ class ConductorServerEndpointTestCase(test_base.CoriolisBaseTestCase):
 
     @mock.patch.object(db_api, "update_service")
     @mock.patch.object(rpc_worker_client.WorkerClient, "get_service_status")
-    @mock.patch.object(db_api, "get_service")
+    @mock.patch.object(db_api, "get_service", new_callable=mock.Mock)
     def test_refresh_service_status(
         self,
         mock_get_service,
@@ -5375,12 +5375,12 @@ class ConductorServerEndpointTestCase(test_base.CoriolisBaseTestCase):
             mock_get_service.return_value,
             result
         )
-        mock_get_service.has_calls([
+        mock_get_service.assert_has_calls([
             mock.call(
                 mock.sentinel.context,
                 mock.sentinel.service_id
-            ) * 2
-        ])
+            )
+        ] * 2)
         mock_get_service_status.assert_called_once_with(
             mock.sentinel.context)
         mock_update_service.assert_called_once_with(

+ 4 - 3
coriolis/tests/tasks/test_replica_tasks.py

@@ -38,9 +38,10 @@ class ReplicaTasksTestCase(test_base.CoriolisBaseTestCase):
     def test__check_ensure_volumes_info_ordering(
             self, mock_sanitize, export_info, volumes_info,
             exception_expected, expected_result):
+        mock_sanitize.side_effect = lambda x: x
         expected_calls = [
-            mock.call.mock_sanitize({"volumes_info": volumes_info}),
-            mock.call.mock_sanitize({"volumes_info": expected_result}),
+            mock.call({"volumes_info": volumes_info}),
+            mock.call({"volumes_info": expected_result}),
         ]
         if exception_expected:
             self.assertRaises(
@@ -50,7 +51,7 @@ class ReplicaTasksTestCase(test_base.CoriolisBaseTestCase):
         else:
             result = replica_tasks._check_ensure_volumes_info_ordering(
                 export_info, volumes_info)
-            mock_sanitize.has_calls(expected_calls)
+            mock_sanitize.assert_has_calls(expected_calls)
             self.assertEqual(result, expected_result)
 
     @ddt.file_data("data/test_nic_ips_update.yml")