def test_context_middleware(self):

        middleware = context.ContextMiddleware(None)
        request = webob.Request.blank('/clusters',
                                      headers=self.headers,
                                      environ=self.environ)
        if self.expected_exception:
            self.assertRaises(self.expected_exception,
                              middleware.process_request, request)
        else:
            self.assertIsNone(middleware.process_request(request))
            ctx = request.context.to_dict()
            for k, v in self.context_dict.items():
                self.assertEqual(v, ctx[k], 'Key %s values do not match' % k)
            self.assertIsNotNone(ctx.get('request_id'))
    def test_context_middleware_with_requestid(self):

        middleware = context.ContextMiddleware(None)
        request = webob.Request.blank('/clusters',
                                      headers=self.headers,
                                      environ=self.environ)
        req_id = 'req-5a63f0d7-1b69-447b-b621-4ea87cc7186d'
        request.environ[request_id.ENV_REQUEST_ID] = req_id
        if self.expected_exception:
            self.assertRaises(self.expected_exception,
                              middleware.process_request, request)
        else:
            self.assertIsNone(middleware.process_request(request))
            ctx = request.context.to_dict()
            for k, v in self.context_dict.items():
                self.assertEqual(v, ctx[k], 'Key %s values do not match' % k)
            self.assertEqual(ctx.get('request_id'), req_id,
                             'Key request_id values do not match')
Beispiel #3
0
def context_filter(app, conf, **local_conf):
    return context.ContextMiddleware(app)