def test_summary_fetch(self, mock_resp, mock_summary, mock_work): unglueTest = Unglueit('9999999999') output = unglueTest.fetchSummary() mock_work.assert_called_once() mock_summary.assert_called_once_with(1) mock_resp.assert_called_once_with( 200, { 'match': True, 'isbn': '9999999999', 'summary': 'summary' } ) self.assertTrue(output)
def handler(event, context): """The central handler response to invocations from event sources. For this function these come from the API Gateway Arguments: event {dict} -- Dictionary containing contents of the event that invoked the function, primarily the payload of data to be processed. context {LambdaContext} -- An object containing metadata describing the event source and client details. Raises: InvalidExecutionType -- Raised when GET parameters are missing or are malformed. Returns: [dict] -- An object that is returned to the service that originated the API call to the API gateway. """ logger.info('Starting Lambda Execution') logger.debug(event) try: isbn = event['queryStringParameters']['isbn'] except KeyError: logger.error('Missing required lookup ISBN parameter') raise InvalidExecutionType('isbn parameter required') unglued = Unglueit(isbn) try: unglued.validate() returnObj = unglued.fetchSummary() except UnglueError as err: logger.error(err) returnObj = Unglueit.formatResponse(err.status, { 'match': False, 'message': err.message }) return returnObj