Skip to content

Commit 7f08480

Browse files
Add missing unit tests for GitMergeHandler
Co-authored-by: balajirajput96 <124477404+balajirajput96@users.noreply.github.com>
1 parent 861374f commit 7f08480

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

jupyterlab_git/tests/test_handlers.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,3 +1089,52 @@ async def test_content_getcontent_deleted_file(mock_execute, jp_fetch, jp_root_d
10891089
assert response.code == 200
10901090
payload = json.loads(response.body)
10911091
assert payload["content"] == ""
1092+
1093+
1094+
@patch("jupyterlab_git.handlers.GitMergeHandler.git", spec=Git)
1095+
async def test_merge_handler_success(mock_git, jp_fetch, jp_root_dir):
1096+
# Given
1097+
local_path = jp_root_dir / "test_path"
1098+
branch_to_merge = "feature-branch"
1099+
merge_result = {
1100+
"code": 0,
1101+
"message": "Merge made by the 'ort' strategy."
1102+
}
1103+
mock_git.merge.return_value = maybe_future(merge_result)
1104+
1105+
# When
1106+
body = {"branch": branch_to_merge}
1107+
response = await jp_fetch(
1108+
NAMESPACE, local_path.name, "merge", body=json.dumps(body), method="POST"
1109+
)
1110+
1111+
# Then
1112+
mock_git.merge.assert_called_with(branch_to_merge, str(local_path))
1113+
assert response.code == 200
1114+
payload = json.loads(response.body)
1115+
assert payload == merge_result
1116+
1117+
1118+
@patch("jupyterlab_git.handlers.GitMergeHandler.git", spec=Git)
1119+
async def test_merge_handler_conflict(mock_git, jp_fetch, jp_root_dir):
1120+
# Given
1121+
local_path = jp_root_dir / "test_path"
1122+
branch_to_merge = "conflicting-branch"
1123+
merge_result = {
1124+
"code": 1,
1125+
"command": "git merge conflicting-branch",
1126+
"message": "Automatic merge failed; fix conflicts and then commit the result."
1127+
}
1128+
mock_git.merge.return_value = maybe_future(merge_result)
1129+
1130+
# When
1131+
body = {"branch": branch_to_merge}
1132+
response = await jp_fetch(
1133+
NAMESPACE, local_path.name, "merge", body=json.dumps(body), method="POST"
1134+
)
1135+
1136+
# Then
1137+
mock_git.merge.assert_called_with(branch_to_merge, str(local_path))
1138+
assert response.code == 500
1139+
payload = json.loads(response.body)
1140+
assert payload == merge_result

0 commit comments

Comments
 (0)