test_tool.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. from core.app.entities.app_invoke_entities import InvokeFrom
  2. from core.workflow.entities.variable_pool import VariablePool
  3. from core.workflow.nodes.tool.tool_node import ToolNode
  4. from models.workflow import WorkflowNodeExecutionStatus
  5. def test_tool_variable_invoke():
  6. pool = VariablePool(system_variables={}, user_inputs={})
  7. pool.append_variable(node_id='1', variable_key_list=['123', 'args1'], value='1+1')
  8. node = ToolNode(
  9. tenant_id='1',
  10. app_id='1',
  11. workflow_id='1',
  12. user_id='1',
  13. user_from=InvokeFrom.WEB_APP,
  14. config={
  15. 'id': '1',
  16. 'data': {
  17. 'title': 'a',
  18. 'desc': 'a',
  19. 'provider_id': 'maths',
  20. 'provider_type': 'builtin',
  21. 'provider_name': 'maths',
  22. 'tool_name': 'eval_expression',
  23. 'tool_label': 'eval_expression',
  24. 'tool_configurations': {},
  25. 'tool_parameters': {
  26. 'expression': {
  27. 'type': 'variable',
  28. 'value': ['1', '123', 'args1'],
  29. }
  30. }
  31. }
  32. }
  33. )
  34. # execute node
  35. result = node.run(pool)
  36. assert result.status == WorkflowNodeExecutionStatus.SUCCEEDED
  37. assert '2' in result.outputs['text']
  38. assert result.outputs['files'] == []
  39. def test_tool_mixed_invoke():
  40. pool = VariablePool(system_variables={}, user_inputs={})
  41. pool.append_variable(node_id='1', variable_key_list=['args1'], value='1+1')
  42. node = ToolNode(
  43. tenant_id='1',
  44. app_id='1',
  45. workflow_id='1',
  46. user_id='1',
  47. user_from=InvokeFrom.WEB_APP,
  48. config={
  49. 'id': '1',
  50. 'data': {
  51. 'title': 'a',
  52. 'desc': 'a',
  53. 'provider_id': 'maths',
  54. 'provider_type': 'builtin',
  55. 'provider_name': 'maths',
  56. 'tool_name': 'eval_expression',
  57. 'tool_label': 'eval_expression',
  58. 'tool_configurations': {},
  59. 'tool_parameters': {
  60. 'expression': {
  61. 'type': 'mixed',
  62. 'value': '{{#1.args1#}}',
  63. }
  64. }
  65. }
  66. }
  67. )
  68. # execute node
  69. result = node.run(pool)
  70. assert result.status == WorkflowNodeExecutionStatus.SUCCEEDED
  71. assert '2' in result.outputs['text']
  72. assert result.outputs['files'] == []