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:
@@ -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)
|
||||
Reference in New Issue
Block a user