Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
laysauchoa authored and angelinekwan committed Dec 27, 2022
1 parent 50e1abb commit 4c333ec
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
Empty file added scripts/__init__.py
Empty file.
58 changes: 58 additions & 0 deletions scripts/tests/test_renamed_files.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 4c333ec

Please sign in to comment.