wip reporting

This commit is contained in:
2025-07-25 11:20:01 -03:00
parent 57cee90187
commit 5eae098098
15 changed files with 269 additions and 213 deletions

View File

@@ -19,7 +19,6 @@ def pytest_configure():
os.environ['COURSE_TABLE'] = PYTEST_TABLE_NAME
os.environ['ENROLLMENT_TABLE'] = PYTEST_TABLE_NAME
os.environ['ORDER_TABLE'] = PYTEST_TABLE_NAME
os.environ['COURSE_TABLE'] = PYTEST_TABLE_NAME
os.environ['LOG_LEVEL'] = 'DEBUG'

View File

@@ -0,0 +1,30 @@
from aws_lambda_powertools.utilities.typing import LambdaContext
from layercake.dynamodb import DynamoDBPersistenceLayer, PartitionKey
import events.reporting.add_item as app
def test_add_item(
dynamodb_seeds,
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
lambda_context: LambdaContext,
):
event = {
'detail': {
'new_image': {
'id': '945e8672-1d72-45c6-b76c-ac06aa8b52ab',
'sk': 'METADATA#BILLING_TERMS',
'billing_day': 5,
'created_at': '2025-07-23T18:09:22.785678-03:00',
'org_id': 'edp8njvgQuzNkLx2ySNfAD',
}
}
}
assert app.lambda_handler(event, lambda_context) # type: ignore
r = dynamodb_persistence_layer.collection.query(
PartitionKey('BILLING#ORG#edp8njvgQuzNkLx2ySNfAD')
)
print(r)

View File

@@ -1,34 +0,0 @@
from decimal import Decimal
from aws_lambda_powertools.utilities.typing import LambdaContext
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair
import events.stopgap.schedule_expired as app
def test_schedule_expired(
dynamodb_client,
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
lambda_context: LambdaContext,
):
event = {
'detail': {
'new_image': {
'id': '123',
'sk': '0',
'due_date': '2025-07-04T08:34:45.780000-03:00',
}
}
}
assert app.lambda_handler(event, lambda_context) # type: ignore
expected = {
'sk': 'schedules#set_as_expired',
'ttl': Decimal('1751715285'),
'id': '123',
}
r = dynamodb_persistence_layer.get_item(
key=KeyPair('123', 'schedules#set_as_expired')
)
assert r['ttl'] == expected['ttl']

View File

@@ -1,25 +0,0 @@
import app.events.set_as_expired as app
def test_set_as_expired(dynamodb_seeds, lambda_context):
event = {
'detail': {
'new_image': {
'id': '9omWNKymwU5U4aeun6mWzZ',
'sk': 'schedules#set_as_expired',
},
}
}
assert app.lambda_handler(event, lambda_context)
def test_set_as_expired_failed(dynamodb_seeds, lambda_context):
event = {
'detail': {
'new_image': {
'id': '18f934d8-035a-4ebc-9f8b-6c84782b8c73',
'sk': 'schedules#set_as_expired',
},
}
}
assert not app.lambda_handler(event, lambda_context)

View File

@@ -10,4 +10,8 @@
{"id": {"S": "vacancies#cJtK9SsnJhKPyxESe7g3DG"}, "sk": {"S": "9omWNKymwU5U4aeun6mWzZ#3"}}
{"id": {"S": "18f934d8-035a-4ebc-9f8b-6c84782b8c73"}, "sk": {"S": "0"}, "payment_method": {"S": "PAID"}}
{"id": {"S": "6a60d026-d383-4707-b093-b6eddea1a24e"}, "sk": {"S": "items"},"items": {"L": [{"M": {"id": {"S": "a810dd22-56c0-4d9b-8cd2-7e2ee9c45839"}, "name": {"S": "pytest"},"quantity": {"N": "1"},"unit_price": {"N": "109"}}}]}}
{"id": {"S": "a810dd22-56c0-4d9b-8cd2-7e2ee9c45839"}, "sk": {"S": "metadata#betaeducacao"},"course_id": {"S": "dc1a0428-47bf-4db1-a5da-24be49c9fda6"},"create_date": {"S": "2025-06-05T12:13:54.371416+00:00"}}
{"id": {"S": "a810dd22-56c0-4d9b-8cd2-7e2ee9c45839"}, "sk": {"S": "metadata#betaeducacao"},"course_id": {"S": "dc1a0428-47bf-4db1-a5da-24be49c9fda6"},"create_date": {"S": "2025-06-05T12:13:54.371416+00:00"}}
{"id": {"S": "945e8672-1d72-45c6-b76c-ac06aa8b52ab"}, "sk": {"S": "0"}, "course": {"M": {"id": {"S": "123"}, "name": {"S": "pytest"}}}, "user": {"M": {"id": {"S": "5OxmMjL-ujoR5IMGegQz"}, "name": {"S": "Sérgio R Siqueira"}}}, "create_date": {"S": "2025-06-05T12:13:54.371416+00:00"}}
{"id": {"S": "945e8672-1d72-45c6-b76c-ac06aa8b52ab"}, "sk": {"S": "author"}, "name": {"S": "Carolina Brand"}, "user_id": {"S": "SMEXYk5MQkKCzknJpxqr8n"}}
{"id": {"S": "CUSTOM_PRICING#ORG#edp8njvgQuzNkLx2ySNfAD"},"sk": {"S": "COURSE#123"},"created_at": {"S": "2025-07-24T16:10:09.304073-03:00"},"unit_price": {"N": "79.2"}}
{"id": {"S": "123"},"sk": {"S": "0"},"access_period": {"N": "360"},"cert": {"M": {"exp_interval": {"N": "360"}}},"created_at": {"S": "2024-12-30T00:33:33.088916-03:00"},"metadata__konviva_class_id": {"N": "194"},"metadata__unit_price": {"N": "99"},"name": {"S": "Direção Defensiva (08 horas)"},"tenant_id": {"S": "*"},"updated_at": {"S": "2025-07-24T00:00:24.639003-03:00"}}

View File

@@ -0,0 +1,31 @@
from datetime import date
from utils import get_billing_period
def test_get_billing_period():
assert get_billing_period(billing_day=29, year=2025, month=2) == (
date(2025, 2, 28),
date(2025, 3, 28),
)
assert get_billing_period(billing_day=31, year=2025, month=2) == (
date(2025, 2, 28),
date(2025, 3, 30),
)
# Leap year
assert get_billing_period(billing_day=29, year=2028, month=2) == (
date(2028, 2, 29),
date(2028, 3, 28),
)
assert get_billing_period(billing_day=28, year=2025, month=2) == (
date(2025, 2, 28),
date(2025, 3, 27),
)
assert get_billing_period(billing_day=5, year=2025, month=12) == (
date(2025, 12, 5),
date(2026, 1, 4),
)