test_procedure.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 Procedure."""
  18. from unittest.mock import patch
  19. import pytest
  20. from pydolphinscheduler.tasks.procedure import Procedure
  21. TEST_PROCEDURE_SQL = (
  22. 'create procedure HelloWorld() selece "hello world"; call HelloWorld();'
  23. )
  24. TEST_PROCEDURE_DATASOURCE_NAME = "test_datasource"
  25. @pytest.mark.parametrize(
  26. "attr, expect",
  27. [
  28. (
  29. {
  30. "name": "test-procedure-task-params",
  31. "datasource_name": TEST_PROCEDURE_DATASOURCE_NAME,
  32. "method": TEST_PROCEDURE_SQL,
  33. },
  34. {
  35. "method": TEST_PROCEDURE_SQL,
  36. "type": "MYSQL",
  37. "datasource": 1,
  38. "localParams": [],
  39. "resourceList": [],
  40. "dependence": {},
  41. "waitStartTimeout": {},
  42. "conditionResult": {"successNode": [""], "failedNode": [""]},
  43. },
  44. )
  45. ],
  46. )
  47. @patch(
  48. "pydolphinscheduler.core.task.Task.gen_code_and_version",
  49. return_value=(123, 1),
  50. )
  51. @patch(
  52. "pydolphinscheduler.core.database.Database.get_database_info",
  53. return_value=({"id": 1, "type": "MYSQL"}),
  54. )
  55. def test_property_task_params(mock_datasource, mock_code_version, attr, expect):
  56. """Test task sql task property."""
  57. task = Procedure(**attr)
  58. assert expect == task.task_params
  59. @patch(
  60. "pydolphinscheduler.core.task.Task.gen_code_and_version",
  61. return_value=(123, 1),
  62. )
  63. @patch(
  64. "pydolphinscheduler.core.database.Database.get_database_info",
  65. return_value=({"id": 1, "type": "MYSQL"}),
  66. )
  67. def test_sql_get_define(mock_datasource, mock_code_version):
  68. """Test task procedure function get_define."""
  69. name = "test_procedure_get_define"
  70. expect = {
  71. "code": 123,
  72. "name": name,
  73. "version": 1,
  74. "description": None,
  75. "delayTime": 0,
  76. "taskType": "PROCEDURE",
  77. "taskParams": {
  78. "type": "MYSQL",
  79. "datasource": 1,
  80. "method": TEST_PROCEDURE_SQL,
  81. "localParams": [],
  82. "resourceList": [],
  83. "dependence": {},
  84. "conditionResult": {"successNode": [""], "failedNode": [""]},
  85. "waitStartTimeout": {},
  86. },
  87. "flag": "YES",
  88. "taskPriority": "MEDIUM",
  89. "workerGroup": "default",
  90. "failRetryTimes": 0,
  91. "failRetryInterval": 1,
  92. "timeoutFlag": "CLOSE",
  93. "timeoutNotifyStrategy": None,
  94. "timeout": 0,
  95. }
  96. task = Procedure(name, TEST_PROCEDURE_DATASOURCE_NAME, TEST_PROCEDURE_SQL)
  97. assert task.get_define() == expect