update conftest

This commit is contained in:
2025-03-21 12:29:05 -03:00
parent b22644a165
commit 36b97b1291
8 changed files with 76 additions and 43 deletions

View File

@@ -1,15 +1,17 @@
import base64
import json
import os
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'
PYTEST_TABLE_NAME = os.getenv('PYTEST_TABLE_NAME', 'pytest')
DYNAMODB_ENDPOINT_URL = os.getenv('DYNAMODB_ENDPOINT_URL')
PK = os.getenv('DYNAMODB_PARTITION_KEY', 'pk')
SK = os.getenv('DYNAMODB_SORT_KEY', 'sk')
@dataclass
@@ -94,22 +96,16 @@ def http_api_proxy():
@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(
client = boto3.client('dynamodb', endpoint_url=DYNAMODB_ENDPOINT_URL)
client.create_table(
AttributeDefinitions=[
{'AttributeName': 'id', 'AttributeType': 'S'},
{'AttributeName': 'sk', 'AttributeType': 'S'},
{'AttributeName': PK, 'AttributeType': 'S'},
{'AttributeName': SK, 'AttributeType': 'S'},
],
TableName=table_name,
TableName=PYTEST_TABLE_NAME,
KeySchema=[
{'AttributeName': 'id', 'KeyType': 'HASH'},
{'AttributeName': 'sk', 'KeyType': 'RANGE'},
{'AttributeName': PK, 'KeyType': 'HASH'},
{'AttributeName': SK, 'KeyType': 'RANGE'},
],
ProvisionedThroughput={
'ReadCapacityUnits': 123,
@@ -117,9 +113,14 @@ def dynamodb_persistence_layer(
},
)
yield DynamoDBPersistenceLayer(table_name, dynamodb_client)
yield client
dynamodb_client.delete_table(TableName=table_name)
client.delete_table(TableName=PYTEST_TABLE_NAME)
@pytest.fixture()
def dynamodb_persistence_layer(dynamodb_client) -> DynamoDBPersistenceLayer:
return DynamoDBPersistenceLayer(PYTEST_TABLE_NAME, dynamodb_client)
@pytest.fixture