Skip to content

Commit

Permalink
add-more-test
Browse files Browse the repository at this point in the history
  • Loading branch information
Gleekzone committed Sep 8, 2020
1 parent 80c23d5 commit 05323eb
Showing 1 changed file with 45 additions and 1 deletion.
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'),
]
)

0 comments on commit 05323eb

Please sign in to comment.