示例#1
0
    def test_get_v2_app(self):
        version_selector = api.VersionSelectorApplication()
        environ = {'PATH_INFO': "/v2"}

        versions_raw = version_selector(environ, self.start_response)
        versions = jsonutils.loads(versions_raw.pop())
        self.assertEqual(self.v2_make_app().versions, versions)
示例#2
0
    def test_no_versions_at_all(self):
        self.v1_make_app.return_value = FakeWSGIApp(1, "404 Not Found")
        self.v2_make_app.return_value = FakeWSGIApp(2, "404 Not Found")
        version_selector = api.VersionSelectorApplication()
        environ = {'PATH_INFO': self.path}

        versions_raw = version_selector(environ, self.start_response)
        self.assertEqual([], versions_raw)
        self.start_response_mock.assert_called_with("204 No Content", [])
示例#3
0
def main():
    """Entry point to start Blazar API wsgi server."""
    cfg.CONF(sys.argv[1:], project='blazar', prog='blazar-api')
    service_utils.prepare_service(sys.argv)
    if not CONF.enable_v1_api:
        app = v2_app.make_app()
    else:
        app = wsgi_app.VersionSelectorApplication()

    wsgi.server(eventlet.listen((CONF.host, CONF.port), backlog=500), app)
示例#4
0
def init_app():
    config_files = _get_config_files()
    CONF([],
         project='blazar',
         prog='blazar-api',
         default_config_files=config_files)
    service_utils.prepare_service()
    if not CONF.enable_v1_api:
        app = v2_app.make_app()
    else:
        app = wsgi_app.VersionSelectorApplication()

    return app
示例#5
0
    def test_get_versions_only_from_one_api(self):
        self.v2_make_app.return_value = FakeWSGIApp(2, "404 Not Found")
        version_selector = api.VersionSelectorApplication()
        environ = {'PATH_INFO': self.path}

        versions_raw = version_selector(environ, self.start_response)
        versions = jsonutils.loads(versions_raw.pop())

        self.assertEqual(1, len(versions['versions']))
        self.assertEqual("v{0}".format(self.v1_make_app().id_version),
                         versions['versions'][0]['id'])
        self.start_response_mock.assert_called_with(
            "300 Multiple Choices", [("Content-Type", "application/json")])
示例#6
0
    def test_unauthorized_token(self):
        self.v1_make_app.return_value = FakeWSGIApp(1, "401 Unauthorized")
        version_selector = api.VersionSelectorApplication()
        environ = {'PATH_INFO': self.path}

        versions_raw = version_selector(environ, self.start_response)
        self.assertEqual([
            '{"error": '
            '{"message": "The request you have '
            'made requires authentication.",'
            '"code": 401, "title": "Unauthorized"}}'
        ], versions_raw)

        self.start_response_mock.assert_called_with(
            "401 Unauthorized", [("Content-Type", "application/json")])