@@ -398,6 +398,7 @@ def test_main_cannot_write_zuliprc_given_good_credentials(
398
398
399
399
# This is default base path to use
400
400
zuliprc_path = os .path .join (str (tmp_path ), path_to_use )
401
+ zuliprc_file = os .path .join (zuliprc_path , "zuliprc" )
401
402
monkeypatch .setenv ("HOME" , zuliprc_path )
402
403
403
404
# Give some arbitrary input and fake that it's always valid
@@ -412,12 +413,18 @@ def test_main_cannot_write_zuliprc_given_good_credentials(
412
413
captured = capsys .readouterr ()
413
414
lines = captured .out .strip ().split ("\n " )
414
415
415
- expected_line = (
416
- "\x1b [91m"
417
- f"{ expected_exception } : zuliprc could not be created "
418
- f"at { os .path .join (zuliprc_path , 'zuliprc' )} "
419
- "\x1b [0m"
420
- )
416
+ if expected_exception == "FileNotFoundError" :
417
+ expected_error = (
418
+ f"could not create { zuliprc_file } "
419
+ f"([Errno 2] No such file or directory: '{ zuliprc_file } ')"
420
+ )
421
+ else : # PermissionError
422
+ expected_error = (
423
+ f"could not create { zuliprc_file } "
424
+ f"([Errno 13] Permission denied: '{ zuliprc_file } ')"
425
+ )
426
+
427
+ expected_line = f"\x1b [91m{ expected_exception } : { expected_error } \x1b [0m"
421
428
assert lines [- 1 ] == expected_line
422
429
423
430
@@ -573,38 +580,29 @@ def test_exit_with_error(
573
580
def test__write_zuliprc__success (
574
581
tmp_path : Path , id : str = "id" , key : str = "key" , url : str = "url"
575
582
) -> None :
576
- path = os .path .join (str (tmp_path ), "zuliprc" )
577
-
578
- error_message = _write_zuliprc (path , server_url = url , login_id = id )
583
+ """Test successful creation of zuliprc and zulip_key files."""
584
+ path = tmp_path / "zuliprc"
585
+ key_path = tmp_path / "zulip_key"
586
+
587
+ error_message = _write_zuliprc (
588
+ to_path = str (path ),
589
+ key_path = str (key_path ),
590
+ login_id = id ,
591
+ api_key = key ,
592
+ server_url = url ,
593
+ )
579
594
580
595
assert error_message == ""
581
596
582
- expected_contents = (
583
- f"[api]\n email={ id } \n "
584
- f"# Fill the passcmd field with a command that outputs the API key.\n "
585
- f"# The API key is temporarily stored in the 'zulip_key' file at "
586
- f"{ os .path .dirname (os .path .abspath (path ))} ."
587
- f"\n # After storing the key in a password manager, replace the cmd.\n "
588
- f"passcmd=cat zulip_key\n site={ url } "
589
- )
597
+ expected_contents = f"[api]\n email={ id } \n passcmd=cat zulip_key\n site={ url } "
590
598
with open (path ) as f :
591
599
assert f .read () == expected_contents
592
600
593
- assert stat . filemode ( os . stat ( path ). st_mode )[ - 6 :] == 6 * "-"
594
-
601
+ with open ( key_path ) as f :
602
+ assert f . read () == key
595
603
596
- def test__write_zuliprc__fail_file_exists (
597
- minimal_zuliprc : str ,
598
- tmp_path : Path ,
599
- id : str = "id" ,
600
- key : str = "key" ,
601
- url : str = "url" ,
602
- ) -> None :
603
- path = os .path .join (str (tmp_path ), "zuliprc" )
604
-
605
- error_message = _write_zuliprc (path , server_url = url , login_id = id )
606
-
607
- assert error_message == "zuliprc already exists at " + path
604
+ assert stat .filemode (os .stat (path ).st_mode )[- 6 :] == 6 * "-"
605
+ assert stat .filemode (os .stat (key_path ).st_mode )[- 6 :] == "------"
608
606
609
607
610
608
@pytest .mark .parametrize (
0 commit comments