@@ -188,6 +188,10 @@ def test_prints_tree_for_empty_directory(self, mock_path, home_dir):
188188class TestUpload :
189189 file = NamedTemporaryFile ()
190190
191+ def test_creates_pa_path_with_provided_path (self , mock_path , home_dir ):
192+ runner .invoke (app , ["upload" , "~/hello.txt" , "-c" , self .file .name ])
193+ mock_path .assert_called_once_with (f"{ home_dir } /hello.txt" )
194+
191195 def test_exits_with_success_when_successful_upload (self , mock_path ):
192196 mock_path .return_value .upload .return_value = True
193197
@@ -206,6 +210,10 @@ def test_exits_with_error_when_unsuccessful_upload(self, mock_path):
206210
207211
208212class TestDelete :
213+ def test_creates_pa_path_with_provided_path (self , mock_path , home_dir ):
214+ runner .invoke (app , ["delete" , "~/hello.txt" ])
215+ mock_path .assert_called_once_with (f"{ home_dir } /hello.txt" )
216+
209217 def test_exits_with_success_when_successful_delete (self , mock_path ):
210218 mock_path .return_value .delete .return_value = True
211219
@@ -221,3 +229,71 @@ def test_exits_with_error_when_unsuccessful_delete(self, mock_path):
221229
222230 assert mock_path .return_value .delete .called
223231 assert result .exit_code == 1
232+
233+
234+ class TestShare :
235+ def test_creates_pa_path_with_provided_path (self , mock_path , home_dir ):
236+ runner .invoke (app , ["share" , "~/hello.txt" ])
237+ mock_path .assert_called_once_with (f"{ home_dir } /hello.txt" )
238+
239+ def test_exits_with_success_and_prints_sharing_url_when_successful_share (self , mock_path ):
240+ mock_path .return_value .share .return_value = "link"
241+
242+ result = runner .invoke (app , ["share" , "~/hello.txt" ])
243+
244+ assert "link" in result .stdout
245+ assert mock_path .return_value .share .called
246+ assert not mock_path .return_value .get_sharing_url .called
247+ assert result .exit_code == 0
248+
249+ def test_exits_with_error_when_unsuccessful_share (self , mock_path ):
250+ mock_path .return_value .share .return_value = ""
251+
252+ result = runner .invoke (app , ["share" , "~/hello.txt" ])
253+
254+ assert mock_path .return_value .share .called
255+ assert not mock_path .return_value .get_sharing_url .called
256+ assert result .stdout == ""
257+ assert result .exit_code == 1
258+
259+ def test_exits_with_success_and_prints_sharing_url_when_path_already_shared (self , mock_path ):
260+ mock_path .return_value .get_sharing_url .return_value = "link"
261+
262+ result = runner .invoke (app , ["share" , "--check" , "~/hello.txt" ])
263+
264+ assert mock_path .return_value .get_sharing_url .called
265+ assert not mock_path .return_value .share .called
266+ assert "link" in result .stdout
267+ assert result .exit_code == 0
268+
269+ def test_exits_with_error_when_path_was_not_shared (self , mock_path ):
270+ mock_path .return_value .get_sharing_url .return_value = ""
271+
272+ result = runner .invoke (app , ["share" , "--check" , "~/hello.txt" ])
273+
274+ assert mock_path .return_value .get_sharing_url .called
275+ assert not mock_path .return_value .share .called
276+ assert result .stdout == ""
277+ assert result .exit_code == 1
278+
279+
280+ class TestUnshare :
281+ def test_creates_pa_path_with_provided_path (self , mock_path , home_dir ):
282+ runner .invoke (app , ["unshare" , "~/hello.txt" ])
283+ mock_path .assert_called_once_with (f"{ home_dir } /hello.txt" )
284+
285+ def test_exits_with_success_when_successful_unshare_or_file_not_shared (self , mock_path ):
286+ mock_path .return_value .unshare .return_value = True
287+
288+ result = runner .invoke (app , ["unshare" , "~/hello.txt" ])
289+
290+ assert mock_path .return_value .unshare .called
291+ assert result .exit_code == 0
292+
293+ def test_exits_with_error_when_unsuccessful_unshare (self , mock_path ):
294+ mock_path .return_value .unshare .return_value = False
295+
296+ result = runner .invoke (app , ["unshare" , "~/hello.txt" ])
297+
298+ assert mock_path .return_value .unshare .called
299+ assert result .exit_code == 1
0 commit comments