update batch
This commit is contained in:
@@ -1,7 +1,21 @@
|
||||
import os
|
||||
from dataclasses import dataclass
|
||||
|
||||
import jsonlines
|
||||
import pytest
|
||||
|
||||
PYTEST_TABLE_NAME = 'pytest'
|
||||
PK = 'id'
|
||||
SK = 'sk'
|
||||
|
||||
|
||||
# https://docs.pytest.org/en/7.1.x/reference/reference.html#pytest.hookspec.pytest_configure
|
||||
def pytest_configure():
|
||||
os.environ['TZ'] = 'America/Sao_Paulo'
|
||||
os.environ['DYNAMODB_PARTITION_KEY'] = PK
|
||||
os.environ['DYNAMODB_SORT_KEY'] = SK
|
||||
os.environ['USER_TABLE'] = PYTEST_TABLE_NAME
|
||||
|
||||
|
||||
@dataclass
|
||||
class LambdaContext:
|
||||
@@ -14,3 +28,42 @@ class LambdaContext:
|
||||
@pytest.fixture
|
||||
def lambda_context() -> LambdaContext:
|
||||
return LambdaContext()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def dynamodb_client():
|
||||
from boto3clients import dynamodb_client as client
|
||||
|
||||
client.create_table(
|
||||
AttributeDefinitions=[
|
||||
{'AttributeName': PK, 'AttributeType': 'S'},
|
||||
{'AttributeName': SK, 'AttributeType': 'S'},
|
||||
],
|
||||
TableName=PYTEST_TABLE_NAME,
|
||||
KeySchema=[
|
||||
{'AttributeName': PK, 'KeyType': 'HASH'},
|
||||
{'AttributeName': SK, 'KeyType': 'RANGE'},
|
||||
],
|
||||
ProvisionedThroughput={
|
||||
'ReadCapacityUnits': 123,
|
||||
'WriteCapacityUnits': 123,
|
||||
},
|
||||
)
|
||||
|
||||
yield client
|
||||
|
||||
client.delete_table(TableName=PYTEST_TABLE_NAME)
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def dynamodb_persistence_layer(dynamodb_client):
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer
|
||||
|
||||
return DynamoDBPersistenceLayer(PYTEST_TABLE_NAME, dynamodb_client)
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def dynamodb_seeds(dynamodb_client):
|
||||
with jsonlines.open('tests/seeds.jsonl') as lines:
|
||||
for line in lines:
|
||||
dynamodb_client.put_item(TableName=PYTEST_TABLE_NAME, Item=line)
|
||||
|
||||
@@ -13,7 +13,7 @@ event = {
|
||||
'source': 'sergio@somosbeta.com.br',
|
||||
'messageId': '2994higq3tr7efijr3lj65etntffapgg1q7hea81',
|
||||
'destination': [
|
||||
'org+35980592000130@users.noreply.saladeaula.digital'
|
||||
'org+15608435000190@users.noreply.saladeaula.digital'
|
||||
],
|
||||
'headersTruncated': False,
|
||||
'headers': [
|
||||
@@ -93,7 +93,7 @@ event = {
|
||||
{'name': 'Subject', 'value': 'Re: test'},
|
||||
{
|
||||
'name': 'To',
|
||||
'value': 'org+35980592000130@users.noreply.saladeaula.digital',
|
||||
'value': 'org+15608435000190@users.noreply.saladeaula.digital',
|
||||
},
|
||||
{
|
||||
'name': 'Content-Type',
|
||||
@@ -104,7 +104,7 @@ event = {
|
||||
'returnPath': 'sergio@somosbeta.com.br',
|
||||
'from': ['"Sérgio Rafael Siqueira" <sergio@somosbeta.com.br>'],
|
||||
'date': 'Thu, 29 May 2025 12:50:26 -0300',
|
||||
'to': ['org+35980592000130@users.noreply.saladeaula.digital'],
|
||||
'to': ['org+15608435000190@users.noreply.saladeaula.digital'],
|
||||
'messageId': '<CAMThe4=yMRJg4YOcACYAR509N1RyWyQgAghyVmr=NuSJnbondg@mail.gmail.com>',
|
||||
'subject': 'Re: test',
|
||||
},
|
||||
@@ -113,7 +113,7 @@ event = {
|
||||
'timestamp': '2025-05-29T15:50:41.604Z',
|
||||
'processingTimeMillis': 1105,
|
||||
'recipients': [
|
||||
'org+35980592000130@users.noreply.saladeaula.digital'
|
||||
'org+15608435000190@users.noreply.saladeaula.digital'
|
||||
],
|
||||
'spamVerdict': {'status': 'PASS'},
|
||||
'virusVerdict': {'status': 'PASS'},
|
||||
@@ -132,5 +132,5 @@ event = {
|
||||
}
|
||||
|
||||
|
||||
def test_email_receiving(lambda_context: LambdaContext):
|
||||
def test_email_receiving(dynamodb_seeds, lambda_context: LambdaContext):
|
||||
assert app.lambda_handler(event, lambda_context) == {'disposition': 'CONTINUE'}
|
||||
|
||||
Reference in New Issue
Block a user