test_gitlab.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 github resource plugin."""
  18. import pytest
  19. from pydolphinscheduler.resources_plugin.gitlab import GitLab
  20. @pytest.mark.parametrize(
  21. "attr, expected",
  22. [
  23. (
  24. "https://gitlab.com/pydolphinscheduler/ds-gitlab/-/blob/main/union.sh",
  25. {
  26. "branch": "main",
  27. "file_path": "union.sh",
  28. "host": "https://gitlab.com",
  29. "repo_name": "ds-gitlab",
  30. "user": "pydolphinscheduler",
  31. },
  32. ),
  33. (
  34. "https://gitlab.com/pydolphinscheduler/ds/-/blob/dev/test/exc.sh",
  35. {
  36. "branch": "dev",
  37. "file_path": "test/exc.sh",
  38. "host": "https://gitlab.com",
  39. "repo_name": "ds",
  40. "user": "pydolphinscheduler",
  41. },
  42. ),
  43. ],
  44. )
  45. def test_gitlab_get_git_file_info(attr, expected):
  46. """Test the get_file_info function of the gitlab resource plugin."""
  47. gitlab = GitLab(prefix="prefix")
  48. gitlab.get_git_file_info(attr)
  49. assert expected == gitlab._git_file_info.__dict__
  50. @pytest.mark.skip(reason="This test needs gitlab service")
  51. @pytest.mark.parametrize(
  52. "attr, expected",
  53. [
  54. (
  55. {
  56. "init": {
  57. "prefix": "https://gitlab.com/pydolphinscheduler/ds-internal/-/blob/main",
  58. "oauth_token": "24518bd4cf5bfe9xx",
  59. },
  60. "file_path": "union.sh",
  61. },
  62. "test gitlab resource plugin\n",
  63. ),
  64. (
  65. {
  66. "init": {
  67. "prefix": "https://gitlab.com/pydolphinscheduler/ds/-/blob/main",
  68. "private_token": "9TyTe2xx",
  69. },
  70. "file_path": "union.sh",
  71. },
  72. "test gitlab resource plugin\n",
  73. ),
  74. (
  75. {
  76. "init": {
  77. "prefix": "https://gitlab.com/pydolphinscheduler/ds-gitlab/-/blob/main",
  78. "username": "pydolphinscheduler",
  79. "password": "4295xx",
  80. },
  81. "file_path": "union.sh",
  82. },
  83. "test gitlab resource plugin\n",
  84. ),
  85. (
  86. {
  87. "init": {
  88. "prefix": "https://gitlab.com/pydolphinscheduler/ds-public/-/blob/main",
  89. },
  90. "file_path": "union.sh",
  91. },
  92. "test gitlab resource plugin\n",
  93. ),
  94. (
  95. {
  96. "init": {
  97. "prefix": "https://gitlab.com/pydolphinscheduler/ds-internal/-/blob/main",
  98. "username": "pydolphinscheduler",
  99. "password": "429xxx",
  100. },
  101. "file_path": "union.sh",
  102. },
  103. "test gitlab resource plugin\n",
  104. ),
  105. ],
  106. )
  107. def test_gitlab_read_file(attr, expected):
  108. """Test the read_file function of the gitlab resource plug-in."""
  109. gitlab = GitLab(**attr.get("init"))
  110. assert expected == gitlab.read_file(attr.get("file_path"))