@@ -166,9 +166,13 @@ class TestPush(ServerTest):
166
166
@patch ("jupyterlab_git.handlers.GitPushHandler.git" , spec = Git )
167
167
def test_push_handler_localbranch (self , mock_git ):
168
168
# Given
169
- mock_git .get_current_branch .return_value = maybe_future ("foo " )
169
+ mock_git .get_current_branch .return_value = maybe_future ("localbranch " )
170
170
mock_git .get_upstream_branch .return_value = maybe_future (
171
- "localbranch"
171
+ {
172
+ "code" : 0 ,
173
+ "remote_short_name" : "." ,
174
+ "remote_branch" : "localbranch"
175
+ }
172
176
)
173
177
mock_git .push .return_value = maybe_future ({"code" : 0 })
174
178
@@ -178,7 +182,7 @@ def test_push_handler_localbranch(self, mock_git):
178
182
179
183
# Then
180
184
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 " )
182
186
mock_git .push .assert_called_with ("." , "HEAD:localbranch" , "test_path" , None )
183
187
184
188
assert response .status_code == 200
@@ -188,10 +192,11 @@ def test_push_handler_localbranch(self, mock_git):
188
192
@patch ("jupyterlab_git.handlers.GitPushHandler.git" , spec = Git )
189
193
def test_push_handler_remotebranch (self , mock_git ):
190
194
# 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 )
195
200
mock_git .push .return_value = maybe_future ({"code" : 0 })
196
201
197
202
# When
@@ -200,9 +205,9 @@ def test_push_handler_remotebranch(self, mock_git):
200
205
201
206
# Then
202
207
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 " )
204
209
mock_git .push .assert_called_with (
205
- "origin" , "HEAD:remotebranch " , "test_path" , None
210
+ "origin/something " , "HEAD:remote-branch-name " , "test_path" , None
206
211
)
207
212
208
213
assert response .status_code == 200
@@ -213,7 +218,12 @@ def test_push_handler_remotebranch(self, mock_git):
213
218
def test_push_handler_noupstream (self , mock_git ):
214
219
# Given
215
220
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 )
217
227
mock_git .push .return_value = maybe_future ({"code" : 0 })
218
228
219
229
# When
@@ -234,23 +244,47 @@ def test_push_handler_noupstream(self, mock_git):
234
244
235
245
236
246
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
+
237
268
@patch ("jupyterlab_git.handlers.GitUpstreamHandler.git" , spec = Git )
238
269
def test_upstream_handler_localbranch (self , mock_git ):
239
270
# 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 )
242
276
243
277
# When
244
278
body = {"current_path" : "test_path" }
245
279
response = self .tester .post (["upstream" ], body = body )
246
280
247
281
# Then
248
282
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 " )
250
284
251
285
assert response .status_code == 200
252
286
payload = response .json ()
253
- assert payload == { " upstream" : "bar" }
287
+ assert payload == upstream
254
288
255
289
256
290
class TestDiffContent (ServerTest ):
0 commit comments