add sample

This commit is contained in:
2025-03-25 22:43:34 -03:00
parent 02f0b317ae
commit e1eae86aa1
24 changed files with 603 additions and 51 deletions

View File

@@ -4,13 +4,11 @@ import os
from dataclasses import dataclass
from http import HTTPMethod
import boto3
import layercake.jsonl as jsonl
import pytest
from layercake.dynamodb import DynamoDBPersistenceLayer
PYTEST_TABLE_NAME = 'pytest'
DYNAMODB_ENDPOINT_URL = 'http://127.0.0.1:8000'
PK = os.getenv('DYNAMODB_PARTITION_KEY', 'pk')
SK = os.getenv('DYNAMODB_SORT_KEY', 'sk')
@@ -102,7 +100,8 @@ def http_api_proxy():
@pytest.fixture
def dynamodb_client():
client = boto3.client('dynamodb', endpoint_url=DYNAMODB_ENDPOINT_URL)
from boto3clients import dynamodb_client as client
client.create_table(
AttributeDefinitions=[
{'AttributeName': PK, 'AttributeType': 'S'},

View File

@@ -0,0 +1,54 @@
import json
from http import HTTPMethod, HTTPStatus
from layercake.dynamodb import DynamoDBCollection, DynamoDBPersistenceLayer
from ..conftest import HttpApiProxy, LambdaContext
def test_me(
mock_app,
dynamodb_seeds,
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
http_api_proxy: HttpApiProxy,
lambda_context: LambdaContext,
):
mock_app.me.collect = DynamoDBCollection(dynamodb_persistence_layer)
# This data was added from seeds
r = mock_app.lambda_handler(
http_api_proxy(
raw_path='/me',
method=HTTPMethod.GET,
),
lambda_context,
)
assert r['statusCode'] == HTTPStatus.OK
body = json.loads(r['body'])
assert body == {
'acls': [
{
'sk': 'cJtK9SsnJhKPyxESe7g3DG',
'id': '5OxmMjL-ujoR5IMGegQz',
'create_date': '2025-03-14T10:06:34.628078-03:00',
'roles': ['ADMIN'],
},
{
'sk': '*',
'id': '5OxmMjL-ujoR5IMGegQz',
'create_date': '2022-06-13T15:00:24.309410-03:00',
'roles': ['ADMIN'],
},
],
'tenants': [
{
'sk': 'cJtK9SsnJhKPyxESe7g3DG',
'name': 'Beta Educação',
'id': '5OxmMjL-ujoR5IMGegQz',
'cnpj': '15608435000190',
'create_date': '2025-03-13T16:36:50.073156-03:00',
}
],
}

View File

@@ -1,24 +0,0 @@
from http import HTTPMethod, HTTPStatus
from layercake.dynamodb import DynamoDBPersistenceLayer
from ..conftest import HttpApiProxy, LambdaContext
def test_settings(
mock_app,
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
http_api_proxy: HttpApiProxy,
lambda_context: LambdaContext,
):
r = mock_app.lambda_handler(
http_api_proxy(
raw_path='/settings',
method=HTTPMethod.GET,
),
lambda_context,
)
print(r)
# assert 'id' in json.loads(r['body'])
assert r['statusCode'] == HTTPStatus.OK

View File

@@ -8,7 +8,6 @@ from ..conftest import HttpApiProxy, LambdaContext
def test_get_emails(
mock_app,
monkeypatch,
dynamodb_seeds,
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
http_api_proxy: HttpApiProxy,

View File

@@ -0,0 +1,11 @@
import konviva
from settings import KONVIVA_API_URL
def test_konviva_token():
token = konviva.token('sergio@somosbeta.com.br')
assert isinstance(token, konviva.KonvivaToken)
redirect_uri = konviva.redirect_uri(token)
assert KONVIVA_API_URL in redirect_uri