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

@@ -7,7 +7,12 @@ requires-python = ">=3.12"
dependencies = ["layercake"]
[dependency-groups]
dev = ["pytest>=8.3.4", "pytest-cov>=6.0.0", "ruff>=0.9.1"]
dev = [
"pytest>=8.3.4",
"pytest-cov>=6.0.0",
"pytest-env>=1.1.5",
"ruff>=0.9.1",
]
[tool.pytest.ini_options]
addopts = "--cov --cov-report html -v"

5
http-api/pytest.ini Normal file
View File

@@ -0,0 +1,5 @@
[pytest]
env =
DYNAMODB_ENDPOINT_URL=http://127.0.0.1:8000
DYNAMODB_PARTITION_KEY=id
DYNAMODB_SORT_KEY=sk

View File

@@ -36,6 +36,7 @@ Globals:
COURSE_TABLE: !Ref CourseTable
ELASTIC_CLOUD_ID: "{{resolve:ssm:/betaeducacao/elastic/cloud_id/str}}"
ELASTIC_AUTH_PASS: "{{resolve:ssm:/betaeducacao/elastic/auth_pass/str}}"
DYNAMODB_PARTITION_KEY: id
Resources:
HttpLog:

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

15
http-api/uv.lock generated
View File

@@ -353,6 +353,7 @@ dependencies = [
dev = [
{ name = "pytest" },
{ name = "pytest-cov" },
{ name = "pytest-env" },
{ name = "ruff" },
]
@@ -363,6 +364,7 @@ requires-dist = [{ name = "layercake", directory = "../layercake" }]
dev = [
{ name = "pytest", specifier = ">=8.3.4" },
{ name = "pytest-cov", specifier = ">=6.0.0" },
{ name = "pytest-env", specifier = ">=1.1.5" },
{ name = "ruff", specifier = ">=0.9.1" },
]
@@ -444,6 +446,7 @@ requires-dist = [
dev = [
{ name = "pytest", specifier = ">=8.3.5" },
{ name = "pytest-cov", specifier = ">=6.0.0" },
{ name = "pytest-env", specifier = ">=1.1.5" },
{ name = "ruff", specifier = ">=0.11.1" },
]
@@ -638,6 +641,18 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/36/3b/48e79f2cd6a61dbbd4807b4ed46cb564b4fd50a76166b1c4ea5c1d9e2371/pytest_cov-6.0.0-py3-none-any.whl", hash = "sha256:eee6f1b9e61008bd34975a4d5bab25801eb31898b032dd55addc93e96fcaaa35", size = 22949 },
]
[[package]]
name = "pytest-env"
version = "1.1.5"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "pytest" },
]
sdist = { url = "https://files.pythonhosted.org/packages/1f/31/27f28431a16b83cab7a636dce59cf397517807d247caa38ee67d65e71ef8/pytest_env-1.1.5.tar.gz", hash = "sha256:91209840aa0e43385073ac464a554ad2947cc2fd663a9debf88d03b01e0cc1cf", size = 8911 }
wheels = [
{ url = "https://files.pythonhosted.org/packages/de/b8/87cfb16045c9d4092cfcf526135d73b88101aac83bc1adcf82dfb5fd3833/pytest_env-1.1.5-py3-none-any.whl", hash = "sha256:ce90cf8772878515c24b31cd97c7fa1f4481cd68d588419fd45f10ecaee6bc30", size = 6141 },
]
[[package]]
name = "python-dateutil"
version = "2.9.0.post0"