Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions api/tests/unit_tests/core/workflow/test_workflow_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
from graphon.nodes.answer.answer_node import AnswerNode
from graphon.nodes.answer.entities import AnswerNodeData
from graphon.nodes.code.code_node import CodeNode
from graphon.nodes.code.entities import CodeNodeData
from graphon.nodes.code.limits import CodeNodeLimits
from graphon.nodes.human_input.entities import HumanInputNodeData as GraphonHumanInputNodeData
from graphon.nodes.human_input.human_input_node import HumanInputNode
Expand Down Expand Up @@ -365,6 +366,40 @@ def fake_head(method, url, *args, **kwargs):
class TestWorkflowEntry:
"""Test WorkflowEntry class methods."""

@pytest.mark.parametrize("input_key", ["item_ext", "code.item_ext"])
@pytest.mark.parametrize(
("attribute", "value"),
[("name", "report.pdf"), ("extension", ".pdf"), ("mime_type", "application/pdf"), ("size", 1024)],
)
def test_mapping_iteration_file_attribute_inputs(
self, input_key: str, attribute: str, value: str | int
) -> None:
selector = ["iteration", "item", attribute]
node_data = CodeNodeData.model_validate(
{
"title": "Classify file",
"code_language": "python3",
"code": "def main(item_ext):\n return {'result': str(item_ext)}",
"variables": [{"variable": "item_ext", "value_selector": selector}],
"outputs": {"result": {"type": "string"}},
}
)
variable_mapping = CodeNode.extract_variable_selector_to_variable_mapping(
graph_config={}, config={"id": "code", "data": node_data}
)
variable_pool = VariablePool()

WorkflowEntry.mapping_user_inputs_to_variable_pool(
variable_mapping=variable_mapping,
user_inputs={input_key: value},
variable_pool=variable_pool,
tenant_id="tenant",
)

attribute_value = variable_pool.get(selector)
assert attribute_value is not None
assert attribute_value.value == value

@pytest.mark.parametrize("value", [0, False, "", [], {}])
def test_qualified_input_preserves_falsy_values(self, value):
variable_pool = VariablePool()
Expand Down
Loading