From 1384db2802d31076fa90d6228935fb1b4fd19897 Mon Sep 17 00:00:00 2001 From: -LAN- Date: Tue, 27 May 2025 10:51:54 +0800 Subject: [PATCH] test(test_workflow): Mock current_user Signed-off-by: -LAN- --- api/tests/unit_tests/models/test_workflow.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/api/tests/unit_tests/models/test_workflow.py b/api/tests/unit_tests/models/test_workflow.py index 6815f880a5..34802d47a7 100644 --- a/api/tests/unit_tests/models/test_workflow.py +++ b/api/tests/unit_tests/models/test_workflow.py @@ -37,9 +37,14 @@ def test_environment_variables(): {"name": "var4", "value": 3.14, "id": str(uuid4()), "selector": ["env", "var4"]} ) + # Mock current_user as an EndUser + mock_user = mock.Mock() + mock_user.tenant_id = "tenant_id" + with ( mock.patch("core.helper.encrypter.encrypt_token", return_value="encrypted_token"), mock.patch("core.helper.encrypter.decrypt_token", return_value="secret"), + mock.patch("models.workflow.current_user", mock_user), ): # Set the environment_variables property of the Workflow instance variables = [variable1, variable2, variable3, variable4] @@ -79,9 +84,14 @@ def test_update_environment_variables(): {"name": "var4", "value": 3.14, "id": str(uuid4()), "selector": ["env", "var4"]} ) + # Mock current_user as an EndUser + mock_user = mock.Mock() + mock_user.tenant_id = "tenant_id" + with ( mock.patch("core.helper.encrypter.encrypt_token", return_value="encrypted_token"), mock.patch("core.helper.encrypter.decrypt_token", return_value="secret"), + mock.patch("models.workflow.current_user", mock_user), ): variables = [variable1, variable2, variable3, variable4] @@ -120,9 +130,14 @@ def test_to_dict(): # Create some EnvironmentVariable instances + # Mock current_user as an EndUser + mock_user = mock.Mock() + mock_user.tenant_id = "tenant_id" + with ( mock.patch("core.helper.encrypter.encrypt_token", return_value="encrypted_token"), mock.patch("core.helper.encrypter.decrypt_token", return_value="secret"), + mock.patch("models.workflow.current_user", mock_user), ): # Set the environment_variables property of the Workflow instance workflow.environment_variables = [