@@ -398,6 +398,7 @@ def test_main_cannot_write_zuliprc_given_good_credentials(
398398
399399 # This is default base path to use
400400 zuliprc_path = os .path .join (str (tmp_path ), path_to_use )
401+ zuliprc_file = os .path .join (zuliprc_path , "zuliprc" )
401402 monkeypatch .setenv ("HOME" , zuliprc_path )
402403
403404 # Give some arbitrary input and fake that it's always valid
@@ -412,12 +413,18 @@ def test_main_cannot_write_zuliprc_given_good_credentials(
412413 captured = capsys .readouterr ()
413414 lines = captured .out .strip ().split ("\n " )
414415
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"
421428 assert lines [- 1 ] == expected_line
422429
423430
@@ -573,38 +580,29 @@ def test_exit_with_error(
573580def test__write_zuliprc__success (
574581 tmp_path : Path , id : str = "id" , key : str = "key" , url : str = "url"
575582) -> 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+ )
579594
580595 assert error_message == ""
581596
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 } "
590598 with open (path ) as f :
591599 assert f .read () == expected_contents
592600
593- assert stat . filemode ( os . stat ( path ). st_mode )[ - 6 :] == 6 * "-"
594-
601+ with open ( key_path ) as f :
602+ assert f . read () == key
595603
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 :] == "------"
608606
609607
610608@pytest .mark .parametrize (
0 commit comments