mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 10:11:52 +00:00
Dev 3.x i18n & improvements (#696)
* Added base code and make code improvements * Auto-exclude coverage for `if TYPE_CHECKING:` * Fixed current coverage * Cover I18n module * Update pipeline * Fixed annotations * Added docs * Move exceptions * Added tests for KeyboardBuilder and initial docs * Remove help generator (removed from sources tree, requires rewrite) * Added patch-notes #698, #699, #700, #701, #702, #703
This commit is contained in:
parent
5bd1162f57
commit
e4046095d7
223 changed files with 1909 additions and 1121 deletions
|
|
@ -1,4 +1,6 @@
|
|||
import io
|
||||
import os
|
||||
from tempfile import mkstemp
|
||||
|
||||
import aiofiles
|
||||
import pytest
|
||||
|
|
@ -6,6 +8,7 @@ from aresponses import ResponsesMockServer
|
|||
|
||||
from aiogram import Bot
|
||||
from aiogram.client.session.aiohttp import AiohttpSession
|
||||
from aiogram.client.telegram import TelegramAPIServer
|
||||
from aiogram.methods import GetFile, GetMe
|
||||
from aiogram.types import File, PhotoSize
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
|
@ -128,3 +131,15 @@ class TestBot:
|
|||
await bot.download(
|
||||
[PhotoSize(file_id="file id", file_unique_id="file id", width=123, height=123)]
|
||||
)
|
||||
|
||||
async def test_download_local_file(self, bot: MockedBot):
|
||||
bot.session.api = TelegramAPIServer.from_base("http://localhost:8081", is_local=True)
|
||||
fd, tmp = mkstemp(prefix="test-", suffix=".txt")
|
||||
value = b"KABOOM"
|
||||
try:
|
||||
with open(fd, "wb") as f:
|
||||
f.write(value)
|
||||
content = await bot.download_file(tmp)
|
||||
assert content.getvalue() == value
|
||||
finally:
|
||||
os.unlink(tmp)
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ from aresponses import ResponsesMockServer
|
|||
from aiogram import Bot
|
||||
from aiogram.client.session import aiohttp
|
||||
from aiogram.client.session.aiohttp import AiohttpSession
|
||||
from aiogram.exceptions import TelegramNetworkError
|
||||
from aiogram.methods import Request, TelegramMethod
|
||||
from aiogram.types import UNSET, InputFile
|
||||
from aiogram.utils.exceptions.network import NetworkError
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
try:
|
||||
|
|
@ -187,7 +187,7 @@ class TestAiohttpSession:
|
|||
new_callable=CoroutineMock,
|
||||
side_effect=side_effect,
|
||||
):
|
||||
with pytest.raises(NetworkError):
|
||||
with pytest.raises(TelegramNetworkError):
|
||||
await bot.get_me()
|
||||
|
||||
async def test_stream_content(self, aresponses: ResponsesMockServer):
|
||||
|
|
|
|||
|
|
@ -7,16 +7,21 @@ import pytest
|
|||
from aiogram import Bot
|
||||
from aiogram.client.session.base import BaseSession, TelegramType
|
||||
from aiogram.client.telegram import PRODUCTION, TelegramAPIServer
|
||||
from aiogram.exceptions import (
|
||||
RestartingTelegram,
|
||||
TelegramAPIError,
|
||||
TelegramBadRequest,
|
||||
TelegramConflictError,
|
||||
TelegramEntityTooLarge,
|
||||
TelegramForbiddenError,
|
||||
TelegramMigrateToChat,
|
||||
TelegramNotFound,
|
||||
TelegramRetryAfter,
|
||||
TelegramServerError,
|
||||
TelegramUnauthorizedError,
|
||||
)
|
||||
from aiogram.methods import DeleteMessage, GetMe, TelegramMethod
|
||||
from aiogram.types import UNSET, User
|
||||
from aiogram.utils.exceptions.bad_request import BadRequest
|
||||
from aiogram.utils.exceptions.base import TelegramAPIError
|
||||
from aiogram.utils.exceptions.conflict import ConflictError
|
||||
from aiogram.utils.exceptions.network import EntityTooLarge
|
||||
from aiogram.utils.exceptions.not_found import NotFound
|
||||
from aiogram.utils.exceptions.server import RestartingTelegram, ServerError
|
||||
from aiogram.utils.exceptions.special import MigrateToChat, RetryAfter
|
||||
from aiogram.utils.exceptions.unauthorized import UnauthorizedError
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
try:
|
||||
|
|
@ -153,25 +158,25 @@ class TestBaseSession:
|
|||
"status_code,content,error",
|
||||
[
|
||||
[200, '{"ok":true,"result":true}', None],
|
||||
[400, '{"ok":false,"description":"test"}', BadRequest],
|
||||
[400, '{"ok":false,"description":"test"}', TelegramBadRequest],
|
||||
[
|
||||
400,
|
||||
'{"ok":false,"description":"test", "parameters": {"retry_after": 1}}',
|
||||
RetryAfter,
|
||||
TelegramRetryAfter,
|
||||
],
|
||||
[
|
||||
400,
|
||||
'{"ok":false,"description":"test", "parameters": {"migrate_to_chat_id": -42}}',
|
||||
MigrateToChat,
|
||||
TelegramMigrateToChat,
|
||||
],
|
||||
[404, '{"ok":false,"description":"test"}', NotFound],
|
||||
[401, '{"ok":false,"description":"test"}', UnauthorizedError],
|
||||
[403, '{"ok":false,"description":"test"}', UnauthorizedError],
|
||||
[409, '{"ok":false,"description":"test"}', ConflictError],
|
||||
[413, '{"ok":false,"description":"test"}', EntityTooLarge],
|
||||
[404, '{"ok":false,"description":"test"}', TelegramNotFound],
|
||||
[401, '{"ok":false,"description":"test"}', TelegramUnauthorizedError],
|
||||
[403, '{"ok":false,"description":"test"}', TelegramForbiddenError],
|
||||
[409, '{"ok":false,"description":"test"}', TelegramConflictError],
|
||||
[413, '{"ok":false,"description":"test"}', TelegramEntityTooLarge],
|
||||
[500, '{"ok":false,"description":"restarting"}', RestartingTelegram],
|
||||
[500, '{"ok":false,"description":"test"}', ServerError],
|
||||
[502, '{"ok":false,"description":"test"}', ServerError],
|
||||
[500, '{"ok":false,"description":"test"}', TelegramServerError],
|
||||
[502, '{"ok":false,"description":"test"}', TelegramServerError],
|
||||
[499, '{"ok":false,"description":"test"}', TelegramAPIError],
|
||||
[499, '{"ok":false,"description":"test"}', TelegramAPIError],
|
||||
],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue