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'])
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'])
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)
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
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")
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)
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')
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)
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")
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')
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)
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)
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
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'])
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'])
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'])
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'])
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])
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'])
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."))
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])
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)
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))
def _setup_app(self): return fakes.wsgi_app_v21(init_only=('os-extended-volumes', 'servers'))
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
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'))
def _setup_wsgi(self): self.app = fakes.wsgi_app_v21(init_only=('servers', 'os-config-drive'))
def _get_app(self): return fakes.wsgi_app_v21()
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'))
def _setup_app(self): self.app = fakes.wsgi_app_v21(init_only=('flavors'))
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
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
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)
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'])
def _get_app(self): return fakes.wsgi_app_v21(init_only=('servers', 'flavors', 'os-flavor-rxtx'))
def _get_app(self): return fakes.wsgi_app_v21(init_only=('servers', 'os-server-usage'))