test_shell.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 shell."""
  18. from unittest.mock import patch
  19. import pytest
  20. from pydolphinscheduler.tasks.shell import Shell
  21. @pytest.mark.parametrize(
  22. "attr, expect",
  23. [
  24. (
  25. {"command": "test script"},
  26. {
  27. "rawScript": "test script",
  28. "localParams": [],
  29. "resourceList": [],
  30. "dependence": {},
  31. "waitStartTimeout": {},
  32. "conditionResult": {"successNode": [""], "failedNode": [""]},
  33. },
  34. )
  35. ],
  36. )
  37. @patch(
  38. "pydolphinscheduler.core.task.Task.gen_code_and_version",
  39. return_value=(123, 1),
  40. )
  41. def test_property_task_params(mock_code_version, attr, expect):
  42. """Test task shell task property."""
  43. task = Shell("test-shell-task-params", **attr)
  44. assert expect == task.task_params
  45. def test_shell_get_define():
  46. """Test task shell function get_define."""
  47. code = 123
  48. version = 1
  49. name = "test_shell_get_define"
  50. command = "echo test shell"
  51. expect = {
  52. "code": code,
  53. "name": name,
  54. "version": 1,
  55. "description": None,
  56. "delayTime": 0,
  57. "taskType": "SHELL",
  58. "taskParams": {
  59. "resourceList": [],
  60. "localParams": [],
  61. "rawScript": command,
  62. "dependence": {},
  63. "conditionResult": {"successNode": [""], "failedNode": [""]},
  64. "waitStartTimeout": {},
  65. },
  66. "flag": "YES",
  67. "taskPriority": "MEDIUM",
  68. "workerGroup": "default",
  69. "failRetryTimes": 0,
  70. "failRetryInterval": 1,
  71. "timeoutFlag": "CLOSE",
  72. "timeoutNotifyStrategy": None,
  73. "timeout": 0,
  74. }
  75. with patch(
  76. "pydolphinscheduler.core.task.Task.gen_code_and_version",
  77. return_value=(code, version),
  78. ):
  79. shell = Shell(name, command)
  80. assert shell.get_define() == expect