Added more details when server send invalid response

This commit is contained in:
Alex Root Junior 2022-10-02 19:22:12 +03:00
parent 44ae565149
commit efae83d337
No known key found for this signature in database
GPG key ID: 074C1D455EBEA4AC
4 changed files with 56 additions and 3 deletions

View file

@ -8,6 +8,7 @@ from aiogram import Bot
from aiogram.client.session.base import BaseSession, TelegramType
from aiogram.client.telegram import PRODUCTION, TelegramAPIServer
from aiogram.exceptions import (
ClientDecodeError,
RestartingTelegram,
TelegramAPIError,
TelegramBadRequest,
@ -183,6 +184,28 @@ class TestBaseSession:
if error.url:
assert error.url in string
def test_check_response_json_decode_error(self):
session = CustomSession()
method = DeleteMessage(chat_id=42, message_id=42)
with pytest.raises(ClientDecodeError, match="JSONDecodeError"):
session.check_response(
method=method,
status_code=200,
content="is not a JSON object",
)
def test_check_response_validation_error(self):
session = CustomSession()
method = DeleteMessage(chat_id=42, message_id=42)
with pytest.raises(ClientDecodeError, match="ValidationError"):
session.check_response(
method=method,
status_code=200,
content='{"ok": "test"}',
)
async def test_make_request(self):
session = CustomSession()