add user if exists on konviva
This commit is contained in:
0
konviva-events/tests/__init__.py
Normal file
0
konviva-events/tests/__init__.py
Normal file
63
konviva-events/tests/conftest.py
Normal file
63
konviva-events/tests/conftest.py
Normal file
@@ -0,0 +1,63 @@
|
||||
import os
|
||||
from dataclasses import dataclass
|
||||
|
||||
import jsonlines
|
||||
import pytest
|
||||
|
||||
PYTEST_TABLE_NAME = 'pytest'
|
||||
PK = 'id'
|
||||
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['DYNAMODB_PARTITION_KEY'] = PK
|
||||
os.environ['DYNAMODB_SORT_KEY'] = SK
|
||||
os.environ['USER_TABLE'] = PYTEST_TABLE_NAME
|
||||
os.environ['KONVIVA_API_URL'] = 'https://lms.saladeaula.digital'
|
||||
|
||||
|
||||
@dataclass
|
||||
class LambdaContext:
|
||||
function_name: str = 'test'
|
||||
memory_limit_in_mb: int = 128
|
||||
invoked_function_arn: str = 'arn:aws:lambda:eu-west-1:809313241:function:test'
|
||||
aws_request_id: str = '52fdfc07-2182-154f-163f-5f0f9a621d72'
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def lambda_context() -> LambdaContext:
|
||||
return LambdaContext()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def dynamodb_client():
|
||||
from boto3clients import dynamodb_client as client
|
||||
|
||||
client.create_table(
|
||||
AttributeDefinitions=[
|
||||
{'AttributeName': PK, 'AttributeType': 'S'},
|
||||
{'AttributeName': SK, 'AttributeType': 'S'},
|
||||
],
|
||||
TableName=PYTEST_TABLE_NAME,
|
||||
KeySchema=[
|
||||
{'AttributeName': PK, 'KeyType': 'HASH'},
|
||||
{'AttributeName': SK, 'KeyType': 'RANGE'},
|
||||
],
|
||||
ProvisionedThroughput={
|
||||
'ReadCapacityUnits': 123,
|
||||
'WriteCapacityUnits': 123,
|
||||
},
|
||||
)
|
||||
|
||||
yield client
|
||||
|
||||
client.delete_table(TableName=PYTEST_TABLE_NAME)
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def dynamodb_seeds(dynamodb_client):
|
||||
with jsonlines.open('tests/seeds.jsonl') as lines:
|
||||
for line in lines:
|
||||
dynamodb_client.put_item(TableName=PYTEST_TABLE_NAME, Item=line)
|
||||
0
konviva-events/tests/events/__init__.py
Normal file
0
konviva-events/tests/events/__init__.py
Normal file
19
konviva-events/tests/events/test_create_user.py
Normal file
19
konviva-events/tests/events/test_create_user.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from aws_lambda_powertools.utilities.typing import LambdaContext
|
||||
|
||||
import events.create_user as app
|
||||
|
||||
|
||||
def test_create_user(dynamodb_client, dynamodb_seeds, lambda_context: LambdaContext):
|
||||
event = {
|
||||
'detail': {
|
||||
'new_image': {
|
||||
'id': '123',
|
||||
'sk': '0',
|
||||
'name': 'Sérgio R Siqueira',
|
||||
'email': 'sergio@somosbeta.com.br',
|
||||
'cpf': '07879819908',
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert app.lambda_handler(event, lambda_context) # type: ignore
|
||||
1
konviva-events/tests/seeds.jsonl
Normal file
1
konviva-events/tests/seeds.jsonl
Normal file
@@ -0,0 +1 @@
|
||||
{"id": {"S": "123"}, "sk": {"S": "0"}}
|
||||
23
konviva-events/tests/test_konviva.py
Normal file
23
konviva-events/tests/test_konviva.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import pytest
|
||||
|
||||
import konviva
|
||||
|
||||
|
||||
def test_create_user_email_exists():
|
||||
with pytest.raises(konviva.KonvivaError):
|
||||
konviva.create_user(
|
||||
id='',
|
||||
name='Sérgio R Siquira',
|
||||
email='sergio@somosbeta.com.br',
|
||||
cpf='0879819908',
|
||||
)
|
||||
|
||||
|
||||
def test_get_users_by_email():
|
||||
r = konviva.get_users_by_email('sergio@somosbeta.com.br')
|
||||
assert len(r) >= 1
|
||||
|
||||
|
||||
def test_get_users_by_email_notfound():
|
||||
r = konviva.get_users_by_email('fake@fake.com')
|
||||
assert r == []
|
||||
Reference in New Issue
Block a user