Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add-more-test
  • Loading branch information
Gleekzone committed Sep 8, 2020
commit 05323eb1a3d3b6e366a61348de5c607a17eab1f8
46 changes: 45 additions & 1 deletion tests/integrations/chalice/test_chalice.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest

import time
from chalice import Chalice
from chalice.local import LambdaContext, LocalGateway

Expand Down Expand Up @@ -42,6 +42,11 @@ def has_request():
return app


@pytest.fixture
def lambda_context_args():
return ['lambda_name', 256]


def test_exception_boom(app, client: RequestHandler) -> None:
response = client.get("/boom")
assert response.status_code == 500
Expand All @@ -63,3 +68,42 @@ def test_has_request(app, capture_events, client: RequestHandler):
assert event["level"] == "error"
(exception,) = event["exception"]["values"]
assert exception["type"] == "Exception"


def test_scheduled_event(app, lambda_context_args):
@app.schedule('rate(1 minutes)')
def every_hour(event):
raise Exception('only chalice event!')

context = LambdaContext(
*lambda_context_args, max_runtime_ms=10000, time_source=time
)

lambda_event = {
"version": "0",
"account": "120987654312",
"region": "us-west-1",
"detail": {},
"detail-type": "Scheduled Event",
"source": "aws.events",
"time": "1970-01-01T00:00:00Z",
"id": "event-id",
"resources": [
"arn:aws:events:us-west-1:120987654312:rule/my-schedule"
],
}
with pytest.raises(Exception) as exc_info:
every_hour(lambda_event, context=context)
assert str(exc_info.value) == 'only chalice event!'


def test_bad_reques(client: RequestHandler) -> None:
response = client.http.get('/badrequest')

assert response.status_code == 400
assert response.json_body == dict(
[
('Code', 'BadRequestError'),
('Message', 'BadRequestError: bad-request'),
]
)