fix: catch ValueError instead of bare except in account CLI commands (#40356)

This commit is contained in:
chelsealong
2026-08-10 03:18:33 +00:00
committed by GitHub
parent c849be5e52
commit 6aa3fa5193
2 changed files with 40 additions and 2 deletions
@@ -0,0 +1,38 @@
from unittest.mock import Mock
import pytest
from click.testing import CliRunner
from commands.account import reset_email, reset_password
def test_reset_password_does_not_swallow_keyboard_interrupt(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(
"commands.account.AccountService.get_account_by_email_with_case_fallback",
Mock(return_value=Mock()),
)
monkeypatch.setattr("commands.account.valid_password", Mock(side_effect=KeyboardInterrupt))
result = CliRunner().invoke(
reset_password,
["--email", "a@example.com", "--new-password", "whatever", "--password-confirm", "whatever"],
)
assert not isinstance(result.exception, SystemExit) or result.exception.code != 0
assert "Invalid password" not in result.output
def test_reset_email_does_not_swallow_keyboard_interrupt(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(
"commands.account.AccountService.get_account_by_email_with_case_fallback",
Mock(return_value=Mock()),
)
monkeypatch.setattr("commands.account.email_validate", Mock(side_effect=KeyboardInterrupt))
result = CliRunner().invoke(
reset_email,
["--email", "a@example.com", "--new-email", "b@example.com", "--email-confirm", "b@example.com"],
)
assert not isinstance(result.exception, SystemExit) or result.exception.code != 0
assert "Invalid email" not in result.output