@@ -33,6 +33,38 @@ def test_git_pull_fail(mock_subproc_popen):
33
33
])
34
34
assert {'code' : 1 , 'message' : 'Authentication failed' } == actual_response
35
35
36
+ @patch ('jupyterlab_git.git.git_auth_input_wrapper' )
37
+ @patch ('os.environ' , {'TEST' : 'test' })
38
+ def test_git_pull_with_auth_fail (mock_git_auth_input_wrapper ):
39
+ # Given
40
+ process_mock = Mock ()
41
+ attrs = {
42
+ 'communicate.return_value' : "remote: Invalid username or password.\r \n fatal: Authentication failed for 'repo_url'" .encode ('utf-8' ),
43
+ 'returncode' : 1
44
+ }
45
+ process_mock .configure_mock (** attrs )
46
+ mock_git_auth_input_wrapper .return_value = process_mock
47
+
48
+ # When
49
+ auth = {
50
+ 'username' : 'asdf' ,
51
+ 'password' : 'qwerty'
52
+ }
53
+ actual_response = Git (root_dir = '/bin' ).pull ('test_curr_path' , auth )
54
+
55
+
56
+ # Then
57
+ mock_git_auth_input_wrapper .assert_has_calls ([
58
+ call (
59
+ command = 'git pull --no-commit' ,
60
+ cwd = '/bin/test_curr_path' ,
61
+ env = {'TEST' : 'test' , 'GIT_TERMINAL_PROMPT' : '1' },
62
+ username = 'asdf' ,
63
+ password = 'qwerty'
64
+ ),
65
+ call ().communicate ()
66
+ ])
67
+ assert {'code' : 1 , 'message' : "remote: Invalid username or password.\r \n fatal: Authentication failed for 'repo_url'" } == actual_response
36
68
37
69
@patch ('subprocess.Popen' )
38
70
@patch ('os.environ' , {'TEST' : 'test' })
@@ -62,6 +94,37 @@ def test_git_pull_success(mock_subproc_popen):
62
94
])
63
95
assert {'code' : 0 } == actual_response
64
96
97
+ @patch ('jupyterlab_git.git.git_auth_input_wrapper' )
98
+ @patch ('os.environ' , {'TEST' : 'test' })
99
+ def test_git_pull_with_auth_success (mock_git_auth_input_wrapper ):
100
+ # Given
101
+ process_mock = Mock ()
102
+ attrs = {
103
+ 'communicate.return_value' : ('output' , '' .encode ('utf-8' )),
104
+ 'returncode' : 0
105
+ }
106
+ process_mock .configure_mock (** attrs )
107
+ mock_git_auth_input_wrapper .return_value = process_mock
108
+
109
+ # When
110
+ auth = {
111
+ 'username' : 'asdf' ,
112
+ 'password' : 'qwerty'
113
+ }
114
+ actual_response = Git (root_dir = '/bin' ).pull ('test_curr_path' , auth )
115
+
116
+ # Then
117
+ mock_git_auth_input_wrapper .assert_has_calls ([
118
+ call (
119
+ command = 'git pull --no-commit' ,
120
+ cwd = '/bin/test_curr_path' ,
121
+ env = {'TEST' : 'test' , 'GIT_TERMINAL_PROMPT' : '1' },
122
+ username = 'asdf' ,
123
+ password = 'qwerty'
124
+ ),
125
+ call ().communicate ()
126
+ ])
127
+ assert {'code' : 0 } == actual_response
65
128
66
129
@patch ('subprocess.Popen' )
67
130
@patch ('os.environ' , {'TEST' : 'test' })
@@ -91,6 +154,38 @@ def test_git_push_fail(mock_subproc_popen):
91
154
])
92
155
assert {'code' : 1 , 'message' : 'Authentication failed' } == actual_response
93
156
157
+ @patch ('jupyterlab_git.git.git_auth_input_wrapper' )
158
+ @patch ('os.environ' , {'TEST' : 'test' })
159
+ def test_git_push_with_auth_fail (mock_git_auth_input_wrapper ):
160
+ # Given
161
+ process_mock = Mock ()
162
+ attrs = {
163
+ 'communicate.return_value' : "remote: Invalid username or password.\r \n fatal: Authentication failed for 'repo_url'" .encode ('utf-8' ),
164
+ 'returncode' : 1
165
+ }
166
+ process_mock .configure_mock (** attrs )
167
+ mock_git_auth_input_wrapper .return_value = process_mock
168
+
169
+ # When
170
+ auth = {
171
+ 'username' : 'asdf' ,
172
+ 'password' : 'qwerty'
173
+ }
174
+ actual_response = Git (root_dir = '/bin' ).push ('test_origin' , 'HEAD:test_master' , 'test_curr_path' , auth )
175
+
176
+ # Then
177
+ mock_git_auth_input_wrapper .assert_has_calls ([
178
+ call (
179
+ command = 'git push test_origin HEAD:test_master' ,
180
+ cwd = '/bin/test_curr_path' ,
181
+ env = {'TEST' : 'test' , 'GIT_TERMINAL_PROMPT' : '1' },
182
+ username = 'asdf' ,
183
+ password = 'qwerty'
184
+ ),
185
+ call ().communicate ()
186
+ ])
187
+ assert {'code' : 1 , 'message' : "remote: Invalid username or password.\r \n fatal: Authentication failed for 'repo_url'" } == actual_response
188
+
94
189
95
190
@patch ('subprocess.Popen' )
96
191
@patch ('os.environ' , {'TEST' : 'test' })
@@ -119,3 +214,35 @@ def test_git_push_success(mock_subproc_popen):
119
214
call ().communicate ()
120
215
])
121
216
assert {'code' : 0 } == actual_response
217
+
218
+ @patch ('jupyterlab_git.git.git_auth_input_wrapper' )
219
+ @patch ('os.environ' , {'TEST' : 'test' })
220
+ def test_git_push_with_auth_success (mock_git_auth_input_wrapper ):
221
+ # Given
222
+ process_mock = Mock ()
223
+ attrs = {
224
+ 'communicate.return_value' : 'does not matter' .encode ('utf-8' ),
225
+ 'returncode' : 0
226
+ }
227
+ process_mock .configure_mock (** attrs )
228
+ mock_git_auth_input_wrapper .return_value = process_mock
229
+
230
+ # When
231
+ auth = {
232
+ 'username' : 'asdf' ,
233
+ 'password' : 'qwerty'
234
+ }
235
+ actual_response = Git (root_dir = '/bin' ).push ('.' , 'HEAD:test_master' , 'test_curr_path' , auth )
236
+
237
+ # Then
238
+ mock_git_auth_input_wrapper .assert_has_calls ([
239
+ call (
240
+ command = 'git push . HEAD:test_master' ,
241
+ cwd = '/bin/test_curr_path' ,
242
+ env = {'TEST' : 'test' , 'GIT_TERMINAL_PROMPT' : '1' },
243
+ username = 'asdf' ,
244
+ password = 'qwerty'
245
+ ),
246
+ call ().communicate ()
247
+ ])
248
+ assert {'code' : 0 } == actual_response
0 commit comments