test(api): add autospec to MagicMock-based patch usage (#32752)

This commit is contained in:
-LAN-
2026-03-01 04:30:45 +08:00
committed by GitHub
parent c034eb036c
commit 20fcc95db9
86 changed files with 865 additions and 804 deletions

View File

@ -12,9 +12,17 @@ def test_get_conversation_mark_read_keeps_updated_at_unchanged():
conversation.id = "conversation-id"
with (
patch("controllers.console.app.conversation.current_account_with_tenant", return_value=(account, None)),
patch("controllers.console.app.conversation.naive_utc_now", return_value=datetime(2026, 2, 9, 0, 0, 0)),
patch("controllers.console.app.conversation.db.session") as mock_session,
patch(
"controllers.console.app.conversation.current_account_with_tenant",
return_value=(account, None),
autospec=True,
),
patch(
"controllers.console.app.conversation.naive_utc_now",
return_value=datetime(2026, 2, 9, 0, 0, 0),
autospec=True,
),
patch("controllers.console.app.conversation.db.session", autospec=True) as mock_session,
):
mock_session.query.return_value.where.return_value.first.return_value = conversation

View File

@ -40,7 +40,7 @@ class TestWorkflowDraftVariableFields:
mock_variable.variable_file = mock_variable_file
# Mock the file helpers
with patch("controllers.console.app.workflow_draft_variable.file_helpers") as mock_file_helpers:
with patch("controllers.console.app.workflow_draft_variable.file_helpers", autospec=True) as mock_file_helpers:
mock_file_helpers.get_signed_file_url.return_value = "http://example.com/signed-url"
# Call the function
@ -203,7 +203,7 @@ class TestWorkflowDraftVariableFields:
}
)
with patch("controllers.console.app.workflow_draft_variable.file_helpers") as mock_file_helpers:
with patch("controllers.console.app.workflow_draft_variable.file_helpers", autospec=True) as mock_file_helpers:
mock_file_helpers.get_signed_file_url.return_value = "http://example.com/signed-url"
assert marshal(node_var, _WORKFLOW_DRAFT_VARIABLE_WITHOUT_VALUE_FIELDS) == expected_without_value
expected_with_value = expected_without_value.copy()