mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Implement AWS DynamoDB storage
This commit is contained in:
parent
69c9ecb7e0
commit
51c1bf48e2
3 changed files with 253 additions and 0 deletions
|
|
@ -4,6 +4,7 @@ import pytest_asyncio
|
|||
import aioredis
|
||||
import pytest
|
||||
from _pytest.config import UsageError
|
||||
from aiodynamo.credentials import Key, StaticCredentials
|
||||
|
||||
from aiogram import Bot
|
||||
from . import TOKEN
|
||||
|
|
@ -20,6 +21,11 @@ def pytest_addoption(parser):
|
|||
default=None,
|
||||
help="run tests which require redis connection",
|
||||
)
|
||||
parser.addoption(
|
||||
"--dynamodb",
|
||||
default=None,
|
||||
help="run tests which require dynamodb-local connection",
|
||||
)
|
||||
parser.addini("asyncio_mode", "", default='auto')
|
||||
|
||||
|
||||
|
|
@ -81,6 +87,24 @@ def redis_options(request):
|
|||
raise UsageError("Unsupported aioredis version")
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="session")
|
||||
def dynamodb_options(request):
|
||||
dynamodb_uri = request.config.getoption("--dynamodb")
|
||||
if dynamodb_uri is None:
|
||||
pytest.skip("need --dynamodb option with dynamodb-local URI to run")
|
||||
return
|
||||
return {
|
||||
"credentials": StaticCredentials(
|
||||
Key(
|
||||
"DUMMYIDEXAMPLE",
|
||||
"DUMMYEXAMPLEKEY",
|
||||
)
|
||||
),
|
||||
"region": "dummy-region-1",
|
||||
"endpoint": dynamodb_uri,
|
||||
}
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(name='bot')
|
||||
async def bot_fixture():
|
||||
"""Bot fixture."""
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import pytest_asyncio
|
|||
from pytest_lazyfixture import lazy_fixture
|
||||
from redis.asyncio.connection import Connection, ConnectionPool
|
||||
|
||||
from aiogram.contrib.fsm_storage.dynamodb import DynamoDBStorage
|
||||
from aiogram.contrib.fsm_storage.memory import MemoryStorage
|
||||
from aiogram.contrib.fsm_storage.redis import RedisStorage, RedisStorage2
|
||||
|
||||
|
|
@ -42,11 +43,17 @@ async def memory_store():
|
|||
yield MemoryStorage()
|
||||
|
||||
|
||||
@pytest_asyncio.fixture()
|
||||
async def dynamodb_store(dynamodb_options):
|
||||
yield DynamoDBStorage(**dynamodb_options)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"store", [
|
||||
lazy_fixture('redis_store'),
|
||||
lazy_fixture('redis_store2'),
|
||||
lazy_fixture('memory_store'),
|
||||
lazy_fixture("dynamodb_store"),
|
||||
]
|
||||
)
|
||||
class TestStorage:
|
||||
|
|
@ -89,6 +96,15 @@ class TestRedisStorage2:
|
|||
connection: Connection = pool._available_connections[0]
|
||||
assert connection.is_connected is False
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"store", [
|
||||
lazy_fixture("redis_store"),
|
||||
lazy_fixture("redis_store2"),
|
||||
lazy_fixture("dynamodb_store"),
|
||||
]
|
||||
)
|
||||
class TestStorage2:
|
||||
@pytest.mark.parametrize(
|
||||
"chat_id,user_id,state",
|
||||
[
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue