Exemplo n.º 1
0
    def get_request_extensions(self):
        request_exts = []

        def _goose_handler(req, res):
            #NOTE: This only handles JSON responses.
            # You can use content type header to test for XML.
            data = json.loads(res.body)
            data['flavor']['googoose'] = req.GET.get('chewing')
            res.body = json.dumps(data)
            return res

        req_ext1 = extensions.RequestExtension('GET', '/v1.1/flavors/:(id)',
                                               _goose_handler)
        request_exts.append(req_ext1)

        def _bands_handler(req, res):
            #NOTE: This only handles JSON responses.
            # You can use content type header to test for XML.
            data = json.loads(res.body)
            data['big_bands'] = 'Pig Bands!'
            res.body = json.dumps(data)
            return res

        req_ext2 = extensions.RequestExtension('GET', '/v1.1/flavors/:(id)',
                                               _bands_handler)
        request_exts.append(req_ext2)
        return request_exts
Exemplo n.º 2
0
    def test_get_resources_with_stub_mgr(self):
        def _req_handler(req, res):
            # only handle JSON responses
            data = json.loads(res.body)
            data['flavor']['googoose'] = req.GET.get('chewing')
            res.body = json.dumps(data)
            return res

        req_ext = extensions.RequestExtension('GET', '/v1.1/123/flavors/:(id)',
                                              _req_handler)

        manager = StubExtensionManager(None, None, req_ext)
        app = fakes.wsgi_app()
        ext_midware = extensions.ExtensionMiddleware(app, manager)
        request = webob.Request.blank("/v1.1/123/flavors/1?chewing=bluegoo")
        request.environ['api.version'] = '1.1'
        response = request.get_response(ext_midware)
        self.assertEqual(200, response.status_int)
        response_data = json.loads(response.body)
        self.assertEqual('bluegoo', response_data['flavor']['googoose'])
Exemplo n.º 3
0
    def test_get_resources_with_stub_mgr(self):
        def _req_handler(req, res, body):
            # only handle JSON responses
            body['flavor']['googoose'] = req.GET.get('chewing')
            return res

        req_ext = base_extensions.RequestExtension('GET',
                                                   '/v2/fake/flavors/:(id)',
                                                   _req_handler)

        manager = StubExtensionManager(None, None, req_ext)
        app = fakes.wsgi_app(serialization=base_wsgi.Middleware)
        ext_midware = compute_extensions.ExtensionMiddleware(app, manager)
        ser_midware = wsgi.LazySerializationMiddleware(ext_midware)
        request = webob.Request.blank("/v2/fake/flavors/1?chewing=bluegoo")
        request.environ['api.version'] = '2'
        response = request.get_response(ser_midware)
        self.assertEqual(200, response.status_int)
        response_data = json.loads(response.body)
        self.assertEqual('bluegoo', response_data['flavor']['googoose'])