|
|
|
@ -194,3 +194,98 @@ def test_workflow_node_variables_fields():
|
|
|
|
item_dict = resp["items"][0]
|
|
|
|
item_dict = resp["items"][0]
|
|
|
|
assert item_dict["name"] == "conv_var"
|
|
|
|
assert item_dict["name"] == "conv_var"
|
|
|
|
assert item_dict["value"] == 1
|
|
|
|
assert item_dict["value"] == 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_workflow_file_variable_with_signed_url():
|
|
|
|
|
|
|
|
"""Test that File type variables include signed URLs in API responses."""
|
|
|
|
|
|
|
|
from core.file.enums import FileTransferMethod, FileType
|
|
|
|
|
|
|
|
from core.file.models import File
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Create a File object with LOCAL_FILE transfer method (which generates signed URLs)
|
|
|
|
|
|
|
|
test_file = File(
|
|
|
|
|
|
|
|
id="test_file_id",
|
|
|
|
|
|
|
|
tenant_id="test_tenant_id",
|
|
|
|
|
|
|
|
type=FileType.IMAGE,
|
|
|
|
|
|
|
|
transfer_method=FileTransferMethod.LOCAL_FILE,
|
|
|
|
|
|
|
|
related_id="test_upload_file_id",
|
|
|
|
|
|
|
|
filename="test.jpg",
|
|
|
|
|
|
|
|
extension=".jpg",
|
|
|
|
|
|
|
|
mime_type="image/jpeg",
|
|
|
|
|
|
|
|
size=12345,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Create a WorkflowDraftVariable with the File
|
|
|
|
|
|
|
|
file_var = WorkflowDraftVariable.new_node_variable(
|
|
|
|
|
|
|
|
app_id=_TEST_APP_ID, node_id="test_node", name="file_var", value=build_segment(test_file)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Marshal the variable using the API fields
|
|
|
|
|
|
|
|
resp = marshal(WorkflowDraftVariableList(variables=[file_var]), _WORKFLOW_DRAFT_VARIABLE_LIST_FIELDS)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Verify the response structure
|
|
|
|
|
|
|
|
assert isinstance(resp, dict)
|
|
|
|
|
|
|
|
assert len(resp["items"]) == 1
|
|
|
|
|
|
|
|
item_dict = resp["items"][0]
|
|
|
|
|
|
|
|
assert item_dict["name"] == "file_var"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Verify the value is a dict (File.to_dict() result) and contains expected fields
|
|
|
|
|
|
|
|
value = item_dict["value"]
|
|
|
|
|
|
|
|
assert isinstance(value, dict)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Verify the File fields are preserved
|
|
|
|
|
|
|
|
assert value["id"] == test_file.id
|
|
|
|
|
|
|
|
assert value["filename"] == test_file.filename
|
|
|
|
|
|
|
|
assert value["type"] == test_file.type.value
|
|
|
|
|
|
|
|
assert value["transfer_method"] == test_file.transfer_method.value
|
|
|
|
|
|
|
|
assert value["size"] == test_file.size
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Verify the URL is present (it should be a signed URL for LOCAL_FILE transfer method)
|
|
|
|
|
|
|
|
remote_url = value["remote_url"]
|
|
|
|
|
|
|
|
assert remote_url is not None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert isinstance(remote_url, str)
|
|
|
|
|
|
|
|
# For LOCAL_FILE, the URL should contain signature parameters
|
|
|
|
|
|
|
|
assert "timestamp=" in remote_url
|
|
|
|
|
|
|
|
assert "nonce=" in remote_url
|
|
|
|
|
|
|
|
assert "sign=" in remote_url
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_workflow_file_variable_remote_url():
|
|
|
|
|
|
|
|
"""Test that File type variables with REMOTE_URL transfer method return the remote URL."""
|
|
|
|
|
|
|
|
from core.file.enums import FileTransferMethod, FileType
|
|
|
|
|
|
|
|
from core.file.models import File
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Create a File object with REMOTE_URL transfer method
|
|
|
|
|
|
|
|
test_file = File(
|
|
|
|
|
|
|
|
id="test_file_id",
|
|
|
|
|
|
|
|
tenant_id="test_tenant_id",
|
|
|
|
|
|
|
|
type=FileType.IMAGE,
|
|
|
|
|
|
|
|
transfer_method=FileTransferMethod.REMOTE_URL,
|
|
|
|
|
|
|
|
remote_url="https://example.com/test.jpg",
|
|
|
|
|
|
|
|
filename="test.jpg",
|
|
|
|
|
|
|
|
extension=".jpg",
|
|
|
|
|
|
|
|
mime_type="image/jpeg",
|
|
|
|
|
|
|
|
size=12345,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Create a WorkflowDraftVariable with the File
|
|
|
|
|
|
|
|
file_var = WorkflowDraftVariable.new_node_variable(
|
|
|
|
|
|
|
|
app_id=_TEST_APP_ID, node_id="test_node", name="file_var", value=build_segment(test_file)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Marshal the variable using the API fields
|
|
|
|
|
|
|
|
resp = marshal(WorkflowDraftVariableList(variables=[file_var]), _WORKFLOW_DRAFT_VARIABLE_LIST_FIELDS)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Verify the response structure
|
|
|
|
|
|
|
|
assert isinstance(resp, dict)
|
|
|
|
|
|
|
|
assert len(resp["items"]) == 1
|
|
|
|
|
|
|
|
item_dict = resp["items"][0]
|
|
|
|
|
|
|
|
assert item_dict["name"] == "file_var"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Verify the value is a dict (File.to_dict() result) and contains expected fields
|
|
|
|
|
|
|
|
value = item_dict["value"]
|
|
|
|
|
|
|
|
assert isinstance(value, dict)
|
|
|
|
|
|
|
|
remote_url = value["remote_url"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# For REMOTE_URL, the URL should be the original remote URL
|
|
|
|
|
|
|
|
assert remote_url == test_file.remote_url
|
|
|
|
|