add exception to transact

This commit is contained in:
2025-05-21 19:16:06 -03:00
parent 249116cc76
commit 4673a7b21c
3 changed files with 118 additions and 55 deletions

View File

@@ -3,7 +3,6 @@ from decimal import Decimal
from ipaddress import IPv4Address
import pytest
from botocore.exceptions import ClientError
from layercake.dateutils import ttl
from layercake.dynamodb import (
@@ -94,6 +93,8 @@ def test_transact_write_items(
dynamodb_seeds,
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
):
class EmailConflictError(Exception): ...
transact = TransactItems(dynamodb_persistence_layer.table_name)
transact.put(item=KeyPair('5OxmMjL-ujoR5IMGegQz', '0'))
transact.put(item=KeyPair('cpf', '07879819908'))
@@ -107,10 +108,12 @@ def test_transact_write_items(
ComposeKey('sergio@somosbeta.com.br', 'emails'),
),
cond_expr='attribute_not_exists(sk)',
exc_cls=EmailConflictError,
)
with pytest.raises(ClientError):
with pytest.raises(EmailConflictError) as exc:
dynamodb_persistence_layer.transact_write_items(transact)
# print(exc.value)
def test_collection_get_item(
@@ -151,7 +154,7 @@ def test_collection_get_item(
with pytest.raises(NotFoundError):
collect.get_item(
KeyPair('5OxmMjL-ujoR5IMGegQz', 'notfound'),
exception_cls=NotFoundError,
exc_cls=NotFoundError,
)