|
8 | 8 | from ksef_client.cli.config import paths |
9 | 9 | from ksef_client.cli.errors import CliError |
10 | 10 | from ksef_client.cli.exit_codes import ExitCode |
| 11 | +from ksef_client.exceptions import KsefHttpError, KsefRateLimitError |
11 | 12 |
|
12 | 13 |
|
13 | 14 | def _json_output(text: str) -> dict: |
@@ -68,6 +69,38 @@ def test_lighthouse_status_validation_error_exit_code(runner, monkeypatch) -> No |
68 | 69 | assert result.exit_code == int(ExitCode.VALIDATION_ERROR) |
69 | 70 |
|
70 | 71 |
|
| 72 | +def test_lighthouse_status_rate_limit_error_exit_code(runner, monkeypatch) -> None: |
| 73 | + monkeypatch.setattr( |
| 74 | + lighthouse_cmd, |
| 75 | + "get_lighthouse_status", |
| 76 | + lambda **kwargs: (_ for _ in ()).throw( |
| 77 | + KsefRateLimitError(status_code=429, message="Too Many Requests") |
| 78 | + ), |
| 79 | + ) |
| 80 | + result = runner.invoke(app, ["lighthouse", "status"]) |
| 81 | + assert result.exit_code == int(ExitCode.RETRY_EXHAUSTED) |
| 82 | + |
| 83 | + |
| 84 | +def test_lighthouse_status_api_error_exit_code(runner, monkeypatch) -> None: |
| 85 | + monkeypatch.setattr( |
| 86 | + lighthouse_cmd, |
| 87 | + "get_lighthouse_status", |
| 88 | + lambda **kwargs: (_ for _ in ()).throw(KsefHttpError(status_code=500, message="boom")), |
| 89 | + ) |
| 90 | + result = runner.invoke(app, ["lighthouse", "status"]) |
| 91 | + assert result.exit_code == int(ExitCode.API_ERROR) |
| 92 | + |
| 93 | + |
| 94 | +def test_lighthouse_status_unexpected_error_exit_code(runner, monkeypatch) -> None: |
| 95 | + monkeypatch.setattr( |
| 96 | + lighthouse_cmd, |
| 97 | + "get_lighthouse_status", |
| 98 | + lambda **kwargs: (_ for _ in ()).throw(RuntimeError("unexpected")), |
| 99 | + ) |
| 100 | + result = runner.invoke(app, ["lighthouse", "status"]) |
| 101 | + assert result.exit_code == int(ExitCode.CONFIG_ERROR) |
| 102 | + |
| 103 | + |
71 | 104 | def test_lighthouse_status_works_without_active_profile(runner, monkeypatch, tmp_path) -> None: |
72 | 105 | _write_unconfigured_config(monkeypatch, tmp_path) |
73 | 106 | seen: dict[str, object] = {} |
@@ -101,6 +134,16 @@ def _fake_status(**kwargs): |
101 | 134 | assert seen["lighthouse_base_url"] == "https://api-latarnia.ksef.mf.gov.pl" |
102 | 135 |
|
103 | 136 |
|
| 137 | +def test_lighthouse_messages_unexpected_error_exit_code(runner, monkeypatch) -> None: |
| 138 | + monkeypatch.setattr( |
| 139 | + lighthouse_cmd, |
| 140 | + "get_lighthouse_messages", |
| 141 | + lambda **kwargs: (_ for _ in ()).throw(RuntimeError("unexpected")), |
| 142 | + ) |
| 143 | + result = runner.invoke(app, ["lighthouse", "messages"]) |
| 144 | + assert result.exit_code == int(ExitCode.CONFIG_ERROR) |
| 145 | + |
| 146 | + |
104 | 147 | def _write_unconfigured_config(monkeypatch, tmp_path: Path) -> Path: |
105 | 148 | config_path = tmp_path / "config.json" |
106 | 149 | config_path.write_text( |
|
0 commit comments