@@ -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,31 +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 , api_key = key , 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 = f"[api]\n email={ id } \n key= { key } \n site={ url } "
597
+ expected_contents = f"[api]\n email={ id } \n passcmd=cat zulip_key \n site={ url } "
583
598
with open (path ) as f :
584
599
assert f .read () == expected_contents
585
600
586
- assert stat .filemode (os .stat (path ).st_mode )[- 6 :] == 6 * "-"
601
+ with open (key_path ) as f :
602
+ assert f .read () == key
587
603
588
-
589
- def test__write_zuliprc__fail_file_exists (
590
- minimal_zuliprc : str ,
591
- tmp_path : Path ,
592
- id : str = "id" ,
593
- key : str = "key" ,
594
- url : str = "url" ,
595
- ) -> None :
596
- path = os .path .join (str (tmp_path ), "zuliprc" )
597
-
598
- error_message = _write_zuliprc (path , api_key = key , server_url = url , login_id = id )
599
-
600
- 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 :] == "------"
601
606
602
607
603
608
@pytest .mark .parametrize (
0 commit comments