test(api): fix broken tests

pull/20699/head
QuantumGhost 12 months ago
parent 80569ce29f
commit 11b1077c8a

@ -1,7 +1,7 @@
import datetime import datetime
import uuid import uuid
from collections import OrderedDict from collections import OrderedDict
from typing import NamedTuple from typing import Any, NamedTuple
from flask_restful import marshal from flask_restful import marshal
@ -18,6 +18,7 @@ from .workflow_draft_variable import (
) )
_TEST_APP_ID = "test_app_id" _TEST_APP_ID = "test_app_id"
_TEST_NODE_EXEC_ID = str(uuid.uuid4())
class TestWorkflowDraftVariableFields: class TestWorkflowDraftVariableFields:
@ -29,7 +30,7 @@ class TestWorkflowDraftVariableFields:
conv_var.id = str(uuid.uuid4()) conv_var.id = str(uuid.uuid4())
conv_var.visible = True conv_var.visible = True
expected_without_value = OrderedDict( expected_without_value: OrderedDict[str, Any] = OrderedDict(
{ {
"id": str(conv_var.id), "id": str(conv_var.id),
"type": conv_var.get_variable_type().value, "type": conv_var.get_variable_type().value,
@ -53,6 +54,7 @@ class TestWorkflowDraftVariableFields:
name="sys_var", name="sys_var",
value=build_segment("a"), value=build_segment("a"),
editable=True, editable=True,
node_execution_id=_TEST_NODE_EXEC_ID,
) )
sys_var.id = str(uuid.uuid4()) sys_var.id = str(uuid.uuid4())
@ -83,12 +85,13 @@ class TestWorkflowDraftVariableFields:
name="node_var", name="node_var",
value=build_segment([1, "a"]), value=build_segment([1, "a"]),
visible=False, visible=False,
node_execution_id=_TEST_NODE_EXEC_ID,
) )
node_var.id = str(uuid.uuid4()) node_var.id = str(uuid.uuid4())
node_var.last_edited_at = datetime.datetime.now(datetime.UTC).replace(tzinfo=None) node_var.last_edited_at = datetime.datetime.now(datetime.UTC).replace(tzinfo=None)
expected_without_value = OrderedDict( expected_without_value: OrderedDict[str, Any] = OrderedDict(
{ {
"id": str(node_var.id), "id": str(node_var.id),
"type": node_var.get_variable_type().value, "type": node_var.get_variable_type().value,
@ -120,6 +123,7 @@ class TestWorkflowDraftVariableList:
name="test_var", name="test_var",
value=build_segment("a"), value=build_segment("a"),
visible=True, visible=True,
node_execution_id=_TEST_NODE_EXEC_ID,
) )
node_var.id = str(uuid.uuid4()) node_var.id = str(uuid.uuid4())
node_var_dict = OrderedDict( node_var_dict = OrderedDict(
@ -216,7 +220,11 @@ def test_workflow_file_variable_with_signed_url():
# Create a WorkflowDraftVariable with the File # Create a WorkflowDraftVariable with the File
file_var = WorkflowDraftVariable.new_node_variable( file_var = WorkflowDraftVariable.new_node_variable(
app_id=_TEST_APP_ID, node_id="test_node", name="file_var", value=build_segment(test_file) app_id=_TEST_APP_ID,
node_id="test_node",
name="file_var",
value=build_segment(test_file),
node_execution_id=_TEST_NODE_EXEC_ID,
) )
# Marshal the variable using the API fields # Marshal the variable using the API fields
@ -270,7 +278,11 @@ def test_workflow_file_variable_remote_url():
# Create a WorkflowDraftVariable with the File # Create a WorkflowDraftVariable with the File
file_var = WorkflowDraftVariable.new_node_variable( file_var = WorkflowDraftVariable.new_node_variable(
app_id=_TEST_APP_ID, node_id="test_node", name="file_var", value=build_segment(test_file) app_id=_TEST_APP_ID,
node_id="test_node",
name="file_var",
value=build_segment(test_file),
node_execution_id=_TEST_NODE_EXEC_ID,
) )
# Marshal the variable using the API fields # Marshal the variable using the API fields

@ -1107,7 +1107,7 @@ class WorkflowDraftVariable(Base):
node_id: str, node_id: str,
name: str, name: str,
value: Segment, value: Segment,
node_execution_id: str | None = None, node_execution_id: str | None,
description: str = "", description: str = "",
) -> "WorkflowDraftVariable": ) -> "WorkflowDraftVariable":
variable = WorkflowDraftVariable() variable = WorkflowDraftVariable()
@ -1137,6 +1137,7 @@ class WorkflowDraftVariable(Base):
name=name, name=name,
value=value, value=value,
description=description, description=description,
node_execution_id=None,
) )
return variable return variable

@ -17,6 +17,7 @@ class TestWorkflowDraftVariableService(unittest.TestCase):
_session: Session _session: Session
_node1_id = "test_node_1" _node1_id = "test_node_1"
_node2_id = "test_node_2" _node2_id = "test_node_2"
_node_exec_id = str(uuid.uuid4())
def setUp(self): def setUp(self):
self._test_app_id = str(uuid.uuid4()) self._test_app_id = str(uuid.uuid4())
@ -25,6 +26,7 @@ class TestWorkflowDraftVariableService(unittest.TestCase):
app_id=self._test_app_id, app_id=self._test_app_id,
name="sys_var", name="sys_var",
value=build_segment("sys_value"), value=build_segment("sys_value"),
node_execution_id=self._node_exec_id,
) )
conv_var = WorkflowDraftVariable.new_conversation_variable( conv_var = WorkflowDraftVariable.new_conversation_variable(
app_id=self._test_app_id, app_id=self._test_app_id,
@ -38,6 +40,7 @@ class TestWorkflowDraftVariableService(unittest.TestCase):
name="int_var", name="int_var",
value=build_segment(1), value=build_segment(1),
visible=False, visible=False,
node_execution_id=self._node_exec_id,
), ),
WorkflowDraftVariable.new_node_variable( WorkflowDraftVariable.new_node_variable(
app_id=self._test_app_id, app_id=self._test_app_id,
@ -45,6 +48,7 @@ class TestWorkflowDraftVariableService(unittest.TestCase):
name="str_var", name="str_var",
value=build_segment("str_value"), value=build_segment("str_value"),
visible=True, visible=True,
node_execution_id=self._node_exec_id,
), ),
] ]
node1_var = WorkflowDraftVariable.new_node_variable( node1_var = WorkflowDraftVariable.new_node_variable(
@ -53,6 +57,7 @@ class TestWorkflowDraftVariableService(unittest.TestCase):
name="str_var", name="str_var",
value=build_segment("str_value"), value=build_segment("str_value"),
visible=True, visible=True,
node_execution_id=self._node_exec_id,
) )
_variables = list(node2_vars) _variables = list(node2_vars)
_variables.extend( _variables.extend(
@ -163,6 +168,7 @@ class TestDraftVariableLoader(unittest.TestCase):
_test_app_id: str _test_app_id: str
_node1_id = "test_loader_node_1" _node1_id = "test_loader_node_1"
_node_exec_id = str(uuid.uuid4())
def setUp(self): def setUp(self):
self._test_app_id = str(uuid.uuid4()) self._test_app_id = str(uuid.uuid4())
@ -170,6 +176,7 @@ class TestDraftVariableLoader(unittest.TestCase):
app_id=self._test_app_id, app_id=self._test_app_id,
name="sys_var", name="sys_var",
value=build_segment("sys_value"), value=build_segment("sys_value"),
node_execution_id=self._node_exec_id,
) )
conv_var = WorkflowDraftVariable.new_conversation_variable( conv_var = WorkflowDraftVariable.new_conversation_variable(
app_id=self._test_app_id, app_id=self._test_app_id,
@ -182,6 +189,7 @@ class TestDraftVariableLoader(unittest.TestCase):
name="str_var", name="str_var",
value=build_segment("str_value"), value=build_segment("str_value"),
visible=True, visible=True,
node_execution_id=self._node_exec_id,
) )
_variables = [ _variables = [
node_var, node_var,

Loading…
Cancel
Save