示例#1
0
 def test_microversions_no_header(self, mock_namespace):
     app = fakes.wsgi_app_v21(init_only='test-microversions')
     req = fakes.HTTPRequest.blank('/v2/fake/microversions')
     res = req.get_response(app)
     self.assertEqual(200, res.status_int)
     resp_json = jsonutils.loads(res.body)
     self.assertEqual('val', resp_json['param'])
示例#2
0
 def _setup_app(self):
     return fakes.wsgi_app_v21(init_only=('os-flavor-manage',
                                          'os-flavor-access',
                                          'os-flavor-rxtx', 'flavors',
                                          'os-flavor-extra-data'),
                              fake_auth_context=self._get_http_request().
                                  environ['patron.context'])
示例#3
0
 def test_get_version_list_302(self):
     req = webob.Request.blank('/v2.1')
     req.accept = "application/json"
     res = req.get_response(fakes.wsgi_app_v21())
     self.assertEqual(res.status_int, 302)
     redirect_req = webob.Request.blank('/v2.1/')
     self.assertEqual(res.location, redirect_req.url)
示例#4
0
 def _make_request(self, url):
     req = webob.Request.blank(url)
     req.headers['Accept'] = self.content_type
     res = req.get_response(fakes.wsgi_app_v21(
         init_only=('servers',
                    'os-extended-status')))
     return res
示例#5
0
 def test_authorize_user(self):
     req = webob.Request.blank("/v2/fake")
     req.headers["X-Auth-User"] = "******"
     req.headers["X-Auth-Key"] = "user1_key"
     req.headers["X-Auth-Project-Id"] = "user1_project"
     result = req.get_response(fakes.wsgi_app_v21(use_no_auth=True))
     self.assertEqual(result.status, "204 No Content")
     self.assertEqual(result.headers["X-Server-Management-Url"], "http://localhost/v2/fake")
示例#6
0
    def test_microversions2_version_too_high(self, mock_namespace,
                                             mock_maxver):
        mock_maxver.return_value = api_version.APIVersionRequest("3.5")

        app = fakes.wsgi_app_v21(init_only='test-microversions')
        req = fakes.HTTPRequest.blank('/v2/fake/microversions2')
        req.headers = {self.header_name: '3.2'}
        res = req.get_response(app)
        self.assertEqual(404, res.status_int)
示例#7
0
 def test_accept_version_v21(self):
     # Test Accept header specifying v2.1 returns v2.1 content.
     req = webob.Request.blank('/')
     req.accept = "application/json;version=2.1"
     res = req.get_response(fakes.wsgi_app_v21(init_only=('versions',)))
     self.assertEqual(res.status_int, 200)
     self.assertEqual(res.content_type, "application/json")
     body = jsonutils.loads(res.body)
     self.assertEqual(body['version']['id'], 'v2.1')
示例#8
0
 def test_auth_token_no_empty_headers(self):
     req = webob.Request.blank('/v2/fake')
     req.headers['X-Auth-User'] = '******'
     req.headers['X-Auth-Key'] = 'user1_key'
     req.headers['X-Auth-Project-Id'] = 'user1_project'
     result = req.get_response(fakes.wsgi_app_v21(use_no_auth=True))
     self.assertEqual(result.status, '204 No Content')
     self.assertNotIn('X-CDN-Management-Url', result.headers)
     self.assertNotIn('X-Storage-Url', result.headers)
示例#9
0
 def test_authorize_user(self):
     req = webob.Request.blank('/v2/fake')
     req.headers['X-Auth-User'] = '******'
     req.headers['X-Auth-Key'] = 'user1_key'
     req.headers['X-Auth-Project-Id'] = 'user1_project'
     result = req.get_response(fakes.wsgi_app_v21(use_no_auth=True))
     self.assertEqual(result.status, '204 No Content')
     self.assertEqual(result.headers['X-Server-Management-Url'],
                      "http://localhost/v2/fake")
示例#10
0
 def test_accept_version_v21(self):
     # Test Accept header specifying v2.1 returns v2.1 content.
     req = webob.Request.blank('/')
     req.accept = "application/json;version=2.1"
     res = req.get_response(fakes.wsgi_app_v21(init_only=('versions', )))
     self.assertEqual(res.status_int, 200)
     self.assertEqual(res.content_type, "application/json")
     body = jsonutils.loads(res.body)
     self.assertEqual(body['version']['id'], 'v2.1')
示例#11
0
 def test_auth_token_no_empty_headers(self):
     req = webob.Request.blank("/v2/fake")
     req.headers["X-Auth-User"] = "******"
     req.headers["X-Auth-Key"] = "user1_key"
     req.headers["X-Auth-Project-Id"] = "user1_project"
     result = req.get_response(fakes.wsgi_app_v21(use_no_auth=True))
     self.assertEqual(result.status, "204 No Content")
     self.assertNotIn("X-CDN-Management-Url", result.headers)
     self.assertNotIn("X-Storage-Url", result.headers)
示例#12
0
 def test_get_version_21_detail_content_type(self):
     req = webob.Request.blank('/')
     req.accept = "application/json;version=2.1"
     res = req.get_response(fakes.wsgi_app_v21())
     self.assertEqual(res.status_int, 200)
     self.assertEqual(res.content_type, "application/json")
     version = jsonutils.loads(res.body)
     expected = {"version": self.exp_versions['v2.1']}
     self.assertEqual(expected, version)
示例#13
0
    def test_plugin_framework_index(self, mock_namespace):
        mock_namespace.return_value = 'patron.api.v3.test_extensions'

        app = fakes.wsgi_app_v21(init_only='test-basic')
        req = fakes.HTTPRequest.blank('/v2/fake/test')
        res = req.get_response(app)
        self.assertEqual(200, res.status_int)
        resp_json = jsonutils.loads(res.body)
        self.assertEqual('val', resp_json['param'])
示例#14
0
    def test_plugin_framework_index(self, mock_namespace):
        mock_namespace.return_value = 'patron.api.v3.test_extensions'

        app = fakes.wsgi_app_v21(init_only='test-basic')
        req = fakes.HTTPRequest.blank('/v2/fake/test')
        res = req.get_response(app)
        self.assertEqual(200, res.status_int)
        resp_json = jsonutils.loads(res.body)
        self.assertEqual('val', resp_json['param'])
 def _make_request(self, url):
     req = fakes.HTTPRequest.blank(url)
     req.headers['Accept'] = self.content_type
     req.headers = {os_wsgi.API_VERSION_REQUEST_HEADER:
                    self.wsgi_api_version}
     res = req.get_response(
         fakes.wsgi_app_v21(init_only=('servers',
                                       'os-extended-server-attributes')))
     return res
示例#16
0
    def test_microversions2_later_version(self, mock_namespace, mock_maxver):
        mock_maxver.return_value = api_version.APIVersionRequest("3.1")

        app = fakes.wsgi_app_v21(init_only='test-microversions')
        req = fakes.HTTPRequest.blank('/v2/fake/microversions2')
        req.headers = {self.header_name: '3.0'}
        res = req.get_response(app)
        self.assertEqual(202, res.status_int)
        resp_json = jsonutils.loads(res.body)
        self.assertEqual('controller2_val2', resp_json['param'])
示例#17
0
    def _check_microversion_response(self, url, req_version, resp_param,
                                     mock_namespace, mock_maxver):
        mock_maxver.return_value = api_version.APIVersionRequest('2.3')

        app = fakes.wsgi_app_v21(init_only='test-microversions')
        req = fakes.HTTPRequest.blank(url)
        req.headers = {self.header_name: req_version}
        res = req.get_response(app)
        self.assertEqual(200, res.status_int)
        resp_json = jsonutils.loads(res.body)
        self.assertEqual(resp_param, resp_json['param'])
示例#18
0
    def test_microversions_return_header_fault(self, mock_namespace,
                                               mock_maxver):
        mock_maxver.return_value = api_version.APIVersionRequest("3.0")

        app = fakes.wsgi_app_v21(init_only='test-microversions')
        req = fakes.HTTPRequest.blank('/v2/fake/microversions')
        req.headers = {self.header_name: '3.0'}
        res = req.get_response(app)
        self.assertEqual(400, res.status_int)
        self.assertEqual("3.0", res.headers[self.header_name])
        self.assertEqual(self.header_name, res.headers['Vary'])
示例#19
0
    def test_microversions_return_header_non_default(self, mock_namespace,
                                                     mock_maxver):
        mock_maxver.return_value = api_version.APIVersionRequest("2.3")

        app = fakes.wsgi_app_v21(init_only='test-microversions')
        req = fakes.HTTPRequest.blank('/v2/fake/microversions')
        req.headers = {self.header_name: '2.3'}
        res = req.get_response(app)
        self.assertEqual(200, res.status_int)
        resp_json = jsonutils.loads(res.body)
        self.assertEqual('val2', resp_json['param'])
        self.assertEqual("2.3", res.headers[self.header_name])
        self.assertEqual(self.header_name, res.headers['Vary'])
示例#20
0
    def _test_microversions_inner_function(self, version, expected_resp,
                                           mock_namespace, mock_maxver):
        mock_maxver.return_value = api_version.APIVersionRequest("2.2")
        app = fakes.wsgi_app_v21(init_only='test-microversions')
        req = fakes.HTTPRequest.blank('/v2/fake/microversions4')
        req.headers = {self.header_name: version}
        req.environ['CONTENT_TYPE'] = "application/json"
        req.method = 'POST'

        res = req.get_response(app)
        self.assertEqual(200, res.status_int)
        resp_json = jsonutils.loads(res.body)
        self.assertEqual(expected_resp, resp_json['param'])
        self.assertEqual(version, res.headers[self.header_name])
示例#21
0
    def test_microversions_global_version_too_high(self, mock_namespace,
                                                   mock_maxver):
        mock_maxver.return_value = api_version.APIVersionRequest("3.5")

        app = fakes.wsgi_app_v21(init_only='test-microversions')
        req = fakes.HTTPRequest.blank('/v2/fake/microversions2')
        req.headers = {self.header_name: '3.7'}
        res = req.get_response(app)
        self.assertEqual(406, res.status_int)
        res_json = jsonutils.loads(res.body)
        self.assertEqual(
            "Version 3.7 is not supported by the API. "
            "Minimum is 2.1 and maximum is 3.5.",
            res_json['computeFault']['message'])
示例#22
0
    def test_microversions_schema_fail(self, mock_namespace, mock_maxver):
        mock_maxver.return_value = api_version.APIVersionRequest("3.3")

        app = fakes.wsgi_app_v21(init_only='test-microversions')
        req = fakes.HTTPRequest.blank('/v2/fake/microversions3')
        req.method = 'POST'
        req.headers = {self.header_name: '2.2'}
        req.environ['CONTENT_TYPE'] = "application/json"
        req.body = jsonutils.dumps({'dummy': {'invalid_param': 'foo'}})

        res = req.get_response(app)
        self.assertEqual(400, res.status_int)
        resp_json = jsonutils.loads(res.body)
        self.assertTrue(resp_json['badRequest']['message'].startswith(
            "Invalid input for field/attribute dummy."))
示例#23
0
    def test_microversions_schema_second_version(self, mock_namespace,
                                                 mock_maxver):
        mock_maxver.return_value = api_version.APIVersionRequest("3.3")

        app = fakes.wsgi_app_v21(init_only='test-microversions')
        req = fakes.HTTPRequest.blank('/v2/fake/microversions3/1')
        req.headers = {self.header_name: '2.10'}
        req.environ['CONTENT_TYPE'] = "application/json"
        req.method = 'PUT'
        req.body = jsonutils.dumps({'dummy': {'val2': 'foo'}})

        res = req.get_response(app)
        self.assertEqual(200, res.status_int)
        resp_json = jsonutils.loads(res.body)
        self.assertEqual('update_val1', resp_json['param'])
        self.assertEqual("2.10", res.headers[self.header_name])
示例#24
0
    def _test_microversions_actions(self, ret_code, ret_header, req_header,
                                    mock_namespace, mock_maxver):
        mock_maxver.return_value = api_version.APIVersionRequest("2.3")

        app = fakes.wsgi_app_v21(init_only='test-microversions')
        req = fakes.HTTPRequest.blank('/v2/fake/microversions3/1/action')
        if req_header:
            req.headers = {self.header_name: req_header}
        req.method = 'POST'
        req.body = jsonutils.dumps({'foo': None})

        res = self._test_microversions(app,
                                       req,
                                       ret_code,
                                       ret_header=ret_header)
        if ret_code == 202:
            resp_json = jsonutils.loads(res.body)
            self.assertEqual({'foo': 'bar'}, resp_json)
示例#25
0
    def test_with_extends_decorator(self, mock_namespace, mock_maxver):
        mock_maxver.return_value = api_version.APIVersionRequest('2.4')

        app = fakes.wsgi_app_v21(init_only='test-microversions')
        req = fakes.HTTPRequest.blank('/v2/fake/microversions5/item')
        req.headers = {'X-OpenStack-Nova-API-Version': '2.4'}
        res = req.get_response(app)
        self.assertEqual(200, res.status_int)

        expected_res = {
            "extend_ctrlr2": "val_2",
            "extend_ctrlr1": "val_1",
            "base_param": "base_val"
        }

        resp_json = jsonutils.loads(res.body)
        for param in resp_json:
            self.assertIn(param, expected_res)
            self.assertEqual(expected_res[param], resp_json[param])
        self.assertEqual(3, len(resp_json))
示例#26
0
 def _setup_app(self):
     return fakes.wsgi_app_v21(init_only=('os-extended-volumes',
                                          'servers'))
示例#27
0
 def _make_request(self, url):
     req = webob.Request.blank(url)
     req.headers['Accept'] = self.content_type
     res = req.get_response(fakes.wsgi_app_v21(init_only=(
         'servers', 'os-extended-availability-zone')))
     return res
示例#28
0
 def _setup_app_and_controller(self):
     self.app_server = fakes.wsgi_app_v21(init_only=('os-keypairs',
                                                     'servers'))
     self.controller = keypairs_v21.KeypairController()
 def _setup_wsgi(self):
     self.wsgi_app = fakes.wsgi_app_v21(
         init_only=('servers', 'os-hide-server-addresses'))
示例#30
0
 def _setup_wsgi(self):
     self.app = fakes.wsgi_app_v21(init_only=('servers', 'os-config-drive'))
示例#31
0
 def _get_app(self):
     return fakes.wsgi_app_v21()
示例#32
0
 def _setup_app(self):
     return fakes.wsgi_app_v21(init_only=('os-extended-volumes', 'servers'))
示例#33
0
 def _setup_app(self):
     return fakes.wsgi_app_v21(init_only=('os-flavor-manage',
                                          'os-flavor-rxtx',
                                          'os-flavor-access', 'flavors',
                                          'os-flavor-extra-data'))
示例#34
0
 def _setup_app(self):
     self.app = fakes.wsgi_app_v21(init_only=('flavors'))
示例#35
0
 def _make_request(self, url):
     req = webob.Request.blank(url)
     req.headers['Accept'] = self.content_type
     res = req.get_response(fakes.wsgi_app_v21(init_only=('flavors')))
     return res
示例#36
0
 def _get_app(self):
     return fakes.wsgi_app_v21()
示例#37
0
 def _setup_app_and_controller(self):
     self.app_server = fakes.wsgi_app_v21(init_only=('os-keypairs',
                                                     'servers'))
     self.controller = keypairs_v21.KeypairController()
示例#38
0
 def _make_request(self, url):
     req = webob.Request.blank(url)
     req.headers["Accept"] = self.content_type
     res = req.get_response(fakes.wsgi_app_v21(init_only=("flavors")))
     return res
示例#39
0
 def _setup_app(self):
     return fakes.wsgi_app_v21(init_only=('os-flavor-manage',
                                          'os-flavor-rxtx',
                                          'os-flavor-access', 'flavors',
                                          'os-flavor-extra-data'))
示例#40
0
 def test_get_version_21_versions_invalid(self):
     req = webob.Request.blank('/v2.1/versions/1234')
     req.accept = "application/json"
     res = req.get_response(fakes.wsgi_app_v21())
     self.assertEqual(res.status_int, 404)
示例#41
0
 def _setup_app(self):
     return fakes.wsgi_app_v21(
         init_only=('os-flavor-manage', 'os-flavor-access',
                    'os-flavor-rxtx', 'flavors', 'os-flavor-extra-data'),
         fake_auth_context=self._get_http_request(
         ).environ['patron.context'])
示例#42
0
 def _get_app(self):
     return fakes.wsgi_app_v21(init_only=('servers', 'flavors',
                                          'os-flavor-rxtx'))
示例#43
0
 def _get_app(self):
     return fakes.wsgi_app_v21(init_only=('servers', 'os-server-usage'))
示例#44
0
 def _get_app(self):
     return fakes.wsgi_app_v21(init_only=('servers',
         'flavors', 'os-flavor-rxtx'))