add cert_expires_at

This commit is contained in:
2025-10-15 15:10:47 -03:00
parent 54c92b3996
commit ffa04d9b15
37 changed files with 371 additions and 230 deletions

View File

@@ -1,11 +1,10 @@
import os
from dataclasses import dataclass
from uuid import uuid4
import jsonlines
import pytest
PYTEST_TABLE_NAME = f'pytest-{uuid4()}'
PYTEST_TABLE_NAME = 'pytest'
PK = 'id'
SK = 'sk'

View File

@@ -15,7 +15,7 @@ def test_append_cert(
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
lambda_context: LambdaContext,
):
expires_at = now() + timedelta(days=360)
cert_expires_at = now() + timedelta(days=360)
event = {
'detail': {
'new_image': {
@@ -25,9 +25,7 @@ def test_append_cert(
'id': '431',
'name': 'How to Sing Better',
},
'cert': {
'expires_at': expires_at.isoformat(),
},
'cert_expires_at': cert_expires_at.isoformat(),
'user': {
'id': '1234',
'name': 'Tobias Summit',
@@ -41,7 +39,7 @@ def test_append_cert(
assert app.lambda_handler(event, lambda_context) # type: ignore
# The reporting month is the month before the certificate expires
month_start = (expires_at.replace(day=1) - timedelta(days=1)).replace(day=1)
month_start = (cert_expires_at.replace(day=1) - timedelta(days=1)).replace(day=1)
report_sk = 'MONTH#{}#SCHEDULE#SEND_REPORT_EMAIL'.format(
month_start.strftime('%Y-%m')
)
@@ -54,7 +52,7 @@ def test_append_cert(
)
+ SortKey(
sk='MONTH#{}#ENROLLMENT#e45019d8-be7a-4a82-9b37-12a01f0127bb'.format(
expires_at.strftime('%Y-%m')
cert_expires_at.strftime('%Y-%m')
),
rename_key='enrollment',
),

View File

@@ -36,3 +36,43 @@ def test_issue_cert(
)
assert 'cert' in r
assert 'cert_expires_at' in r
assert (
r['cert']['s3_uri']
== 's3://saladeaula.digital/certs/1ee108ae-67d4-4545-bf6d-4e641cdaa4e0.pdf'
)
def test_non_exp_interval(
seeds,
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
lambda_context: LambdaContext,
):
enrollment_id = '1ee108ae-67d4-4545-bf6d-4e641cdaa4e0'
event = {
'detail': {
'new_image': {
'id': enrollment_id,
'completed_at': '2025-09-21T14:20:36.276467-03:00',
'started_at': '2025-09-19T14:34:54.704548-03:00',
'user': {
'name': 'Josh Kiszka',
'cpf': '74630003037',
},
'course': {
'id': '12334',
'name': 'pytest',
},
'score': 79,
'status': 'COMPLETED',
}
}
}
assert app.lambda_handler(event, lambda_context) # type: ignore
r = dynamodb_persistence_layer.get_item(
key=KeyPair('1ee108ae-67d4-4545-bf6d-4e641cdaa4e0', '0')
)
assert 'cert' in r
assert 'cert_expires_at' not in r

View File

@@ -12,7 +12,7 @@
// Course
{"id": "123", "sk": "0", "access_period": 360, "cert": {"exp_interval": 700, "s3_uri": "s3://saladeaula.digital/certs/samples/cipa-grau-de-risco-1.html"}, "created_at": "2025-07-14T15:09:18.559528-03:00", "metadata__konviva_class_id": "281", "name": "pytest", "tenant_id": "*"}
{"id": "12334", "sk": "0", "access_period": 360}
{"id": "12334", "sk": "0", "access_period": 360, "cert": {"s3_uri": "s3://saladeaula.digital/certs/samples/cipa-grau-de-risco-1.html"}}
{"id": "a955518e-ebcb-4441-b914-ddc9ecef84f0", "sk": "0", "access_period": "360", "cert": {"exp_interval": 360}, "created_at": "2025-07-14T15:09:18.559528-03:00", "metadata__konviva_class_id": "281", "name": "NR-11 Operador de Munck", "tenant_id": "*"}
{"id": "6a403773-aeac-4e6a-ac39-dc958e4be52a", "sk": "0", "access_period": "360", "cert": {"exp_interval": 360}, "created_at": "2025-07-14T15:09:18.559528-03:00", "metadata__konviva_class_id": "281", "name": "Reciclagem em NR-11 - Operador de Empilhadeira", "tenant_id": "*"}
{"id": "e1c44881-2fe3-484e-ada2-12b6bf5b9398", "sk": "0", "name": "NR-35 Segurança nos Trabalhos em Altura (Teórico)", "updated_at": "2025-08-22T00:00:24.431267-03:00", "access_period": 360, "created_at": "2024-12-30T00:11:33.088916-03:00", "metadata__konviva_class_id": 1, "tenant_id": "*", "cert": {"exp_interval": 700}, "metadata__unit_price": 119}