Skip to content

Commit 3d01df5

Browse files
committed
update tests
1 parent e2aa81f commit 3d01df5

File tree

2 files changed

+49
-15
lines changed

2 files changed

+49
-15
lines changed

jupyterlab_git/handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ async def post(self):
404404
response = await self.git.get_upstream_branch(current_path, current_branch)
405405
if response['code'] != 0:
406406
self.set_status(500)
407-
self.finish(json.dumps(upstream))
407+
self.finish(json.dumps(response))
408408

409409

410410
class GitPullHandler(GitHandler):

jupyterlab_git/tests/test_handlers.py

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,13 @@ class TestPush(ServerTest):
166166
@patch("jupyterlab_git.handlers.GitPushHandler.git", spec=Git)
167167
def test_push_handler_localbranch(self, mock_git):
168168
# Given
169-
mock_git.get_current_branch.return_value = maybe_future("foo")
169+
mock_git.get_current_branch.return_value = maybe_future("localbranch")
170170
mock_git.get_upstream_branch.return_value = maybe_future(
171-
"localbranch"
171+
{
172+
"code": 0,
173+
"remote_short_name": ".",
174+
"remote_branch": "localbranch"
175+
}
172176
)
173177
mock_git.push.return_value = maybe_future({"code": 0})
174178

@@ -178,7 +182,7 @@ def test_push_handler_localbranch(self, mock_git):
178182

179183
# Then
180184
mock_git.get_current_branch.assert_called_with("test_path")
181-
mock_git.get_upstream_branch.assert_called_with("test_path", "foo")
185+
mock_git.get_upstream_branch.assert_called_with("test_path", "localbranch")
182186
mock_git.push.assert_called_with(".", "HEAD:localbranch", "test_path", None)
183187

184188
assert response.status_code == 200
@@ -188,10 +192,11 @@ def test_push_handler_localbranch(self, mock_git):
188192
@patch("jupyterlab_git.handlers.GitPushHandler.git", spec=Git)
189193
def test_push_handler_remotebranch(self, mock_git):
190194
# Given
191-
mock_git.get_current_branch.return_value = maybe_future("foo")
192-
mock_git.get_upstream_branch.return_value = maybe_future(
193-
"origin/remotebranch"
194-
)
195+
mock_git.get_current_branch.return_value = maybe_future("foo/bar")
196+
upstream = {"code": 0,
197+
"remote_short_name": "origin/something",
198+
"remote_branch": "remote-branch-name"}
199+
mock_git.get_upstream_branch.return_value = maybe_future(upstream)
195200
mock_git.push.return_value = maybe_future({"code": 0})
196201

197202
# When
@@ -200,9 +205,9 @@ def test_push_handler_remotebranch(self, mock_git):
200205

201206
# Then
202207
mock_git.get_current_branch.assert_called_with("test_path")
203-
mock_git.get_upstream_branch.assert_called_with("test_path", "foo")
208+
mock_git.get_upstream_branch.assert_called_with("test_path", "foo/bar")
204209
mock_git.push.assert_called_with(
205-
"origin", "HEAD:remotebranch", "test_path", None
210+
"origin/something", "HEAD:remote-branch-name", "test_path", None
206211
)
207212

208213
assert response.status_code == 200
@@ -213,7 +218,12 @@ def test_push_handler_remotebranch(self, mock_git):
213218
def test_push_handler_noupstream(self, mock_git):
214219
# Given
215220
mock_git.get_current_branch.return_value = maybe_future("foo")
216-
mock_git.get_upstream_branch.return_value = maybe_future("")
221+
upstream = {
222+
"code": 128,
223+
"command": "",
224+
"message": "fatal: no upstream configured for branch 'foo'"
225+
}
226+
mock_git.get_upstream_branch.return_value = maybe_future(upstream)
217227
mock_git.push.return_value = maybe_future({"code": 0})
218228

219229
# When
@@ -234,23 +244,47 @@ def test_push_handler_noupstream(self, mock_git):
234244

235245

236246
class TestUpstream(ServerTest):
247+
@patch("jupyterlab_git.handlers.GitUpstreamHandler.git", spec=Git)
248+
def test_upstream_handler_forward_slashes(self, mock_git):
249+
# Given
250+
mock_git.get_current_branch.return_value = maybe_future("foo/bar")
251+
upstream = {"code": 0,
252+
"remote_short_name": "origin/something",
253+
"remote_branch": "foo/bar"}
254+
mock_git.get_upstream_branch.return_value = maybe_future(upstream)
255+
256+
# When
257+
body = {"current_path": "test_path"}
258+
response = self.tester.post(["upstream"], body=body)
259+
260+
# Then
261+
mock_git.get_current_branch.assert_called_with("test_path")
262+
mock_git.get_upstream_branch.assert_called_with("test_path", "foo/bar")
263+
264+
assert response.status_code == 200
265+
payload = response.json()
266+
assert payload == upstream
267+
237268
@patch("jupyterlab_git.handlers.GitUpstreamHandler.git", spec=Git)
238269
def test_upstream_handler_localbranch(self, mock_git):
239270
# Given
240-
mock_git.get_current_branch.return_value = maybe_future("foo")
241-
mock_git.get_upstream_branch.return_value = maybe_future("bar")
271+
mock_git.get_current_branch.return_value = maybe_future("foo/bar")
272+
upstream = {"code": 0,
273+
"remote_short_name": ".",
274+
"remote_branch": "foo/bar"}
275+
mock_git.get_upstream_branch.return_value = maybe_future(upstream)
242276

243277
# When
244278
body = {"current_path": "test_path"}
245279
response = self.tester.post(["upstream"], body=body)
246280

247281
# Then
248282
mock_git.get_current_branch.assert_called_with("test_path")
249-
mock_git.get_upstream_branch.assert_called_with("test_path", "foo")
283+
mock_git.get_upstream_branch.assert_called_with("test_path", "foo/bar")
250284

251285
assert response.status_code == 200
252286
payload = response.json()
253-
assert payload == {"upstream": "bar"}
287+
assert payload == upstream
254288

255289

256290
class TestDiffContent(ServerTest):

0 commit comments

Comments
 (0)