update block
This commit is contained in:
@@ -171,7 +171,7 @@ def enroll_now(enrollment: Enrollment, context: Context):
|
||||
)
|
||||
transact.condition(
|
||||
key=KeyPair(
|
||||
pk='SUBSCRIPTION#FREEZE',
|
||||
pk='SUBSCRIPTION#FROZEN',
|
||||
sk=f'ORG#{org.id}',
|
||||
),
|
||||
cond_expr='attribute_not_exists(sk)',
|
||||
@@ -288,7 +288,7 @@ def enroll_later(enrollment: Enrollment, context: Context):
|
||||
)
|
||||
transact.condition(
|
||||
key=KeyPair(
|
||||
pk='SUBSCRIPTION#FREEZE',
|
||||
pk='SUBSCRIPTION#FROZEN',
|
||||
sk=f'ORG#{org.id}',
|
||||
),
|
||||
cond_expr='attribute_not_exists(sk)',
|
||||
|
||||
@@ -45,8 +45,8 @@ def get_org(org_id: str):
|
||||
+ SortKey('METADATA#ADDRESS', rename_key='address')
|
||||
+ SortKey('METADATA#SUBSCRIPTION', rename_key='subscription')
|
||||
+ KeyPair(
|
||||
pk='SUBSCRIPTION#FREEZE',
|
||||
pk='SUBSCRIPTION#FROZEN',
|
||||
sk=SortKey(f'ORG#{org_id}'),
|
||||
rename_key='subscription_freeze',
|
||||
rename_key='subscription_frozen',
|
||||
)
|
||||
)
|
||||
|
||||
@@ -31,6 +31,7 @@ def add(
|
||||
name: Annotated[str, Body(embed=True)],
|
||||
billing_day: Annotated[int, Body(embed=True, ge=1, le=31)],
|
||||
payment_method: Annotated[PaymentMethod, Body(embed=True)],
|
||||
subscription_frozen: Annotated[bool, Body(embed=True)] = False,
|
||||
):
|
||||
now_ = now()
|
||||
|
||||
@@ -71,6 +72,15 @@ def add(
|
||||
exc_cls=SubscriptionConflictError,
|
||||
)
|
||||
|
||||
if subscription_frozen:
|
||||
transact.put(
|
||||
item={
|
||||
'id': 'SUBSCRIPTION#FROZEN',
|
||||
'sk': f'ORG#{org_id}',
|
||||
'created_at': now_,
|
||||
}
|
||||
)
|
||||
|
||||
return JSONResponse(status_code=HTTPStatus.CREATED)
|
||||
|
||||
|
||||
@@ -100,19 +110,19 @@ def edit(
|
||||
':now': now_,
|
||||
},
|
||||
cond_expr='attribute_exists(sk)',
|
||||
exc_cls=OrgNotFoundError,
|
||||
exc_cls=SubscriptionRequiredError,
|
||||
)
|
||||
|
||||
if subscription_frozen:
|
||||
transact.put(
|
||||
item={
|
||||
'id': 'SUBSCRIPTION#FREEZE',
|
||||
'id': 'SUBSCRIPTION#FROZEN',
|
||||
'sk': f'ORG#{org_id}',
|
||||
'created_at': now_,
|
||||
}
|
||||
)
|
||||
else:
|
||||
transact.delete(key=KeyPair('SUBSCRIPTION#FREEZE', f'ORG#{org_id}'))
|
||||
transact.delete(key=KeyPair('SUBSCRIPTION#FROZEN', f'ORG#{org_id}'))
|
||||
|
||||
return JSONResponse(status_code=HTTPStatus.NO_CONTENT)
|
||||
|
||||
@@ -133,6 +143,6 @@ def remove(org_id: str):
|
||||
)
|
||||
transact.delete(key=KeyPair(org_id, 'METADATA#SUBSCRIPTION'))
|
||||
transact.delete(key=KeyPair('SUBSCRIPTION', f'ORG#{org_id}'))
|
||||
transact.delete(key=KeyPair('SUBSCRIPTION#FREEZE', f'ORG#{org_id}'))
|
||||
transact.delete(key=KeyPair('SUBSCRIPTION#FROZEN', f'ORG#{org_id}'))
|
||||
|
||||
return JSONResponse(status_code=HTTPStatus.NO_CONTENT)
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
from http import HTTPMethod, HTTPStatus
|
||||
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer
|
||||
|
||||
from ...conftest import HttpApiProxy, LambdaContext
|
||||
|
||||
|
||||
def test_address(
|
||||
app,
|
||||
seeds,
|
||||
http_api_proxy: HttpApiProxy,
|
||||
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
|
||||
lambda_context: LambdaContext,
|
||||
):
|
||||
r = app.lambda_handler(
|
||||
http_api_proxy(
|
||||
raw_path='/orgs/cJtK9SsnJhKPyxESe7g3DG/address',
|
||||
method=HTTPMethod.GET,
|
||||
),
|
||||
lambda_context,
|
||||
)
|
||||
assert r['statusCode'] == HTTPStatus.OK
|
||||
@@ -5,6 +5,22 @@ from layercake.dynamodb import DynamoDBPersistenceLayer
|
||||
from ...conftest import HttpApiProxy, LambdaContext
|
||||
|
||||
|
||||
def test_get_scheduled(
|
||||
app,
|
||||
seeds,
|
||||
http_api_proxy: HttpApiProxy,
|
||||
lambda_context: LambdaContext,
|
||||
):
|
||||
r = app.lambda_handler(
|
||||
http_api_proxy(
|
||||
raw_path='/orgs/cJtK9SsnJhKPyxESe7g3DG/enrollments/scheduled',
|
||||
method=HTTPMethod.GET,
|
||||
),
|
||||
lambda_context,
|
||||
)
|
||||
assert r['statusCode'] == HTTPStatus.OK
|
||||
|
||||
|
||||
def test_scheduled_proceed(
|
||||
app,
|
||||
seeds,
|
||||
|
||||
@@ -17,7 +17,7 @@ def test_subscription(
|
||||
):
|
||||
r = app.lambda_handler(
|
||||
http_api_proxy(
|
||||
raw_path='/orgs/2a8963fc-4694-4fe2-953a-316d1b10f1f5',
|
||||
raw_path='/orgs/e63a579a-4719-4d64-816f-f1650ca73753',
|
||||
method=HTTPMethod.GET,
|
||||
),
|
||||
lambda_context,
|
||||
@@ -32,13 +32,13 @@ def test_add_subscription(
|
||||
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
|
||||
lambda_context: LambdaContext,
|
||||
):
|
||||
org_id = 'f6000f79-6e5c-49a0-952f-3bda330ef278'
|
||||
org_id = 'e63a579a-4719-4d64-816f-f1650ca73753'
|
||||
r = app.lambda_handler(
|
||||
http_api_proxy(
|
||||
raw_path=f'/orgs/{org_id}/subscription',
|
||||
method=HTTPMethod.POST,
|
||||
body={
|
||||
'name': 'Banco do Brasil',
|
||||
'name': 'pytest subscribed',
|
||||
'billing_day': 1,
|
||||
'payment_method': 'MANUAL',
|
||||
},
|
||||
@@ -55,4 +55,4 @@ def test_add_subscription(
|
||||
|
||||
assert r['metadata']['billing_day'] == 1
|
||||
assert r['metadata']['payment_method'] == 'MANUAL'
|
||||
assert r['subscription']['name'] == 'Banco do Brasil'
|
||||
assert r['subscription']['name'] == 'pytest subscribed'
|
||||
|
||||
@@ -15,14 +15,15 @@ def test_get_org(
|
||||
):
|
||||
r = app.lambda_handler(
|
||||
http_api_proxy(
|
||||
raw_path='/orgs/2a8963fc-4694-4fe2-953a-316d1b10f1f5',
|
||||
raw_path='/orgs/7362ce9e-9dad-4483-a28b-fff4034a17a5',
|
||||
method=HTTPMethod.GET,
|
||||
),
|
||||
lambda_context,
|
||||
)
|
||||
body = json.loads(r['body'])
|
||||
|
||||
assert 'subscription_freeze' in body
|
||||
assert 'address' in body
|
||||
assert 'subscription_frozen' in body
|
||||
|
||||
|
||||
def test_add_org(
|
||||
@@ -93,19 +94,3 @@ def test_revoke(
|
||||
lambda_context,
|
||||
)
|
||||
assert r['statusCode'] == HTTPStatus.NO_CONTENT
|
||||
|
||||
|
||||
def test_get_scheduled(
|
||||
app,
|
||||
seeds,
|
||||
http_api_proxy: HttpApiProxy,
|
||||
lambda_context: LambdaContext,
|
||||
):
|
||||
r = app.lambda_handler(
|
||||
http_api_proxy(
|
||||
raw_path='/orgs/1234/enrollments/scheduled',
|
||||
method=HTTPMethod.GET,
|
||||
),
|
||||
lambda_context,
|
||||
)
|
||||
assert r['statusCode'] == HTTPStatus.OK
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Users
|
||||
{"id": "213a6682-2c59-4404-9189-12eec0a846d4", "sk": "orgs#f6000f79-6e5c-49a0-952f-3bda330ef278", "name": "Banco do Brasil", "cnpj": "00000000000191"}
|
||||
// Users
|
||||
{"id": "15bacf02-1535-4bee-9022-19d106fd7518", "sk": "0", "name": "Sérgio R Siqueira", "email": "sergio@somosbeta.com.br", "emails": ["osergiosiqueira@gmail.com", "sergio@somosbeta.combr"], "cpf": "07879819908"}
|
||||
{"id": "15bacf02-1535-4bee-9022-19d106fd7518", "sk": "emails#sergio@somosbeta.com.br", "email_primary": true, "mx_record_exists": true}
|
||||
{"id": "15bacf02-1535-4bee-9022-19d106fd7518", "sk": "emails#osergiosiqueira@gmail.com", "email_verified": false, "mx_record_exists": true}
|
||||
@@ -12,33 +12,42 @@
|
||||
{"id": "578ec87f-94c7-4840-8780-bb4839cc7e64", "sk": "0", "course": {"id": "af3258f0-bccf-4781-aec6-d4c618d234a7", "name": "pytest", "access_period": 180}, "user": {"id": "068b4600-cc36-4b55-b832-bb620021705a", "name": "Benjamin Burnley", "email": "burnley@breakingbenjamin.com"}}
|
||||
{"id": "9c166c5e-890f-4e77-9855-769c29aaeb2e", "sk": "0", "course": {"id": "c27d1b4f-575c-4b6b-82a1-9b91ff369e0b", "name": "pytest", "access_period": 180, "scormset": "76c75561-d972-43ef-9818-497d8fc6edbe"}, "user": {"id": "068b4600-cc36-4b55-b832-bb620021705a", "name": "Layne Staley", "email": "layne@aliceinchains.com"}}
|
||||
|
||||
// Scheduled
|
||||
{"id": "SCHEDULED#ORG#cJtK9SsnJhKPyxESe7g3DG", "sk": "2028-12-16T00:00:00-03:06#981ddaa78ffaf9a1074ab1169893f45d", "org_name": "Beta Educação", "scheduled_at": "2025-12-15T17:09:39.398009-03:00", "user": { "name": "Maitê Laurenti Siqueira", "cpf": "02186829991", "id": "87606a7f-de56-4198-a91d-b6967499d382", "email": "osergiosiqueira+maite@gmail.com" }, "ttl": 1765854360, "subscription_billing_day": 5, "created_by": { "name": "Sérgio Rafael de Siqueira", "id": "5OxmMjL-ujoR5IMGegQz" }, "course": { "name": "Reciclagem em NR-10 Básico (20 horas)", "id": "c01ec8a2-0359-4351-befb-76c3577339e0", "access_period": 360}}
|
||||
|
||||
// Orgs
|
||||
// Seeds for Org
|
||||
{"id": "2a8963fc-4694-4fe2-953a-316d1b10f1f5", "sk": "0", "name": "pytest", "cnpj": "04978826000180"}
|
||||
{"id": "2a8963fc-4694-4fe2-953a-316d1b10f1f5", "sk": "METADATA#SUBSCRIPTION", "billing_day": 6}
|
||||
{"id": "2a8963fc-4694-4fe2-953a-316d1b10f1f5", "sk": "METADATA#PAYMENT_POLICY", "due_days": 30, "created_at": "2025-07-15T15:04:36.369323-03:00"}
|
||||
{"id": "SUBSCRIPTION", "sk": "ORG#2a8963fc-4694-4fe2-953a-316d1b10f1f5"}
|
||||
{"id": "cnpj", "sk": "04978826000180", "org_id": "2a8963fc-4694-4fe2-953a-316d1b10f1f5"}
|
||||
|
||||
// Seeds for Org
|
||||
{"id": "f6000f79-6e5c-49a0-952f-3bda330ef278", "sk": "0", "name": "Banco do Brasil", "cnpj": "00000000000191"}
|
||||
|
||||
// Org admins
|
||||
{"id": "f6000f79-6e5c-49a0-952f-3bda330ef278", "sk": "admins#15bacf02-1535-4bee-9022-19d106fd7518", "name": "Chester Bennington", "email": "chester@linkinpark.com"}
|
||||
|
||||
{"id": "orgmembers#f6000f79-6e5c-49a0-952f-3bda330ef278", "sk": "15bacf02-1535-4bee-9022-19d106fd7518"}
|
||||
|
||||
// Seeds for Org
|
||||
{"id": "cJtK9SsnJhKPyxESe7g3DG", "sk": "0", "name": "Beta Educação", "cnpj": "15608435000190"}
|
||||
{"id": "SUBSCRIPTION", "sk": "ORG#cJtK9SsnJhKPyxESe7g3DG"}
|
||||
{"id": "SCHEDULED#ORG#cJtK9SsnJhKPyxESe7g3DG", "sk": "2028-12-16T00:00:00-03:06#981ddaa78ffaf9a1074ab1169893f45d", "org_name": "Beta Educação", "scheduled_at": "2025-12-15T17:09:39.398009-03:00", "user": { "name": "Maitê Laurenti Siqueira", "cpf": "02186829991", "id": "87606a7f-de56-4198-a91d-b6967499d382", "email": "osergiosiqueira+maite@gmail.com" }, "ttl": 1765854360, "subscription_billing_day": 5, "created_by": { "name": "Sérgio Rafael de Siqueira", "id": "5OxmMjL-ujoR5IMGegQz" }, "course": { "name": "Reciclagem em NR-10 Básico (20 horas)", "id": "c01ec8a2-0359-4351-befb-76c3577339e0", "access_period": 360}}
|
||||
|
||||
// Seeds for Org
|
||||
// file: tests/routes/orgs/test_subscription.py
|
||||
{"id": "e63a579a-4719-4d64-816f-f1650ca73753", "sk": "0", "name": "pytest", "cnpj": "89329353000143"}
|
||||
{"id": "cnpj", "sk": "89329353000143", "org_id": "f6000f79-6e5c-49a0-952f-3bda330ef278"}
|
||||
|
||||
// Seeds for Org with subscription
|
||||
// file: tests/routes/test_orgs.py::test_get_org
|
||||
{"id": "7362ce9e-9dad-4483-a28b-fff4034a17a5", "sk": "METADATA#ADDRESS", "state": "SC", "postcode": "88101001", "address1": "Avenida Presidente Kennedy", "city": "São José", "address2": "1", "neighborhood": "Campinas"}
|
||||
{"id": "SUBSCRIPTION#FROZEN", "sk": "ORG#7362ce9e-9dad-4483-a28b-fff4034a17a5", "created_at": "2025-12-24T00:05:27-03:00"}
|
||||
{"id": "SUBSCRIPTION", "sk": "ORG#7362ce9e-9dad-4483-a28b-fff4034a17a5", "created_at": "2025-12-24T00:05:27-03:00"}
|
||||
|
||||
|
||||
// Seeds for Order
|
||||
// file: tests/routes/orders/test_payment_retries.py
|
||||
{"id": "4b23f6f5-5377-476b-b1de-79427c0295f6", "sk": "0", "installments": 3, "status": "PENDING"}
|
||||
{"id": "4b23f6f5-5377-476b-b1de-79427c0295f6", "sk": "INVOICE", "invoice_id": "123"}
|
||||
{"id": "4b23f6f5-5377-476b-b1de-79427c0295f6", "sk": "TRANSACTION#STATS", "last_attempt_succeeded": false}
|
||||
|
||||
// Indicies
|
||||
// CNPJs
|
||||
{"id": "cnpj", "sk": "04978826000180", "org_id": "2a8963fc-4694-4fe2-953a-316d1b10f1f5"}
|
||||
{"id": "cnpj", "sk": "00000000000191", "org_id": "6000f79-6e5c-49a0-952f-3bda330ef278"}
|
||||
{"id": "SUBSCRIPTION", "sk": "ORG#2a8963fc-4694-4fe2-953a-316d1b10f1f5"}
|
||||
{"id": "SUBSCRIPTION", "sk": "ORG#cJtK9SsnJhKPyxESe7g3DG"}
|
||||
{"id": "SUBSCRIPTION#FREEZE", "sk": "ORG#2a8963fc-4694-4fe2-953a-316d1b10f1f5", "created_at": "2025-12-24T00:05:27-03:00"}
|
||||
|
||||
// CPFs
|
||||
{"id": "cpf", "sk": "07879819908", "user_id": "15bacf02-1535-4bee-9022-19d106fd7518"}
|
||||
|
||||
Reference in New Issue
Block a user