Пример #1
0
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
Пример #2
0
 def test_validate_invalid_characters(self):
     validateTest = Unglueit('fake iSBN 978xxxxx')
     with self.assertRaises(UnglueError):
         validateTest.validate()
Пример #3
0
 def test_validate_invalid_character_count(self):
     validateTest = Unglueit('999999999')
     with self.assertRaises(UnglueError):
         validateTest.validate()
Пример #4
0
 def test_validate_isbn13(self, mock_isbn13):
     validateTest = Unglueit('978-99-999-9999-9')
     validateTest.validate()
     mock_isbn13.assert_called_once_with('9789999999999')