def testWithNspError(self):
     '''APIGateway.createErrorResponse() should wrap the passed NspError in an HttpError and then create an error
     response with it'''
     event = {}
     sut = APIGateway(mockLoggerFactory, event)
     error = NspError(NspError.THING_NOT_FOUND, 'message')
     httpError = HttpError.wrap(error)
     httpError.method = sut.getHttpMethod()
     httpError.resource = sut.getHttpResource()
     response = sut.createErrorResponse(error)
     self.assertEqual(response, {
         'statusCode': httpError.statusCode,
         'headers': {'Access-Control-Allow-Origin': '*'},
         'body': json.dumps(httpError.__dict__, default=jsonutils.dumpdefault)
     })
 def testWithException(self):
     '''APIGateway.createErrorResponse() should wrap the passed Exception in an HttpError and the create an error
     response with it'''
     event = {}
     sut = APIGateway(mockLoggerFactory, event)
     error = KeyError('unknown')
     httpError = HttpError.wrap(error)
     httpError.method = sut.getHttpMethod()
     httpError.resource = sut.getHttpResource()
     response = sut.createErrorResponse(error)
     self.assertEqual(response['statusCode'], httpError.statusCode)
     self.assertEqual(response['headers'], {'Access-Control-Allow-Origin': '*'})
     body = json.loads(response['body'])
     self.assertEqual(body['message'], httpError.message)
     self.assertEqual(body['method'], httpError.method)
     self.assertEqual(body['resource'], httpError.resource)
     self.assertEqual(body['causes'], [])
 def testFound(self):
     'APIGateway.getHttpMethod() should return the method found in the event'
     event = {'httpMethod': 'method'}
     sut = APIGateway(mockLoggerFactory, event)
     httpMethod = sut.getHttpMethod()
     self.assertEqual(httpMethod, 'method')
 def testMissing(self):
     'APIGateway.getHttpMethod() should return `UNKNOWN_METHOD` if no method is found in the event'
     event = {}
     sut = APIGateway(mockLoggerFactory, event)
     httpMethod = sut.getHttpMethod()
     self.assertEqual(httpMethod, 'UNKNOWN_METHOD')