mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 02:03:04 +00:00
Upgrade architecture + 5.0 Bot API (#469)
Upgrade architecture + 5.0 Bot API (#469) * Moved `methods`, `types` and `client` to root package * Removed update handler from routers to dispatcher * Reworked events propagation mechanism to handlers * Reworked inner middlewares logic (very small change) * Updated to Bot API 5.0 * Initial migration from MkDocs to Sphinx + config for readthedocs
This commit is contained in:
parent
566b7ff282
commit
4008a3114d
608 changed files with 12537 additions and 6427 deletions
|
|
@ -1,4 +1,4 @@
|
|||
from aiogram.api.client.telegram import PRODUCTION
|
||||
from aiogram.client.telegram import PRODUCTION, TelegramAPIServer
|
||||
|
||||
|
||||
class TestAPIServer:
|
||||
|
|
@ -9,3 +9,13 @@ class TestAPIServer:
|
|||
def test_file_url(self):
|
||||
file_url = PRODUCTION.file_url(token="42:TEST", path="path")
|
||||
assert file_url == "https://api.telegram.org/file/bot42:TEST/path"
|
||||
|
||||
def test_from_base(self):
|
||||
local_server = TelegramAPIServer.from_base("http://localhost:8081", is_local=True)
|
||||
|
||||
method_url = local_server.api_url("42:TEST", method="apiMethod")
|
||||
file_url = local_server.file_url(token="42:TEST", path="path")
|
||||
|
||||
assert method_url == "http://localhost:8081/bot42:TEST/apiMethod"
|
||||
assert file_url == "http://localhost:8081/file/bot42:TEST/path"
|
||||
assert local_server.is_local
|
||||
|
|
|
|||
|
|
@ -5,15 +5,16 @@ import pytest
|
|||
from aresponses import ResponsesMockServer
|
||||
|
||||
from aiogram import Bot
|
||||
from aiogram.api.client.session.aiohttp import AiohttpSession
|
||||
from aiogram.api.methods import GetFile, GetMe
|
||||
from aiogram.api.types import File, PhotoSize
|
||||
from aiogram.client.session.aiohttp import AiohttpSession
|
||||
from aiogram.methods import GetFile, GetMe
|
||||
from aiogram.types import File, PhotoSize
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
try:
|
||||
from asynctest import CoroutineMock, patch
|
||||
except ImportError:
|
||||
from unittest.mock import AsyncMock as CoroutineMock, patch # type: ignore
|
||||
from unittest.mock import AsyncMock as CoroutineMock # type: ignore
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
class TestBot:
|
||||
|
|
@ -38,7 +39,7 @@ class TestBot:
|
|||
method = GetMe()
|
||||
|
||||
with patch(
|
||||
"aiogram.api.client.session.aiohttp.AiohttpSession.make_request",
|
||||
"aiogram.client.session.aiohttp.AiohttpSession.make_request",
|
||||
new_callable=CoroutineMock,
|
||||
) as mocked_make_request:
|
||||
await bot(method)
|
||||
|
|
@ -51,16 +52,16 @@ class TestBot:
|
|||
await session.create_session()
|
||||
|
||||
with patch(
|
||||
"aiogram.api.client.session.aiohttp.AiohttpSession.close", new_callable=CoroutineMock
|
||||
"aiogram.client.session.aiohttp.AiohttpSession.close", new_callable=CoroutineMock
|
||||
) as mocked_close:
|
||||
await bot.close()
|
||||
await bot.session.close()
|
||||
mocked_close.assert_awaited()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize("close", [True, False])
|
||||
async def test_context_manager(self, close: bool):
|
||||
with patch(
|
||||
"aiogram.api.client.session.aiohttp.AiohttpSession.close", new_callable=CoroutineMock
|
||||
"aiogram.client.session.aiohttp.AiohttpSession.close", new_callable=CoroutineMock
|
||||
) as mocked_close:
|
||||
async with Bot("42:TEST", session=AiohttpSession()).context(auto_close=close) as bot:
|
||||
assert isinstance(bot, Bot)
|
||||
|
|
|
|||
|
|
@ -1,20 +1,21 @@
|
|||
from typing import AsyncContextManager, AsyncGenerator
|
||||
|
||||
import aiohttp
|
||||
import aiohttp_socks
|
||||
import pytest
|
||||
from aresponses import ResponsesMockServer
|
||||
|
||||
from aiogram import Bot
|
||||
from aiogram.api.client.session.aiohttp import AiohttpSession
|
||||
from aiogram.api.methods import Request, TelegramMethod
|
||||
from aiogram.api.types import InputFile, UNSET
|
||||
from aiogram.client.session import aiohttp
|
||||
from aiogram.client.session.aiohttp import AiohttpSession
|
||||
from aiogram.methods import Request, TelegramMethod
|
||||
from aiogram.types import InputFile, UNSET
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
try:
|
||||
from asynctest import CoroutineMock, patch
|
||||
except ImportError:
|
||||
from unittest.mock import AsyncMock as CoroutineMock, patch # type: ignore
|
||||
from unittest.mock import AsyncMock as CoroutineMock # type: ignore
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
class BareInputFile(InputFile):
|
||||
|
|
@ -172,7 +173,7 @@ class TestAiohttpSession:
|
|||
|
||||
call = TestMethod()
|
||||
with patch(
|
||||
"aiogram.api.client.session.base.BaseSession.raise_for_status"
|
||||
"aiogram.client.session.base.BaseSession.raise_for_status"
|
||||
) as patched_raise_for_status:
|
||||
result = await session.make_request(bot, call)
|
||||
assert isinstance(result, int)
|
||||
|
|
@ -206,12 +207,12 @@ class TestAiohttpSession:
|
|||
assert isinstance(session, AsyncContextManager)
|
||||
|
||||
with patch(
|
||||
"aiogram.api.client.session.aiohttp.AiohttpSession.create_session",
|
||||
"aiogram.client.session.aiohttp.AiohttpSession.create_session",
|
||||
new_callable=CoroutineMock,
|
||||
) as mocked_create_session, patch(
|
||||
"aiogram.api.client.session.aiohttp.AiohttpSession.close", new_callable=CoroutineMock
|
||||
"aiogram.client.session.aiohttp.AiohttpSession.close", new_callable=CoroutineMock
|
||||
) as mocked_close:
|
||||
async with session as ctx:
|
||||
assert session == ctx
|
||||
mocked_close.awaited_once()
|
||||
mocked_create_session.awaited_once()
|
||||
mocked_close.assert_awaited_once()
|
||||
mocked_create_session.assert_awaited_once()
|
||||
|
|
|
|||
|
|
@ -4,15 +4,16 @@ from typing import AsyncContextManager, AsyncGenerator, Optional
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.client.session.base import BaseSession, T
|
||||
from aiogram.api.client.telegram import PRODUCTION, TelegramAPIServer
|
||||
from aiogram.api.methods import GetMe, Response, TelegramMethod
|
||||
from aiogram.api.types import UNSET
|
||||
from aiogram.client.session.base import BaseSession, T
|
||||
from aiogram.client.telegram import PRODUCTION, TelegramAPIServer
|
||||
from aiogram.methods import GetMe, Response, TelegramMethod
|
||||
from aiogram.types import UNSET
|
||||
|
||||
try:
|
||||
from asynctest import CoroutineMock, patch
|
||||
except ImportError:
|
||||
from unittest.mock import AsyncMock as CoroutineMock, patch # type: ignore
|
||||
from unittest.mock import AsyncMock as CoroutineMock # type: ignore
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
class CustomSession(BaseSession):
|
||||
|
|
@ -169,4 +170,4 @@ class TestBaseSession:
|
|||
) as mocked_close:
|
||||
async with session as ctx:
|
||||
assert session == ctx
|
||||
mocked_close.awaited_once()
|
||||
mocked_close.assert_awaited_once()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue