This commit is contained in:
2025-03-20 21:26:04 -03:00
parent 85cbc9269c
commit 1f19380f5c
20 changed files with 293 additions and 54 deletions

View File

@@ -2,8 +2,14 @@ import base64
import json
from dataclasses import dataclass
from http import HTTPMethod
from typing import Generator
import boto3
import pytest
from layercake.dynamodb import DynamoDBPersistenceLayer
table_name = 'pytest'
dynamodb_endpoint_url = 'http://127.0.0.1:8000'
@dataclass
@@ -86,6 +92,36 @@ def http_api_proxy():
return HttpApiProxy()
@pytest.fixture
def dynamodb_client():
return boto3.client('dynamodb', endpoint_url=dynamodb_endpoint_url)
@pytest.fixture()
def dynamodb_persistence_layer(
dynamodb_client,
) -> Generator[DynamoDBPersistenceLayer, None, None]:
dynamodb_client.create_table(
AttributeDefinitions=[
{'AttributeName': 'id', 'AttributeType': 'S'},
{'AttributeName': 'sk', 'AttributeType': 'S'},
],
TableName=table_name,
KeySchema=[
{'AttributeName': 'id', 'KeyType': 'HASH'},
{'AttributeName': 'sk', 'KeyType': 'RANGE'},
],
ProvisionedThroughput={
'ReadCapacityUnits': 123,
'WriteCapacityUnits': 123,
},
)
yield DynamoDBPersistenceLayer(table_name, dynamodb_client)
dynamodb_client.delete_table(TableName=table_name)
@pytest.fixture
def mock_app(monkeypatch):
monkeypatch.setattr('settings.ELASTIC_CONN', {'hosts': 'http://127.0.0.1:9200'})