This commit is contained in:
2025-07-22 14:26:05 -03:00
parent 2f7b880f48
commit 1a1d545544
12 changed files with 298 additions and 200 deletions

View File

@@ -3,11 +3,12 @@ import json
import os
from dataclasses import dataclass
from http import HTTPMethod
from uuid import uuid4
import jsonlines
import pytest
PYTEST_TABLE_NAME = 'pytest'
PYTEST_TABLE_NAME = f'pytest-{uuid4()}'
PK = 'id'
SK = 'sk'

View File

@@ -21,12 +21,14 @@ def test_get_policies(
),
lambda_context,
)
assert r['statusCode'] == HTTPStatus.OK
assert json.loads(r['body']) == {
expected = {
'billing_policy': {'billing_day': 1, 'payment_method': 'PIX'},
'payment_policy': {'due_days': 90},
}
assert r['statusCode'] == HTTPStatus.OK
assert json.loads(r['body']) == expected
def test_put_policies(
mock_app,
@@ -67,7 +69,7 @@ def test_get_address(
),
lambda_context,
)
address = {
expected = {
'id': 'cJtK9SsnJhKPyxESe7g3DG',
'sk': 'metadata#address',
'postcode': '88101001',
@@ -78,7 +80,7 @@ def test_get_address(
'state': 'SC',
}
assert r['statusCode'] == HTTPStatus.OK
assert json.loads(r['body']) == address
assert json.loads(r['body']) == expected
def test_post_address(
@@ -110,3 +112,61 @@ def test_post_address(
)
assert data['address1'] == 'Rua Monsenhor Ivo Zanlorenzi, 5190'
assert data['postcode'] == '81280350'
def test_get_custom_pricing(
mock_app,
dynamodb_seeds,
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
http_api_proxy: HttpApiProxy,
lambda_context: LambdaContext,
):
r = mock_app.lambda_handler(
http_api_proxy(
raw_path='/orgs/cJtK9SsnJhKPyxESe7g3DG/custompricing',
method=HTTPMethod.GET,
),
lambda_context,
)
expected = {
'items': [
{
'sk': 'COURSE#281198c2-f293-4acc-b96e-e4a2d5f6b73c',
'unit_price': 199,
'id': 'CUSTOM_PRICING#ORG#cJtK9SsnJhKPyxESe7g3DG',
}
],
'last_key': None,
}
assert json.loads(r['body']) == expected
def test_post_custom_pricing(
mock_app,
dynamodb_seeds,
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
http_api_proxy: HttpApiProxy,
lambda_context: LambdaContext,
):
r = mock_app.lambda_handler(
http_api_proxy(
raw_path='/orgs/cJtK9SsnJhKPyxESe7g3DG/custompricing',
method=HTTPMethod.POST,
body={
'course_id': '15ee05a3-4ceb-4b7e-9979-db75b28c9ade',
'unit_price': '99.3',
},
),
lambda_context,
)
assert r['statusCode'] == HTTPStatus.CREATED
data = dynamodb_persistence_layer.collection.get_item(
KeyPair(
'CUSTOM_PRICING#ORG#cJtK9SsnJhKPyxESe7g3DG',
'COURSE#15ee05a3-4ceb-4b7e-9979-db75b28c9ade',
)
)
assert data

View File

@@ -33,3 +33,5 @@
{"sk": {"S": "lock"}, "id": {"S": "KpZTYvu4RzgMJW3A2DF6cC"}, "lock_type": {"S": "CNPJ"}, "create_date": {"S": "2024-02-08T08:42:13.058916-03:00"}}
{"sk": {"S": "nfse"}, "nfse": {"S": "10384"}, "id": {"S": "KpZTYvu4RzgMJW3A2DF6cC"}, "create_date": {"S": "2024-02-08T09:05:03.879692-03:00"}}
{"sk": {"S": "user"}, "user_id": {"S": "5AZXXXCWa2bU4spsxfLznx"}, "id": {"S": "KpZTYvu4RzgMJW3A2DF6cC"}, "create_date": {"S": "2024-02-08T08:42:05.190415-03:00"}}
{"id": {"S": "15ee05a3-4ceb-4b7e-9979-db75b28c9ade"}, "sk": {"S": "0"}, "name": {"S": "pytest"}}
{"id": {"S": "CUSTOM_PRICING#ORG#cJtK9SsnJhKPyxESe7g3DG"}, "sk": {"S": "COURSE#281198c2-f293-4acc-b96e-e4a2d5f6b73c"}, "unit_price": {"N": "199"}}