diff --git a/monkey/tests/unit_tests/monkey_island/cc/repository/test_mongo_node_repository.py b/monkey/tests/unit_tests/monkey_island/cc/repository/test_mongo_node_repository.py index b056cb575..9d1ee6279 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/repository/test_mongo_node_repository.py +++ b/monkey/tests/unit_tests/monkey_island/cc/repository/test_mongo_node_repository.py @@ -158,7 +158,7 @@ def test_upsert_communication__find_one_fails(error_raising_node_repository): def test_upsert_communication__replace_one_fails( error_raising_mock_mongo_client, error_raising_node_repository ): - error_raising_mock_mongo_client.monkey_island.nodes.find_one = lambda _: None + error_raising_mock_mongo_client.monkey_island.nodes.find_one = MagicMock(return_value=None) with pytest.raises(StorageError): error_raising_node_repository.upsert_communication(1, 2, CommunicationType.SCANNED) @@ -169,8 +169,10 @@ def test_upsert_communication__replace_one_matched_without_modify( mock_result = MagicMock() mock_result.matched_count = 1 mock_result.modified_count = 0 - error_raising_mock_mongo_client.monkey_island.nodes.find_one = lambda _: None - error_raising_mock_mongo_client.monkey_island.nodes.replace_one = lambda *_, **__: mock_result + error_raising_mock_mongo_client.monkey_island.nodes.find_one = MagicMock(return_value=None) + error_raising_mock_mongo_client.monkey_island.nodes.replace_one = MagicMock( + return_value=mock_result + ) with pytest.raises(StorageError): error_raising_node_repository.upsert_communication(1, 2, CommunicationType.SCANNED) @@ -182,8 +184,10 @@ def test_upsert_communication__replace_one_insert_fails( mock_result = MagicMock() mock_result.matched_count = 0 mock_result.upserted_id = None - error_raising_mock_mongo_client.monkey_island.nodes.find_one = lambda _: None - error_raising_mock_mongo_client.monkey_island.nodes.replace_one = lambda *_, **__: mock_result + error_raising_mock_mongo_client.monkey_island.nodes.find_one = MagicMock(return_value=None) + error_raising_mock_mongo_client.monkey_island.nodes.replace_one = MagicMock( + return_value=mock_result + ) with pytest.raises(StorageError): error_raising_node_repository.upsert_communication(1, 2, CommunicationType.SCANNED)