86 lines
2.3 KiB
Python
86 lines
2.3 KiB
Python
from http import HTTPMethod, HTTPStatus
|
|
|
|
from layercake.dynamodb import DynamoDBPersistenceLayer
|
|
from requests_toolbelt import MultipartEncoder
|
|
|
|
from ..conftest import HttpApiProxy, LambdaContext
|
|
|
|
|
|
def test_get_course(
|
|
app,
|
|
seeds,
|
|
http_api_proxy: HttpApiProxy,
|
|
lambda_context: LambdaContext,
|
|
):
|
|
r = app.lambda_handler(
|
|
http_api_proxy(
|
|
raw_path='/courses/2a8963fc-4694-4fe2-953a-316d1b10f1f5',
|
|
method=HTTPMethod.GET,
|
|
),
|
|
lambda_context,
|
|
)
|
|
assert r['statusCode'] == HTTPStatus.OK
|
|
|
|
|
|
def test_edit_course(
|
|
app,
|
|
seeds,
|
|
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
|
|
http_api_proxy: HttpApiProxy,
|
|
lambda_context: LambdaContext,
|
|
):
|
|
course_id = '2a8963fc-4694-4fe2-953a-316d1b10f1f5'
|
|
|
|
with open('tests/sample.html', 'rb') as f:
|
|
m = MultipartEncoder(
|
|
fields={
|
|
'given_cert': 'true',
|
|
'name': 'pytest updated from test',
|
|
'access_period': '365',
|
|
'rawfile': ('sample.html', f, 'text/html'),
|
|
}
|
|
)
|
|
r = app.lambda_handler(
|
|
http_api_proxy(
|
|
raw_path=f'/courses/{course_id}',
|
|
method=HTTPMethod.PUT,
|
|
headers={
|
|
'Content-Type': m.content_type,
|
|
},
|
|
body=m.to_string().decode(),
|
|
is_base64_encoded=True,
|
|
),
|
|
lambda_context,
|
|
)
|
|
assert r['statusCode'] == HTTPStatus.NO_CONTENT
|
|
|
|
r = dynamodb_persistence_layer.get_item(
|
|
key={'id': course_id, 'sk': '0'},
|
|
)
|
|
|
|
assert (
|
|
r['cert']['s3_uri']
|
|
== 's3://saladeaula.digital/certs/2a8963fc-4694-4fe2-953a-316d1b10f1f5.html'
|
|
)
|
|
|
|
|
|
def test_sample(
|
|
app,
|
|
seeds,
|
|
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
|
|
http_api_proxy: HttpApiProxy,
|
|
lambda_context: LambdaContext,
|
|
):
|
|
r = app.lambda_handler(
|
|
http_api_proxy(
|
|
raw_path='/courses/2a8963fc-4694-4fe2-953a-316d1b10f1f5/sample',
|
|
method=HTTPMethod.POST,
|
|
body={
|
|
's3_uri': 's3://saladeaula.digital/certs/samples/cipa-grau-de-risco-1.html',
|
|
},
|
|
),
|
|
lambda_context,
|
|
)
|
|
assert r['statusCode'] == HTTPStatus.OK
|
|
# print(r['body'])
|