Exemplo n.º 1
0
 def test_get_resources(self):
     app = openstack.APIRouterV11()
     ext_midware = extensions.ExtensionMiddleware(app)
     request = webob.Request.blank("/123/foxnsocks")
     response = request.get_response(ext_midware)
     self.assertEqual(200, response.status_int)
     self.assertEqual(response_body, response.body)
Exemplo n.º 2
0
 def test_invalid_extensions(self):
     app = openstack.APIRouterV11()
     ext_midware = extensions.ExtensionMiddleware(app)
     ext_mgr = ext_midware.ext_mgr
     ext_mgr.add_extension(InvalidExtension())
     self.assertTrue('FOXNSOX' in ext_mgr.extensions)
     self.assertTrue('THIRD' not in ext_mgr.extensions)
Exemplo n.º 3
0
 def test_no_extension_present(self):
     manager = StubExtensionManager(None)
     app = openstack.APIRouterV11()
     ext_midware = extensions.ExtensionMiddleware(app, manager)
     request = webob.Request.blank("/blah")
     response = request.get_response(ext_midware)
     self.assertEqual(404, response.status_int)
Exemplo n.º 4
0
    def test_list_extensions_json(self):
        app = openstack.APIRouterV11()
        ext_midware = extensions.ExtensionMiddleware(app)
        request = webob.Request.blank("/123/extensions")
        response = request.get_response(ext_midware)
        self.assertEqual(200, response.status_int)

        # Make sure we have all the extensions.
        data = json.loads(response.body)
        names = [x['name'] for x in data['extensions']]
        names.sort()
        self.assertEqual(names, self.ext_list)

        # Make sure that at least Fox in Sox is correct.
        (fox_ext, ) = [
            x for x in data['extensions'] if x['alias'] == 'FOXNSOX'
        ]
        self.assertEqual(
            fox_ext,
            {
                'namespace': 'http://www.fox.in.socks/api/ext/pie/v1.0',
                'name': 'Fox In Socks',
                'updated': '2011-01-22T13:25:27-06:00',
                'description': 'The Fox In Socks Extension',
                'alias': 'FOXNSOX',
                'links': []
            },
        )
Exemplo n.º 5
0
    def test_list_extensions_xml(self):
        app = openstack.APIRouterV11()
        ext_midware = extensions.ExtensionMiddleware(app)
        request = webob.Request.blank("/123/extensions")
        request.accept = "application/xml"
        response = request.get_response(ext_midware)
        self.assertEqual(200, response.status_int)
        print response.body

        root = etree.XML(response.body)
        self.assertEqual(root.tag.split('extensions')[0], NS)

        # Make sure we have all the extensions.
        exts = root.findall('{0}extension'.format(NS))
        self.assertEqual(len(exts), len(self.ext_list))

        # Make sure that at least Fox in Sox is correct.
        (fox_ext, ) = [x for x in exts if x.get('alias') == 'FOXNSOX']
        self.assertEqual(fox_ext.get('name'), 'Fox In Socks')
        self.assertEqual(fox_ext.get('namespace'),
                         'http://www.fox.in.socks/api/ext/pie/v1.0')
        self.assertEqual(fox_ext.get('updated'), '2011-01-22T13:25:27-06:00')
        self.assertEqual(fox_ext.findtext('{0}description'.format(NS)),
                         'The Fox In Socks Extension')

        xmlutil.validate_schema(root, 'extensions')
Exemplo n.º 6
0
 def _send_server_action_request(self, url, body):
     app = openstack.APIRouterV11()
     ext_midware = extensions.ExtensionMiddleware(app)
     request = webob.Request.blank(url)
     request.method = 'POST'
     request.content_type = 'application/json'
     request.body = json.dumps(body)
     response = request.get_response(ext_midware)
     return response
Exemplo n.º 7
0
 def test_get_resources_with_controller(self):
     res_ext = extensions.ResourceExtension('tweedles',
                                            StubController(response_body))
     manager = StubExtensionManager(res_ext)
     app = openstack.APIRouterV11()
     ext_midware = extensions.ExtensionMiddleware(app, manager)
     request = webob.Request.blank("/123/tweedles")
     response = request.get_response(ext_midware)
     self.assertEqual(200, response.status_int)
     self.assertEqual(response_body, response.body)
Exemplo n.º 8
0
    def test_get_resources_with_mgr(self):

        app = fakes.wsgi_app()
        ext_midware = extensions.ExtensionMiddleware(app)
        request = webob.Request.blank("/v1.1/123/flavors/1?chewing=newblue")
        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('newblue', response_data['flavor']['googoose'])
        self.assertEqual("Pig Bands!", response_data['big_bands'])
Exemplo n.º 9
0
    def test_get_extension_json(self):
        app = openstack.APIRouterV11()
        ext_midware = extensions.ExtensionMiddleware(app)
        request = webob.Request.blank("/123/extensions/FOXNSOX")
        response = request.get_response(ext_midware)
        self.assertEqual(200, response.status_int)

        data = json.loads(response.body)
        self.assertEqual(
            data['extension'], {
                "namespace": "http://www.fox.in.socks/api/ext/pie/v1.0",
                "name": "Fox In Socks",
                "updated": "2011-01-22T13:25:27-06:00",
                "description": "The Fox In Socks Extension",
                "alias": "FOXNSOX",
                "links": []
            })
Exemplo n.º 10
0
    def test_get_extension_xml(self):
        app = openstack.APIRouterV11()
        ext_midware = extensions.ExtensionMiddleware(app)
        request = webob.Request.blank("/extensions/FOXNSOX")
        request.accept = "application/xml"
        response = request.get_response(ext_midware)
        self.assertEqual(200, response.status_int)
        print response.body

        root = ElementTree.XML(response.body)
        self.assertEqual(root.tag.split('extension')[0], NS)
        self.assertEqual(root.get('alias'), 'FOXNSOX')
        self.assertEqual(root.get('name'), 'Fox In Socks')
        self.assertEqual(root.get('namespace'),
                         'http://www.fox.in.socks/api/ext/pie/v1.0')
        self.assertEqual(root.get('updated'), '2011-01-22T13:25:27-06:00')
        self.assertEqual(root.findtext('{0}description'.format(NS)),
                         'The Fox In Socks Extension')
Exemplo n.º 11
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.º 12
0
    def test_get_resources_with_stub_mgr(self):

        test_resp = "Gooey goo for chewy chewing!"

        def _resp_handler(res):
            # only handle JSON responses
            data = json.loads(res.body)
            data['flavor']['googoose'] = test_resp
            return data

        resp_ext = extensions.ResponseExtension('GET', '/v1.1/flavors/:(id)',
                                                _resp_handler)

        manager = StubExtensionManager(None, None, resp_ext)
        app = fakes.wsgi_app()
        ext_midware = extensions.ExtensionMiddleware(app, manager)
        request = webob.Request.blank("/v1.1/flavors/1")
        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(test_resp, response_data['flavor']['googoose'])
Exemplo n.º 13
0
 def test_get_non_existing_extension_json(self):
     app = openstack.APIRouterV11()
     ext_midware = extensions.ExtensionMiddleware(app)
     request = webob.Request.blank("/fake/extensions/4")
     response = request.get_response(ext_midware)
     self.assertEqual(404, response.status_int)
Exemplo n.º 14
0
 def test_get_by_alias(self):
     app = openstack.APIRouterV11()
     ext_midware = extensions.ExtensionMiddleware(app)
     request = webob.Request.blank("/extensions/FOXNSOX")
     response = request.get_response(ext_midware)
     self.assertEqual(200, response.status_int)