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)
