Merge branch 'aiogram:dev-3.x' into dev-3.x

This commit is contained in:
m-xim 2025-02-14 01:32:22 +03:00 committed by GitHub
commit b939b4e95d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 27 additions and 14 deletions

View file

@ -1,5 +1,7 @@
from pathlib import Path
import pytest
from aiogram.client.telegram import (
PRODUCTION,
BareFilesPathWrapper,
@ -13,15 +15,17 @@ class TestAPIServer:
method_url = PRODUCTION.api_url(token="42:TEST", method="apiMethod")
assert method_url == "https://api.telegram.org/bot42:TEST/apiMethod"
def test_file_url(self):
file_url = PRODUCTION.file_url(token="42:TEST", path="path")
@pytest.mark.parametrize("path", ["path", Path("path")])
def test_file_url(self, path):
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):
@pytest.mark.parametrize("path", ["path", Path("path")])
def test_from_base(self, path):
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")
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"

View file

@ -1,5 +1,6 @@
import io
import os
from pathlib import Path
from tempfile import mkstemp
from unittest.mock import AsyncMock, MagicMock, patch
@ -112,7 +113,8 @@ class TestBot:
mocked_close.assert_not_awaited()
await session.close()
async def test_download_file(self, aresponses: ResponsesMockServer):
@pytest.mark.parametrize("file_path", ["file.png", Path("file.png")])
async def test_download_file(self, aresponses: ResponsesMockServer, file_path):
aresponses.add(
method_pattern="get",
response=aresponses.Response(status=200, body=b"\f" * 10),
@ -127,7 +129,7 @@ class TestBot:
async with Bot("42:TEST").context() as bot:
with patch("aiofiles.threadpool.sync_open", return_value=mock_file):
await bot.download_file("TEST", "file.png")
await bot.download_file("TEST", file_path)
mock_file.write.assert_called_once_with(b"\f" * 10)
async def test_download_file_default_destination(

View file

@ -10,12 +10,14 @@ PAYLOADS = [
"aaBBccDDeeFF5544332211",
-12345678901234567890,
12345678901234567890,
"underscore_and-dash",
]
WRONG_PAYLOADS = [
"@BotFather",
"Some:special$characters#=",
"spaces spaces spaces",
1234567890123456789.0,
"has`backtick",
]