def test_response_with_uuid_data(self): _id = uuid.uuid4() resp = Response(_id) lambda_output = resp.to_lambda_output() result = utils.parse_lambda_output(lambda_output) assert str(_id) in result.data
def test_lambda_handler_with_data(context, dict_data): event = utils.build_event(dict_data) uuid_obj = uuid.uuid4() date_obj = date(2018, 1, 1) datetime_obj = datetime( 2018, 1, 1, hour=1, minute=2, second=3, microsecond=45678, ) @lambda_handler def handler(req): payload = { 'req_data': req.data, 'uuid': uuid_obj, 'date': date_obj, 'datetime': datetime_obj } return Response(payload) lambda_output = handler(event, context) result = utils.parse_lambda_output(lambda_output) assert result.status_code == 200 assert result.data['req_data'] == dict_data assert uuid.UUID(result.data['uuid']) == uuid_obj assert result.data['date'] == '2018-01-01' assert result.data['datetime'] == '2018-01-01T01:02:03.045678'
def test_response_with_headers(self, dict_data): resp = Response(headers=dict_data) lambda_output = resp.to_lambda_output() result = utils.parse_lambda_output(lambda_output) assert result.status_code == 200 assert all([result.headers[k] == v for k, v in dict_data.items()])
def test_response_with_date_data(self): date_obj = date(2018, 1, 1) resp = Response(date_obj) lambda_output = resp.to_lambda_output() result = utils.parse_lambda_output(lambda_output) assert result.data == '2018-01-01'
def test_response_with_data(self, dict_data): resp = Response(dict_data) lambda_output = resp.to_lambda_output() result = utils.parse_lambda_output(lambda_output) assert result.status_code == 200 assert result.data == dict_data
def test_response(self): resp = Response() lambda_output = resp.to_lambda_output() result = utils.parse_lambda_output(lambda_output) assert result.status_code == 200 assert result.data == None assert isinstance(result.headers, dict)
def test_response_with_status_code(self): expected_status_code = 999 resp = Response(None, expected_status_code) lambda_output = resp.to_lambda_output() result = utils.parse_lambda_output(lambda_output) assert result.status_code == expected_status_code assert result.data == None
def test_lambda_handler_invalid_return_value(context): event = utils.build_event(None) @lambda_handler def handler(req): return None lambda_output = handler(event, context) result = utils.parse_lambda_output(lambda_output) assert result.status_code == 500
def test_lambda_handler_bad_request(context): event = utils.build_event(None) @lambda_handler def handler(req): raise BadRequest('invalid request') lambda_output = handler(event, context) result = utils.parse_lambda_output(lambda_output) assert result.status_code == BadRequest.status_code assert 'message' in result.data assert 'errors' in result.data
def test_lambda_handler_exception(context): event = utils.build_event(None) @lambda_handler def handler(req): raise Exception('unknown exception') lambda_output = handler(event, context) result = utils.parse_lambda_output(lambda_output) assert result.status_code == 500 assert 'message' in result.data assert 'errors' in result.data
def test_lambda_handler_with_status_code(context): expected_status_code = 999 event = utils.build_event(None) @lambda_handler def handler(req): return Response(None, expected_status_code) lambda_output = handler(event, context) result = utils.parse_lambda_output(lambda_output) assert result.status_code == expected_status_code assert not result.data
def test_response_with_datetime_data(self): datetime_obj = datetime(2018, 1, 1, hour=1, minute=2, second=3, microsecond=45678) resp = Response(datetime_obj) lambda_output = resp.to_lambda_output() result = utils.parse_lambda_output(lambda_output) assert result.data == '2018-01-01T01:02:03.045678'
def test_lambda_handler_with_query(context, dict_data): event = utils.build_event(None, query_params=dict_data) @lambda_handler def handler(req): payload = {'req_query': req.query} return Response(payload) lambda_output = handler(event, context) result = utils.parse_lambda_output(lambda_output) assert result.status_code == 200 assert result.data['req_query'] == dict_data
def test_lambda_handler(context): event = utils.build_event(None) @lambda_handler def handler(req): payload = {'event': req.event, 'context': req.context} return Response(payload) lambda_output = handler(event, context) result = utils.parse_lambda_output(lambda_output) assert result.status_code == 200 assert result.data['event'] == event assert result.data['context'] == context