55
66from unittest .mock import MagicMock
77
8+ import click .exceptions
89import pytest
910from globus_sdk import GlobusAPIError
1011
@@ -15,29 +16,33 @@ def _make_api_error(code: str) -> GlobusAPIError:
1516 """Create a GlobusAPIError with a specific error code."""
1617 err = MagicMock (spec = GlobusAPIError )
1718 err .code = code
18- err .message = None
19+ err .message = "Something is very wrong here."
1920 # Make it a proper exception so it can be raised
2021 err .__class__ = GlobusAPIError
22+ err .raw_json = {"code" : code , "message" : "Something is very wrong here." }
2123 return err
2224
2325
2426def test_handle_auth_error_exits_with_message (capsys ):
2527 err = _make_api_error ("AUTHENTICATION_ERROR" )
2628
27- with pytest .raises (SystemExit ) as exc_info :
29+ with pytest .raises (click . exceptions . Exit ) as exc_info :
2830 _handle_globus_api_error (err )
2931
30- assert exc_info .value .code == 1
32+ assert exc_info .value .exit_code == 1
3133 captured = capsys .readouterr ()
3234 assert "Authentication Error" in captured .err
3335 assert "globus-registered-api logout" in captured .err
3436 assert "globus-registered-api whoami" in captured .err
3537
3638
37- def test_handle_non_auth_error_reraises ():
39+ def test_handle_non_auth_error_reraises (capsys ):
3840 err = _make_api_error ("NOT_FOUND" )
3941
40- with pytest .raises (TypeError ):
41- # TypeError because mock can't be raised, but this proves the
42- # function attempted to re-raise rather than handling the error
42+ with pytest .raises (click .exceptions .Exit ) as exc_info :
4343 _handle_globus_api_error (err )
44+
45+ assert exc_info .value .exit_code == 1
46+ captured = capsys .readouterr ()
47+ assert err .code in captured .err
48+ assert err .message in captured .err
0 commit comments