|
20 | 20 | implementations for BaseRequest and we want to test HTTPXRequest anyway."""
|
21 | 21 | import asyncio
|
22 | 22 | import json
|
| 23 | +import logging |
23 | 24 | from collections import defaultdict
|
24 | 25 | from dataclasses import dataclass
|
25 | 26 | from http import HTTPStatus
|
@@ -172,15 +173,22 @@ async def test_replaced_unprintable_char(self, monkeypatch, httpx_request):
|
172 | 173 | # not only implicitly.
|
173 | 174 | assert httpx_request.parse_json_payload(server_response) == {"result": "test_string�"}
|
174 | 175 |
|
175 |
| - async def test_illegal_json_response(self, monkeypatch, httpx_request: HTTPXRequest): |
| 176 | + async def test_illegal_json_response(self, monkeypatch, httpx_request: HTTPXRequest, caplog): |
176 | 177 | # for proper JSON it should be `"result":` instead of `result:`
|
177 | 178 | server_response = b'{result: "test_string"}'
|
178 | 179 |
|
179 | 180 | monkeypatch.setattr(httpx_request, "do_request", mocker_factory(response=server_response))
|
180 | 181 |
|
181 |
| - with pytest.raises(TelegramError, match="Invalid server response"): |
| 182 | + with pytest.raises(TelegramError, match="Invalid server response"), caplog.at_level( |
| 183 | + logging.ERROR |
| 184 | + ): |
182 | 185 | await httpx_request.post(None, None, None)
|
183 | 186 |
|
| 187 | + assert len(caplog.records) == 1 |
| 188 | + record = caplog.records[0] |
| 189 | + assert record.name == "telegram.request.BaseRequest" |
| 190 | + assert record.getMessage().endswith(f'invalid JSON data: "{server_response.decode()}"') |
| 191 | + |
184 | 192 | async def test_chat_migrated(self, monkeypatch, httpx_request: HTTPXRequest):
|
185 | 193 | server_response = b'{"ok": "False", "parameters": {"migrate_to_chat_id": 123}}'
|
186 | 194 |
|
|
0 commit comments