test_resource_plugin.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 abstract class resource_plugin."""
  18. import pytest
  19. from pydolphinscheduler.exceptions import PyResPluginException
  20. from pydolphinscheduler.resources_plugin import GitHub
  21. @pytest.mark.parametrize(
  22. "attr, expected",
  23. [
  24. (
  25. {
  26. "s": "https://api.github.com/repos/apache/dolphinscheduler/contents/script/install.sh",
  27. "x": "/",
  28. "n": 2,
  29. },
  30. 7,
  31. ),
  32. (
  33. {
  34. "s": "https://api.github.com",
  35. "x": ":",
  36. "n": 1,
  37. },
  38. 5,
  39. ),
  40. ],
  41. )
  42. def test_github_get_index(attr, expected):
  43. """Test the get_index function of the abstract class resource_plugin."""
  44. github = GitHub(prefix="prefix")
  45. assert expected == github.get_index(**attr)
  46. @pytest.mark.parametrize(
  47. "attr",
  48. [
  49. {
  50. "s": "https://api.github.com",
  51. "x": "/",
  52. "n": 3,
  53. },
  54. {
  55. "s": "https://api.github.com/",
  56. "x": "/",
  57. "n": 4,
  58. },
  59. ],
  60. )
  61. def test_github_get_index_exception(attr):
  62. """Test exception to get_index function of abstract class resource_plugin."""
  63. with pytest.raises(
  64. PyResPluginException,
  65. match="Incomplete path.",
  66. ):
  67. github = GitHub(prefix="prefix")
  68. github.get_index(**attr)