test_sub_process.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on an
  13. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. # KIND, either express or implied. See the License for the
  15. # specific language governing permissions and limitations
  16. # under the License.
  17. """Test Task sub_process."""
  18. from unittest.mock import patch
  19. import pytest
  20. from pydolphinscheduler.core.process_definition import ProcessDefinition
  21. from pydolphinscheduler.tasks.sub_process import SubProcess
  22. TEST_SUB_PROCESS_DEFINITION_NAME = "sub-test-process-definition"
  23. TEST_SUB_PROCESS_DEFINITION_CODE = "3643589832320"
  24. TEST_PROCESS_DEFINITION_NAME = "simple-test-process-definition"
  25. @pytest.mark.parametrize(
  26. "attr, expect",
  27. [
  28. (
  29. {"process_definition_name": TEST_SUB_PROCESS_DEFINITION_NAME},
  30. {
  31. "processDefinitionCode": TEST_SUB_PROCESS_DEFINITION_CODE,
  32. "localParams": [],
  33. "resourceList": [],
  34. "dependence": {},
  35. "waitStartTimeout": {},
  36. "conditionResult": {"successNode": [""], "failedNode": [""]},
  37. },
  38. )
  39. ],
  40. )
  41. @patch(
  42. "pydolphinscheduler.tasks.sub_process.SubProcess.get_process_definition_info",
  43. return_value=(
  44. {
  45. "id": 1,
  46. "name": TEST_SUB_PROCESS_DEFINITION_NAME,
  47. "code": TEST_SUB_PROCESS_DEFINITION_CODE,
  48. }
  49. ),
  50. )
  51. @patch(
  52. "pydolphinscheduler.core.task.Task.gen_code_and_version",
  53. return_value=(123, 1),
  54. )
  55. def test_property_task_params(mock_code_version, mock_pd_info, attr, expect):
  56. """Test task sub process property."""
  57. task = SubProcess("test-sub-process-task-params", **attr)
  58. assert expect == task.task_params
  59. @patch(
  60. "pydolphinscheduler.tasks.sub_process.SubProcess.get_process_definition_info",
  61. return_value=(
  62. {
  63. "id": 1,
  64. "name": TEST_SUB_PROCESS_DEFINITION_NAME,
  65. "code": TEST_SUB_PROCESS_DEFINITION_CODE,
  66. }
  67. ),
  68. )
  69. def test_sub_process_get_define(mock_process_definition):
  70. """Test task sub_process function get_define."""
  71. code = 123
  72. version = 1
  73. name = "test_sub_process_get_define"
  74. expect = {
  75. "code": code,
  76. "name": name,
  77. "version": 1,
  78. "description": None,
  79. "delayTime": 0,
  80. "taskType": "SUB_PROCESS",
  81. "taskParams": {
  82. "resourceList": [],
  83. "localParams": [],
  84. "processDefinitionCode": TEST_SUB_PROCESS_DEFINITION_CODE,
  85. "dependence": {},
  86. "conditionResult": {"successNode": [""], "failedNode": [""]},
  87. "waitStartTimeout": {},
  88. },
  89. "flag": "YES",
  90. "taskPriority": "MEDIUM",
  91. "workerGroup": "default",
  92. "failRetryTimes": 0,
  93. "failRetryInterval": 1,
  94. "timeoutFlag": "CLOSE",
  95. "timeoutNotifyStrategy": None,
  96. "timeout": 0,
  97. }
  98. with patch(
  99. "pydolphinscheduler.core.task.Task.gen_code_and_version",
  100. return_value=(code, version),
  101. ):
  102. with ProcessDefinition(TEST_PROCESS_DEFINITION_NAME):
  103. sub_process = SubProcess(name, TEST_SUB_PROCESS_DEFINITION_NAME)
  104. assert sub_process.get_define() == expect