mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 18:19:34 +00:00
Rework session DI and files path wrapper
This commit is contained in:
parent
1357a7a91b
commit
2620a6547c
9 changed files with 98 additions and 40 deletions
|
|
@ -1,4 +1,11 @@
|
|||
from aiogram.client.telegram import PRODUCTION, TelegramAPIServer
|
||||
from pathlib import Path
|
||||
|
||||
from aiogram.client.telegram import (
|
||||
PRODUCTION,
|
||||
BareFilesPathWrapper,
|
||||
SimpleFilesPathWrapper,
|
||||
TelegramAPIServer,
|
||||
)
|
||||
|
||||
|
||||
class TestAPIServer:
|
||||
|
|
@ -19,3 +26,27 @@ class TestAPIServer:
|
|||
assert method_url == "http://localhost:8081/bot42:TEST/apiMethod"
|
||||
assert file_url == "http://localhost:8081/file/bot42:TEST/path"
|
||||
assert local_server.is_local
|
||||
|
||||
|
||||
class TestBareFilesPathWrapper:
|
||||
def test_to_local(self):
|
||||
wrapper = BareFilesPathWrapper()
|
||||
assert wrapper.to_local("/path/to/file.dat") == "/path/to/file.dat"
|
||||
|
||||
def test_to_server(self):
|
||||
wrapper = BareFilesPathWrapper()
|
||||
assert wrapper.to_server("/path/to/file.dat") == "/path/to/file.dat"
|
||||
|
||||
|
||||
class TestSimpleFilesPathWrapper:
|
||||
def test_to_local(self):
|
||||
wrapper = SimpleFilesPathWrapper(Path("/etc/telegram-bot-api/data"), Path("/opt/app/data"))
|
||||
assert wrapper.to_local("/etc/telegram-bot-api/data/documents/file.dat") == Path(
|
||||
"/opt/app/data/documents/file.dat"
|
||||
)
|
||||
|
||||
def test_to_server(self):
|
||||
wrapper = SimpleFilesPathWrapper(Path("/etc/telegram-bot-api/data"), Path("/opt/app/data"))
|
||||
assert wrapper.to_server("/opt/app/data/documents/file.dat") == Path(
|
||||
"/etc/telegram-bot-api/data/documents/file.dat"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -74,25 +74,6 @@ class TestBaseSession:
|
|||
session.json_loads = custom_loads
|
||||
assert session.json_loads == custom_loads
|
||||
|
||||
def test_timeout(self):
|
||||
session = CustomSession()
|
||||
assert session.timeout == session.default_timeout == CustomSession.default_timeout
|
||||
|
||||
session.default_timeout = float(65.0_0) # mypy will complain
|
||||
assert session.timeout != session.default_timeout
|
||||
|
||||
CustomSession.default_timeout = float(68.0_0)
|
||||
assert session.timeout == CustomSession.default_timeout
|
||||
|
||||
session.timeout = float(71.0_0)
|
||||
assert session.timeout != session.default_timeout
|
||||
del session.timeout
|
||||
CustomSession.default_timeout = session.default_timeout + 100
|
||||
assert (
|
||||
session.timeout != BaseSession.default_timeout
|
||||
and session.timeout == CustomSession.default_timeout
|
||||
)
|
||||
|
||||
def test_init_custom_api(self):
|
||||
api = TelegramAPIServer(
|
||||
base="http://example.com/{token}/{method}",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue