xdu-chenrj commented on code in PR #11831: URL: https://github.com/apache/dolphinscheduler/pull/11831#discussion_r967679428
########## dolphinscheduler-python/pydolphinscheduler/tests/resources_plugin/test_github.py: ########## @@ -0,0 +1,228 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Test github resource plugin.""" +from unittest.mock import PropertyMock, patch + +import pytest + +from pydolphinscheduler.resources_plugin import GitHub +from pydolphinscheduler.resources_plugin.base.git import GitFileInfo + + [email protected]( + "attr, expected", + [ + ( + { + "user": "apache", + "repo_name": "dolphinscheduler", + "file_path": "script/install.sh", + "api": "https://api.github.com/repos/{user}/{repo_name}/contents/{file_path}", + }, + "https://api.github.com/repos/apache/dolphinscheduler/contents/script/install.sh", + ), + ], +) +def test_github_build_req_api(attr, expected): + """Test the build_req_api function of the github resource plug-in.""" + github = GitHub(prefix="prefix") + assert expected == github.build_req_api(**attr) + + [email protected]( + "attr, expected", + [ + ( + "https://github.com/apache/dolphinscheduler/blob/dev/script/install.sh", + { + "_user": "apache", + "_repo_name": "dolphinscheduler", + "_branch": "dev", + "_file_path": "script/install.sh", + }, + ), + ( + "https://github.com/apache/dolphinscheduler/blob/master/pom.xml", + { + "_user": "apache", + "_repo_name": "dolphinscheduler", + "_branch": "master", + "_file_path": "pom.xml", + }, + ), + ( + "https://github.com/apache/dolphinscheduler/blob/1.3.9-release/docker/build/startup.sh", + { + "_user": "apache", + "_repo_name": "dolphinscheduler", + "_branch": "1.3.9-release", + "_file_path": "docker/build/startup.sh", + }, + ), + ], +) +def test_github_get_git_file_info(attr, expected): + """Test the get_git_file_info function of the github resource plug-in.""" + github = GitHub(prefix="prefix") + github.get_git_file_info(attr) + assert expected == github._git_file_info.__dict__ + + [email protected]( + "attr, expected", + [ + ( + ( + { + "user": "apache", + "repo_name": "dolphinscheduler", + "file_path": "docker/build/startup.sh", + } + ), + "https://api.github.com/repos/apache/dolphinscheduler/contents/docker/build/startup.sh", + ), + ( + ( + { + "user": "apache", + "repo_name": "dolphinscheduler", + "file_path": "pom.xml", + } + ), + "https://api.github.com/repos/apache/dolphinscheduler/contents/pom.xml", + ), + ( + ( + { + "user": "apache", + "repo_name": "dolphinscheduler", + "file_path": "script/create-dolphinscheduler.sh", + } + ), + "https://api.github.com/repos/apache/dolphinscheduler/contents/script/create-dolphinscheduler.sh", + ), + ], +) +@patch( + "pydolphinscheduler.resources_plugin.github.GitHub._git_file_info", + new_callable=PropertyMock, +) +def test_github_get_req_url(m_git_file_info, attr, expected): + """Test the get_req_url function of the github resource plug-in.""" + github = GitHub(prefix="prefix") + m_git_file_info.return_value = GitFileInfo(**attr) + assert expected == github.get_req_url() + + [email protected](reason="Lack of test environment, need stable repository") [email protected]( + "attr, expected", + [ + ( + "lombok.config", + "#\n" + "# Licensed to the Apache Software Foundation (ASF) under one or more\n" + "# contributor license agreements. See the NOTICE file distributed with\n" + "# this work for additional information regarding copyright ownership.\n" + "# The ASF licenses this file to You under the Apache License, Version 2.0\n" + '# (the "License"); you may not use this file except in compliance with\n' + "# the License. You may obtain a copy of the License at\n" + "#\n" + "# http://www.apache.org/licenses/LICENSE-2.0\n" + "#\n" + "# Unless required by applicable law or agreed to in writing, software\n" + '# distributed under the License is distributed on an "AS IS" BASIS,\n' + "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" + "# See the License for the specific language governing permissions and\n" + "# limitations under the License.\n" + "#\n" + "\n" + "lombok.addLombokGeneratedAnnotation = true\n", + ), + ], +) +def test_github_read_file(attr, expected): + """Test the read_file function of the github resource plug-in.""" + github = GitHub( + prefix="https://github.com/apache/dolphinscheduler/blob/dev", + ) + assert expected == github.read_file(attr) + + [email protected](reason="Lack of test environment, need stable repository") [email protected]( + "attr, expected", + [ + ( + "https://github.com/apache/dolphinscheduler/blob/dev/lombok.config", + "#\n" + "# Licensed to the Apache Software Foundation (ASF) under one or more\n" + "# contributor license agreements. See the NOTICE file distributed with\n" + "# this work for additional information regarding copyright ownership.\n" + "# The ASF licenses this file to You under the Apache License, Version 2.0\n" + '# (the "License"); you may not use this file except in compliance with\n' + "# the License. You may obtain a copy of the License at\n" + "#\n" + "# http://www.apache.org/licenses/LICENSE-2.0\n" + "#\n" + "# Unless required by applicable law or agreed to in writing, software\n" + '# distributed under the License is distributed on an "AS IS" BASIS,\n' + "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" + "# See the License for the specific language governing permissions and\n" + "# limitations under the License.\n" + "#\n" + "\n" + "lombok.addLombokGeneratedAnnotation = true\n", + ), + ], +) +def test_github_req(attr, expected): + """Test the req function of the github resource plug-in.""" + github = GitHub( + prefix="prefix", + ) + assert expected == github.req(attr) + + [email protected]( Review Comment: > Same as above. Thank you for your suggestion. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
