def testWithHttpError(self):
     '''APIGateway.createErrorResponse() should create a response with the statusCode of the passed HttpError, the
     Access-Control-Allow-Origin header and the conversion to json of the __dict__ of the passed HttpError as
     body'''
     event = {}
     sut = APIGateway(mockLoggerFactory, event)
     error = HttpError(HttpError.NOT_FOUND, 'message')
     response = sut.createErrorResponse(error)
     self.assertEqual(response, {
         'statusCode': error.statusCode,
         'headers': {'Access-Control-Allow-Origin': '*'},
         'body': json.dumps(error.__dict__, default=jsonutils.dumpdefault)
     })
 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'], [])