From 4c333ecc9088ed4c32356d5d2e5b8c9d34bb1b55 Mon Sep 17 00:00:00 2001 From: "laysa.uchoa" Date: Sat, 10 Dec 2022 09:47:31 +0100 Subject: [PATCH] Add tests --- scripts/__init__.py | 0 scripts/tests/test_renamed_files.py | 58 +++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 scripts/__init__.py create mode 100644 scripts/tests/test_renamed_files.py diff --git a/scripts/__init__.py b/scripts/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/scripts/tests/test_renamed_files.py b/scripts/tests/test_renamed_files.py new file mode 100644 index 0000000000..8303e2c8ee --- /dev/null +++ b/scripts/tests/test_renamed_files.py @@ -0,0 +1,58 @@ +import sys, os +import mock, pytest + +myPath = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, myPath + "/../../") +from scripts.check_renamed_files import check_missing_redirects + + +@mock.patch.dict( + os.environ, + { + "ALL_OLD_AND_NEW_RENAMED_FILES": "docs/tools.rst,docs/renamed_tools_file.rst docs/community.rst,docs/renamed_community_file.rst docs/integrations.rst,docs/renamed_integration_file.rst docs/platform.rst,docs/platform2.rst docs/products/opensearch/howto/connect-with-python.rst,docs/products/opensearch/howto/renamed_opensearch_file.rst" + }, +) +def test_check_missing_redirects_with_missing_links(): + renamed_files = [ + "docs/renamed_community_file.rst", + "docs/renamed_integration_file.rst", + "docs/renamed_tools_file.rst", + "docs/products/opensearch/howto/renamed_opensearch_file.rst", + ] + missing_redirects = check_missing_redirects(renamed_files) + assert missing_redirects == { + "docs/community": "docs/renamed_community_file", + "docs/integration": "docs/renamed_integration_file", + "docs/tool": "docs/renamed_tools_file", + "docs/products/opensearch/howto/connect-with-python": "docs/products/opensearch/howto/renamed_opensearch_file", + } + + +@mock.patch.dict( + os.environ, + { + "ALL_OLD_AND_NEW_RENAMED_FILES": "docs/tools.rst,docs/renamed_tools_file.rst docs/community.rst,docs/renamed_community_file.rst docs/integrations.rst,docs/renamed_integration_file.rst docs/platform.rst,docs/platform2.rst docs/products/opensearch/howto/connect-with-python.rst,docs/products/opensearch/howto/renamed_opensearch_file.rst" + }, +) +def test_check_missing_redirects_with_no_renamed_files(): + """ + Test when there were previous changes in all old and new renamed file, + without renamed files in current commit. No missind redirects should be + reported + """ + renamed_files = [] + missing_redirects = check_missing_redirects(renamed_files) + assert missing_redirects == {} + + +@mock.patch.dict( + os.environ, + {"ALL_OLD_AND_NEW_RENAMED_FILES": ""}, +) +def test_check_missing_redirects_no_files_changed_and_no_renamed_files(): + """ + Function should raise an error if no files changed and this function is called + """ + with pytest.raises(ValueError): + renamed_files = [] + check_missing_redirects(renamed_files)