Skip to content

Commit

Permalink
Merge pull request #128 from aldbr/main_FIX_diracLogout
Browse files Browse the repository at this point in the history
fix: dirac logout if creds do not exist
  • Loading branch information
chrisburr authored Oct 6, 2023
2 parents 98c6fba + bb90fa5 commit 690723b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/diracx/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async def whoami():
async def logout():
async with DiracClient() as api:
credentials_path = get_diracx_preferences().credentials_path
if credentials_path:
if credentials_path.exists():
credentials = json.loads(credentials_path.read_text())

# Revoke refresh token
Expand Down
28 changes: 28 additions & 0 deletions tests/cli/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,31 @@ def fake_sleep(*args, **kwargs):
# Return the credentials so this test can also be used by the
# "with_cli_login" fixture
return expected_credentials_path.read_text()


async def test_logout(monkeypatch, capfd, cli_env, with_cli_login):
expected_credentials_path = expected_credentials_path = Path(
cli_env["HOME"], ".cache", "diracx", "credentials.json"
)
# Ensure the credentials file does exist
assert expected_credentials_path.exists()

# Run the logout command
await cli.logout()
captured = capfd.readouterr()
assert "Removed credentials from" in captured.out
assert "Logout successful!" in captured.out
assert captured.err == ""

# Ensure the credentials file does not exist after logging out
assert not expected_credentials_path.exists()

# Rerun the logout command, it should not fail
await cli.logout()
captured = capfd.readouterr()
assert "Removed credentials from" not in captured.out
assert "Logout successful!" in captured.out
assert captured.err == ""

# Ensure the credentials file still does not exist
assert not expected_credentials_path.exists()

0 comments on commit 690723b

Please sign in to comment.