test_oss.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 oss resource plugin."""
  18. import pytest
  19. from pydolphinscheduler.resources_plugin.oss import OSS
  20. @pytest.mark.parametrize(
  21. "attr, expected",
  22. [
  23. (
  24. "https://ospp-ds-private.oss-cn-hangzhou.aliyuncs.com/a.sh",
  25. {
  26. "endpoint": "https://oss-cn-hangzhou.aliyuncs.com",
  27. "file_path": "a.sh",
  28. "bucket": "ospp-ds-private",
  29. },
  30. ),
  31. (
  32. "https://ospp-ds-public.oss-cn-hangzhou.aliyuncs.com/dir/a.sh",
  33. {
  34. "endpoint": "https://oss-cn-hangzhou.aliyuncs.com",
  35. "file_path": "dir/a.sh",
  36. "bucket": "ospp-ds-public",
  37. },
  38. ),
  39. ],
  40. )
  41. def test_oss_get_bucket_file_info(attr, expected):
  42. """Test the get_bucket_file_info function of the oss resource plugin."""
  43. oss = OSS(prefix="prefix")
  44. oss.get_bucket_file_info(attr)
  45. assert expected == oss._bucket_file_info.__dict__
  46. @pytest.mark.skip(reason="This test requires OSS services")
  47. @pytest.mark.parametrize(
  48. "attr, expected",
  49. [
  50. (
  51. {
  52. "init": {
  53. "prefix": "https://ospp-ds-private.oss-cn-hangzhou.aliyuncs.com",
  54. "access_key_id": "LTAI5tP25Mxx",
  55. "access_key_secret": "cSur23Qbxx",
  56. },
  57. "file_path": "a.sh",
  58. },
  59. "test oss resource plugin\n",
  60. ),
  61. (
  62. {
  63. "init": {
  64. "prefix": "https://ospp-ds-private.oss-cn-hangzhou.aliyuncs.com/dir/",
  65. "access_key_id": "LTAxx",
  66. "access_key_secret": "cSur23Qxx",
  67. },
  68. "file_path": "b.sh",
  69. },
  70. "test oss resource plugin\n",
  71. ),
  72. (
  73. {
  74. "init": {
  75. "prefix": "https://ospp-ds-private.oss-cn-hangzhou.aliyuncs.com",
  76. },
  77. "file_path": "b.sh",
  78. },
  79. "test oss resource plugin\n",
  80. ),
  81. (
  82. {
  83. "init": {
  84. "prefix": "https://ospp-ds-public.oss-cn-hangzhou.aliyuncs.com",
  85. },
  86. "file_path": "b.sh",
  87. },
  88. "test oss resource plugin\n",
  89. ),
  90. (
  91. {
  92. "init": {
  93. "prefix": "https://ospp-ds-public.oss-cn-hangzhou.aliyuncs.com/dir/",
  94. "access_key_id": "LTAIxx",
  95. "access_key_secret": "cSurxx",
  96. },
  97. "file_path": "a.sh",
  98. },
  99. "test oss resource plugin\n",
  100. ),
  101. ],
  102. )
  103. def test_oss_read_file(attr, expected):
  104. """Test the read_file function of the oss resource plug-in."""
  105. oss = OSS(**attr.get("init"))
  106. assert expected == oss.read_file(attr.get("file_path"))