Skip to content

Commit

Permalink
Fix Client.logout() method
Browse files Browse the repository at this point in the history
Ensure `Client.logout()` correctly handles `GlobusApp` and `LoginManager`
objects. This method previously only handled the latter.
  • Loading branch information
rjmello committed Nov 20, 2024
1 parent ee8e51d commit b568abd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Bug Fixes
^^^^^^^^^

- ``Client.logout()`` no longer raises an ``AttributeError``.
7 changes: 6 additions & 1 deletion compute_sdk/globus_compute_sdk/sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ def __init__(

self._task_status_table: dict[str, dict] = {}

self.app: GlobusApp | None = None
self.login_manager: LoginManagerProtocol | None = None

if app and login_manager:
raise ValueError("'app' and 'login_manager' are mutually exclusive.")
elif login_manager:
Expand Down Expand Up @@ -150,7 +153,9 @@ def version_check(self, endpoint_version: str | None = None) -> None:

def logout(self):
"""Remove credentials from your local system"""
self.login_manager.logout()
auth_obj = self.app or self.login_manager
if auth_obj:
auth_obj.logout()

def _log_version_mismatch(self, worker_details: dict | None) -> None:
"""
Expand Down
16 changes: 16 additions & 0 deletions compute_sdk/tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,3 +729,19 @@ def test_client_handles_login_manager():
assert mock_lm.get_auth_client.call_count == 1
assert mock_lm.get_web_client.call_count == 1
assert mock_lm.get_web_client.call_args[1]["base_url"] == client.web_service_address


def test_client_logout_with_app(mocker):
mocker.patch(f"{_MOCK_BASE}ComputeAuthClient")
mocker.patch(f"{_MOCK_BASE}WebClient")
mock_app = mock.Mock(spec=UserApp)
client = gc.Client(do_version_check=False, app=mock_app)
client.logout()
assert mock_app.logout.called


def test_client_logout_with_login_manager():
mock_lm = mock.Mock(spec=LoginManager)
client = gc.Client(do_version_check=False, login_manager=mock_lm)
client.logout()
assert mock_lm.logout.called

0 comments on commit b568abd

Please sign in to comment.