Skip to content

Commit

Permalink
Add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Zxun2 committed Nov 10, 2023
1 parent c6558a8 commit aca9029
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
1 change: 0 additions & 1 deletion jupyterlab_git/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,6 @@ async def show_prefix(self, path, contents_manager):
return {
"code": code,
"path": None,
"relative_path": relative_git_path,
}
else:
result = {
Expand Down
48 changes: 48 additions & 0 deletions jupyterlab_git/tests/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from .testutils import assert_http_error, maybe_future
from tornado.httpclient import HTTPClientError

from pathlib import Path


def test_mapping_added():
mock_web_app = Mock()
Expand Down Expand Up @@ -112,6 +114,52 @@ async def test_git_show_prefix(mock_execute, jp_fetch, jp_root_dir):
)


@patch("jupyterlab_git.git.execute")
async def test_git_show_prefix_nested_directory(mock_execute, jp_fetch, jp_root_dir):
# Given
path = "path/to/repo"

local_path = jp_root_dir / "test_path"

mock_execute.return_value = maybe_future((0, str(path), ""))

# When
response = await jp_fetch(
NAMESPACE,
local_path.name + "/subfolder",
"show_prefix",
body="{}",
method="POST",
)

# Then
assert response.code == 200
payload = json.loads(response.body)
assert payload["path"] == str(path)

mock_execute.assert_has_calls(
[
call(
["git", "rev-parse", "--show-prefix"],
cwd=str(local_path / "subfolder"),
timeout=20,
env=None,
username=None,
password=None,
is_binary=False,
),
]
)

try:
Path(path).absolute().relative_to(Path(local_path).absolute())
except ValueError:
# pass the test if the path is not a subdirectory of the root directory
pass
else:
assert False, "The path should not be a subdirectory of the root directory"


async def test_git_show_prefix_for_excluded_path(
jp_fetch, jp_server_config, jp_root_dir
):
Expand Down

0 comments on commit aca9029

Please sign in to comment.