add forgot endpoint

This commit is contained in:
2025-12-04 15:39:44 -03:00
parent c3917addfa
commit d29ad3ceb6
14 changed files with 267 additions and 30 deletions

View File

@@ -16,7 +16,7 @@ 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['OAUTH2_TABLE'] = PYTEST_TABLE_NAME
os.environ['USER_TABLE'] = PYTEST_TABLE_NAME
os.environ['SESSION_SECRET'] = 'secret'
os.environ['DYNAMODB_PARTITION_KEY'] = PK
os.environ['DYNAMODB_SORT_KEY'] = SK

View File

@@ -0,0 +1,19 @@
from aws_lambda_powertools.utilities.typing.lambda_context import LambdaContext
import events.send_forgot_email as app
def test_send_forgot_email(monkeypatch, lambda_context: LambdaContext):
monkeypatch.setattr(app.sesv2_client, 'send_email', lambda *args, **kwargs: ...)
event = {
'detail': {
'new_image': {
'id': 'PASSWORD_RESET',
'sk': 'CODE#123',
'name': 'Sérgio R Siqueira',
'email': 'sergio@somosbeta.com.br',
}
}
}
assert app.lambda_handler(event, lambda_context) # type: ignore

View File

@@ -0,0 +1,37 @@
from http import HTTPMethod
from layercake.dynamodb import DynamoDBPersistenceLayer, PartitionKey
from ..conftest import HttpApiProxy, LambdaContext
def test_forgot(
app,
seeds,
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
http_api_proxy: HttpApiProxy,
lambda_context: LambdaContext,
):
r = app.lambda_handler(
http_api_proxy(
raw_path='/forgot',
method=HTTPMethod.POST,
body={'username': '07879819908'},
),
lambda_context,
)
assert 's****io@somosbeta.com.br' == r['body']['email']
app.lambda_handler(
http_api_proxy(
raw_path='/forgot',
method=HTTPMethod.POST,
body={'username': '07879819908'},
),
lambda_context,
)
forgot = dynamodb_persistence_layer.collection.query(
PartitionKey('PASSWORD_RESET'),
)
assert len(forgot['items']) == 3