wip
This commit is contained in:
@@ -3,10 +3,11 @@ from http import HTTPMethod, HTTPStatus
|
||||
|
||||
from layercake.dynamodb import (
|
||||
ComposeKey,
|
||||
DynamoDBCollection,
|
||||
DynamoDBPersistenceLayer,
|
||||
KeyPair,
|
||||
PartitionKey,
|
||||
SortKey,
|
||||
TransactKey,
|
||||
)
|
||||
|
||||
from ..conftest import HttpApiProxy, LambdaContext
|
||||
@@ -53,6 +54,10 @@ def test_enroll(
|
||||
'deduplication_window': {
|
||||
'offset_days': 60,
|
||||
},
|
||||
'vacancy': {
|
||||
'id': 'vacancies#cJtK9SsnJhKPyxESe7g3DG',
|
||||
'sk': '3CNrFB9dy2RLit2pdeUWy4#8c9b55ef-e988-43ee-b2da-8594850605d7',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -62,12 +67,75 @@ def test_enroll(
|
||||
|
||||
assert r['statusCode'] == HTTPStatus.OK
|
||||
|
||||
fail, _ = json.loads(r['body'])
|
||||
fail, succ = json.loads(r['body'])
|
||||
assert fail['cause'] == {
|
||||
'type': 'DeduplicationConflictError',
|
||||
'message': 'Enrollment already exists',
|
||||
}
|
||||
|
||||
enrollment = dynamodb_persistence_layer.collection.get_items(
|
||||
TransactKey(
|
||||
'8c9b55ef-e988-43ee-b2da-8594850605d7',
|
||||
)
|
||||
+ SortKey('0')
|
||||
+ SortKey('parent_vacancy', path_spec='vacancy')
|
||||
+ SortKey('related_ids#order', path_spec='order_id'),
|
||||
)
|
||||
|
||||
assert succ['output']['id'] == '8c9b55ef-e988-43ee-b2da-8594850605d7'
|
||||
assert enrollment['related_ids#order'] == '3CNrFB9dy2RLit2pdeUWy4'
|
||||
assert enrollment['parent_vacancy'] == {
|
||||
'sk': '3CNrFB9dy2RLit2pdeUWy4#8c9b55ef-e988-43ee-b2da-8594850605d7',
|
||||
'id': 'vacancies#cJtK9SsnJhKPyxESe7g3DG',
|
||||
}
|
||||
|
||||
|
||||
def test_enroll_vacancy(
|
||||
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='/enrollments',
|
||||
method=HTTPMethod.POST,
|
||||
headers={'X-Tenant': 'cJtK9SsnJhKPyxESe7g3DG'},
|
||||
body={
|
||||
'items': [
|
||||
{
|
||||
'user': {
|
||||
'id': '9a41e867-55e1-4573-bd27-7b5d1d1bcfde',
|
||||
'name': 'Tiago Maciel',
|
||||
'email': 'tiago@somosbeta.com.br',
|
||||
'cpf': '08679004901',
|
||||
},
|
||||
'course': {
|
||||
'id': '6d69a34a-cefd-40aa-a89b-dceb694c3e61',
|
||||
'name': 'pytest',
|
||||
},
|
||||
'deduplication_window': {
|
||||
'offset_days': 60,
|
||||
},
|
||||
'vacancy': {
|
||||
'id': 'vacancies#cJtK9SsnJhKPyxESe7g3DG',
|
||||
'sk': '3CNrFB9dy2RLit2pdeUWy4#does_not_exist',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
),
|
||||
lambda_context,
|
||||
)
|
||||
|
||||
assert r['statusCode'] == HTTPStatus.OK
|
||||
fail, *_ = json.loads(r['body'])
|
||||
assert fail['cause'] == {
|
||||
'type': 'VacancyDoesNotExistError',
|
||||
'message': 'Vacancy does not exist',
|
||||
}
|
||||
|
||||
|
||||
def test_vacancies(
|
||||
mock_app,
|
||||
@@ -119,11 +187,12 @@ def test_cancel_enrollment(
|
||||
|
||||
assert r['statusCode'] == HTTPStatus.OK
|
||||
|
||||
collect = DynamoDBCollection(dynamodb_persistence_layer)
|
||||
enrollment = collect.get_item(KeyPair('43ea4475-c369-4f90-b576-135b7df5106b', '0'))
|
||||
enrollment = dynamodb_persistence_layer.collection.get_item(
|
||||
KeyPair('43ea4475-c369-4f90-b576-135b7df5106b', '0')
|
||||
)
|
||||
assert enrollment['status'] == 'CANCELED'
|
||||
|
||||
vacancies = collect.query(
|
||||
vacancies = dynamodb_persistence_layer.collection.query(
|
||||
PartitionKey(ComposeKey('cJtK9SsnJhKPyxESe7g3DG', 'vacancies'))
|
||||
)
|
||||
assert len(vacancies['items']) == 1
|
||||
assert len(vacancies['items']) == 2
|
||||
|
||||
@@ -247,12 +247,10 @@ def test_patch_email(
|
||||
|
||||
assert r['statusCode'] == HTTPStatus.OK
|
||||
|
||||
collect = DynamoDBCollection(dynamodb_persistence_layer)
|
||||
user = collect.get_item(KeyPair('5OxmMjL-ujoR5IMGegQz', '0'))
|
||||
print(user)
|
||||
# assert user['emails'] == {
|
||||
# 'sergio@somosbeta.com.br',
|
||||
# }
|
||||
user = dynamodb_persistence_layer.collection.get_item(
|
||||
KeyPair('5OxmMjL-ujoR5IMGegQz', '0')
|
||||
)
|
||||
assert user['email'] == 'osergiosiqueira@gmail.com'
|
||||
|
||||
|
||||
def test_delete_email(
|
||||
|
||||
@@ -21,4 +21,5 @@
|
||||
{"id": {"S": "email"}, "sk": {"S": "sergio@somosbeta.com.br"}}
|
||||
{"id": {"S": "cpf"}, "sk": {"S": "07879819908"}}
|
||||
{"id": {"S": "cpf"}, "sk": {"S": "08679004901"}}
|
||||
{"id": {"S": "lock"}, "sk": {"S": "c2116a43f8f1aed659a10c83dab17ed3"}}
|
||||
{"id": {"S": "lock"}, "sk": {"S": "c2116a43f8f1aed659a10c83dab17ed3"}}
|
||||
{"id": {"S": "vacancies#cJtK9SsnJhKPyxESe7g3DG"}, "sk": {"S": "3CNrFB9dy2RLit2pdeUWy4#8c9b55ef-e988-43ee-b2da-8594850605d7"}}
|
||||
Reference in New Issue
Block a user