Exemple #1
0
 def test_make_context(self):
     app = mock.Mock()
     options = mock.MagicMock()
     with mock.patch.object(openstack.common.context.RequestContext,
                            '__init__',
                            mock.Mock(return_value=None)) as init:
         ctx_middleware = context.ContextMiddleware(app, options)
         ctx_middleware.make_context(mock.sentinel.arg)
         init.assert_called_with(mock.sentinel.arg)
Exemple #2
0
 def test_make_explicit_context(self):
     app = mock.Mock()
     import_class = mock.Mock()
     options = {'context_class': mock.sentinel.context_class}
     with mock.patch('openstack.common.importutils.import_class',
                     mock.Mock(return_value=import_class)):
         ctx_middleware = context.ContextMiddleware(app, options)
         ctx_middleware.make_context(mock.sentinel.arg)
         import_class.assert_called_with(mock.sentinel.arg)
Exemple #3
0
    def test_process_request(self):
        req = mock.Mock()
        app = mock.Mock()
        options = mock.MagicMock()
        ctx = mock.sentinel.context
        with mock.patch.object(context.ContextMiddleware, 'make_context',
                               mock.Mock(return_value=ctx)):
            ctx_middleware = context.ContextMiddleware(app, options)
            ctx_middleware.process_request(req)

        self.assertEqual(req.context, ctx)