refactor: migrate api_client.py prints to structured logging

Replace all print() calls with logger.info/logger.error using
lazy % formatting. Add test verifying error path emits ERROR log.

U2 of P2-001 (replace print with logging)
This commit is contained in:
2026-04-30 23:49:23 +02:00
parent 390853eb60
commit 060c0b0e0a
2 changed files with 36 additions and 12 deletions
+19
View File
@@ -0,0 +1,19 @@
import logging
from unittest.mock import patch
import pytest
from api_client import TweedeKamerAPI
class TestTweedeKamerAPILogging:
def test_get_motions_error_logged(self, caplog):
api = TweedeKamerAPI()
caplog.set_level(logging.ERROR, logger="api_client")
with patch.object(api, "_get_voting_records", side_effect=Exception("network down")):
result = api.get_motions()
assert result == []
assert any("network down" in rec.message for rec in caplog.records)
assert any(rec.levelno == logging.ERROR for rec in caplog.records)