Extracted HTTP response codes to constants
There are several places in the source code where HTTP response codes are used as numeric values. Status codes 200, 202, 204, 300, 400, 403, 404, 405 , 406 and 413 under tests/unit/api/v2 and tests/unit/api/v3 are replaced with symbolic constants from six.moves.http_client thus improves code readability. More patches will be submitted to address other status codes. Partial-Bug: #1520159 Change-Id: Iaa337432f9a368c33be9a182d9074cc316241cb9
This commit is contained in:
parent
35738c47ab
commit
665775f924
|
@ -17,6 +17,7 @@ import ddt
|
|||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import encodeutils
|
||||
import six
|
||||
from six.moves import http_client
|
||||
import webob
|
||||
|
||||
from cinder.api.openstack import api_version_request
|
||||
|
@ -63,7 +64,7 @@ class VersionsControllerTestCase(test.TestCase):
|
|||
req = self.build_request(base_url='http://localhost')
|
||||
|
||||
response = req.get_response(versions.Versions())
|
||||
self.assertEqual(300, response.status_int)
|
||||
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status_int)
|
||||
body = jsonutils.loads(response.body)
|
||||
version_list = body['versions']
|
||||
|
||||
|
@ -88,13 +89,13 @@ class VersionsControllerTestCase(test.TestCase):
|
|||
req = self.build_request(base_url='http://localhost/v1')
|
||||
|
||||
response = req.get_response(router.APIRouter())
|
||||
self.assertEqual(200, response.status_int)
|
||||
self.assertEqual(http_client.OK, response.status_int)
|
||||
|
||||
def test_versions_v2_no_header(self):
|
||||
req = self.build_request(base_url='http://localhost/v2')
|
||||
|
||||
response = req.get_response(router.APIRouter())
|
||||
self.assertEqual(200, response.status_int)
|
||||
self.assertEqual(http_client.OK, response.status_int)
|
||||
|
||||
@ddt.data('1.0', '2.0', '3.0')
|
||||
def test_versions(self, version):
|
||||
|
@ -106,7 +107,7 @@ class VersionsControllerTestCase(test.TestCase):
|
|||
req.headers = {VERSION_HEADER_NAME: VOLUME_SERVICE + version}
|
||||
|
||||
response = req.get_response(router.APIRouter())
|
||||
self.assertEqual(200, response.status_int)
|
||||
self.assertEqual(http_client.OK, response.status_int)
|
||||
body = jsonutils.loads(response.body)
|
||||
version_list = body['versions']
|
||||
|
||||
|
@ -128,7 +129,7 @@ class VersionsControllerTestCase(test.TestCase):
|
|||
|
||||
response = req.get_response(router.APIRouter())
|
||||
|
||||
self.assertEqual(200, response.status_int)
|
||||
self.assertEqual(http_client.OK, response.status_int)
|
||||
self.check_response(response, api_version_request._MAX_API_VERSION)
|
||||
|
||||
def test_versions_version_invalid(self):
|
||||
|
@ -137,7 +138,7 @@ class VersionsControllerTestCase(test.TestCase):
|
|||
for app in self.wsgi_apps:
|
||||
response = req.get_response(app)
|
||||
|
||||
self.assertEqual(400, response.status_int)
|
||||
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
|
||||
|
||||
@ddt.data('1.0', '2.0', '3.0')
|
||||
def test_versions_response_fault(self, version):
|
||||
|
@ -148,7 +149,7 @@ class VersionsControllerTestCase(test.TestCase):
|
|||
app = wsgi.Fault(webob.exc.HTTPBadRequest(explanation='what?'))
|
||||
response = req.get_response(app)
|
||||
|
||||
self.assertEqual(400, response.status_int)
|
||||
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
|
||||
if version == '3.0':
|
||||
self.check_response(response, '3.0')
|
||||
else:
|
||||
|
@ -234,32 +235,32 @@ class VersionsControllerTestCase(test.TestCase):
|
|||
self.assertEqual('None.None', _get_str_version(new_method.end_version))
|
||||
|
||||
@ddt.data(
|
||||
('2.0', 'index', 406, 'ControllerParent'),
|
||||
('2.0', 'show', 406, 'ControllerParent'),
|
||||
('3.0', 'index', 404, 'ControllerParent'),
|
||||
('3.0', 'show', 404, 'ControllerParent'),
|
||||
('2.0', 'index', http_client.NOT_ACCEPTABLE, 'ControllerParent'),
|
||||
('2.0', 'show', http_client.NOT_ACCEPTABLE, 'ControllerParent'),
|
||||
('3.0', 'index', http_client.NOT_FOUND, 'ControllerParent'),
|
||||
('3.0', 'show', http_client.NOT_FOUND, 'ControllerParent'),
|
||||
('3.1', 'index', 'parent', 'ControllerParent'),
|
||||
('3.1', 'show', 404, 'ControllerParent'),
|
||||
('3.1', 'show', http_client.NOT_FOUND, 'ControllerParent'),
|
||||
('3.2', 'index', 'parent', 'ControllerParent'),
|
||||
('3.2', 'show', 404, 'ControllerParent'),
|
||||
('3.2', 'show', http_client.NOT_FOUND, 'ControllerParent'),
|
||||
|
||||
('2.0', 'index', 406, 'Controller'),
|
||||
('2.0', 'show', 406, 'Controller'),
|
||||
('3.0', 'index', 404, 'Controller'),
|
||||
('3.0', 'show', 404, 'Controller'),
|
||||
('2.0', 'index', http_client.NOT_ACCEPTABLE, 'Controller'),
|
||||
('2.0', 'show', http_client.NOT_ACCEPTABLE, 'Controller'),
|
||||
('3.0', 'index', http_client.NOT_FOUND, 'Controller'),
|
||||
('3.0', 'show', http_client.NOT_FOUND, 'Controller'),
|
||||
('3.1', 'index', 'single', 'Controller'),
|
||||
('3.1', 'show', 404, 'Controller'),
|
||||
('3.1', 'show', http_client.NOT_FOUND, 'Controller'),
|
||||
('3.2', 'index', 'single', 'Controller'),
|
||||
('3.2', 'show', 404, 'Controller'),
|
||||
('3.2', 'show', http_client.NOT_FOUND, 'Controller'),
|
||||
|
||||
('2.0', 'index', 406, 'ControllerChild'),
|
||||
('2.0', 'show', 406, 'ControllerChild'),
|
||||
('3.0', 'index', 404, 'ControllerChild'),
|
||||
('3.0', 'show', 404, 'ControllerChild'),
|
||||
('2.0', 'index', http_client.NOT_ACCEPTABLE, 'ControllerChild'),
|
||||
('2.0', 'show', http_client.NOT_ACCEPTABLE, 'ControllerChild'),
|
||||
('3.0', 'index', http_client.NOT_FOUND, 'ControllerChild'),
|
||||
('3.0', 'show', http_client.NOT_FOUND, 'ControllerChild'),
|
||||
('3.1', 'index', 'parent', 'ControllerChild'),
|
||||
('3.1', 'show', 404, 'ControllerChild'),
|
||||
('3.1', 'show', http_client.NOT_FOUND, 'ControllerChild'),
|
||||
('3.2', 'index', 'child 3.2', 'ControllerChild'),
|
||||
('3.2', 'show', 404, 'ControllerChild'),
|
||||
('3.2', 'show', http_client.NOT_FOUND, 'ControllerChild'),
|
||||
('3.3', 'index', 'child 3.3', 'ControllerChild'),
|
||||
('3.3', 'show', 'show', 'ControllerChild'),
|
||||
('3.4', 'index', 'child 3.4', 'ControllerChild'))
|
||||
|
@ -307,7 +308,7 @@ class VersionsControllerTestCase(test.TestCase):
|
|||
resp = encodeutils.safe_decode(response.body, incoming='utf-8')
|
||||
|
||||
if isinstance(expected, six.string_types):
|
||||
self.assertEqual(200, response.status_int)
|
||||
self.assertEqual(http_client.OK, response.status_int)
|
||||
self.assertEqual(expected, resp)
|
||||
else:
|
||||
self.assertEqual(expected, response.status_int)
|
||||
|
@ -329,14 +330,14 @@ class VersionsControllerTestCase(test.TestCase):
|
|||
|
||||
response = req.get_response(app)
|
||||
|
||||
self.assertEqual(404, response.status_int)
|
||||
self.assertEqual(http_client.NOT_FOUND, response.status_int)
|
||||
|
||||
def test_versions_version_not_acceptable(self):
|
||||
req = self.build_request(header_version='4.0')
|
||||
|
||||
response = req.get_response(router.APIRouter())
|
||||
|
||||
self.assertEqual(406, response.status_int)
|
||||
self.assertEqual(http_client.NOT_ACCEPTABLE, response.status_int)
|
||||
|
||||
@ddt.data(['volume 3.0, compute 2.22', True],
|
||||
['volume 3.0, compute 2.22, identity 2.3', True],
|
||||
|
@ -355,7 +356,7 @@ class VersionsControllerTestCase(test.TestCase):
|
|||
elif not should_pass:
|
||||
return
|
||||
|
||||
self.assertEqual(200, response.status_int)
|
||||
self.assertEqual(http_client.OK, response.status_int)
|
||||
body = jsonutils.loads(response.body)
|
||||
version_list = body['versions']
|
||||
|
||||
|
@ -368,7 +369,7 @@ class VersionsControllerTestCase(test.TestCase):
|
|||
self.assertEqual(api_version_request._MIN_API_VERSION,
|
||||
version_list[0].get('min_version'))
|
||||
|
||||
@ddt.data(['3.5', 200], ['3.55', 404])
|
||||
@ddt.data(['3.5', http_client.OK], ['3.55', http_client.NOT_FOUND])
|
||||
@ddt.unpack
|
||||
def test_req_version_matches(self, version, HTTP_ret):
|
||||
version_request = api_version_request.APIVersionRequest(version)
|
||||
|
@ -388,9 +389,9 @@ class VersionsControllerTestCase(test.TestCase):
|
|||
response = req.get_response(app)
|
||||
resp = encodeutils.safe_decode(response.body, incoming='utf-8')
|
||||
|
||||
if HTTP_ret == 200:
|
||||
if HTTP_ret == http_client.OK:
|
||||
self.assertEqual('off', resp)
|
||||
elif HTTP_ret == 404:
|
||||
elif HTTP_ret == http_client.NOT_FOUND:
|
||||
self.assertNotEqual('off', resp)
|
||||
self.assertEqual(HTTP_ret, response.status_int)
|
||||
|
||||
|
@ -418,7 +419,7 @@ class VersionsControllerTestCase(test.TestCase):
|
|||
|
||||
resp = encodeutils.safe_decode(response.body, incoming='utf-8')
|
||||
self.assertEqual(ret_val, resp)
|
||||
self.assertEqual(200, response.status_int)
|
||||
self.assertEqual(http_client.OK, response.status_int)
|
||||
|
||||
@ddt.data(['3.5', 'older'], ['3.37', 'newer'])
|
||||
@ddt.unpack
|
||||
|
@ -444,7 +445,7 @@ class VersionsControllerTestCase(test.TestCase):
|
|||
|
||||
resp = encodeutils.safe_decode(response.body, incoming='utf-8')
|
||||
self.assertEqual(ret_val, resp)
|
||||
self.assertEqual(200, response.status_int)
|
||||
self.assertEqual(http_client.OK, response.status_int)
|
||||
|
||||
def test_req_version_matches_with_None_None(self):
|
||||
version_request = api_version_request.APIVersionRequest('3.39')
|
||||
|
@ -467,4 +468,4 @@ class VersionsControllerTestCase(test.TestCase):
|
|||
|
||||
resp = encodeutils.safe_decode(response.body, incoming='utf-8')
|
||||
self.assertEqual("Pass", resp)
|
||||
self.assertEqual(200, response.status_int)
|
||||
self.assertEqual(http_client.OK, response.status_int)
|
||||
|
|
|
@ -252,17 +252,18 @@ class LimitMiddlewareTest(BaseLimitTestSuite):
|
|||
"""Test successful GET request through middleware."""
|
||||
request = webob.Request.blank("/")
|
||||
response = request.get_response(self.app)
|
||||
self.assertEqual(200, response.status_int)
|
||||
self.assertEqual(http_client.OK, response.status_int)
|
||||
|
||||
def test_limited_request_json(self):
|
||||
"""Test a rate-limited (413) GET request through middleware."""
|
||||
request = webob.Request.blank("/")
|
||||
response = request.get_response(self.app)
|
||||
self.assertEqual(200, response.status_int)
|
||||
self.assertEqual(http_client.OK, response.status_int)
|
||||
|
||||
request = webob.Request.blank("/")
|
||||
response = request.get_response(self.app)
|
||||
self.assertEqual(413, response.status_int)
|
||||
self.assertEqual(http_client.REQUEST_ENTITY_TOO_LARGE,
|
||||
response.status_int)
|
||||
|
||||
self.assertIn('Retry-After', response.headers)
|
||||
retry_after = int(response.headers['Retry-After'])
|
||||
|
@ -574,17 +575,18 @@ class WsgiLimiterTest(BaseLimitTestSuite):
|
|||
response = request.get_response(self.app)
|
||||
|
||||
if "X-Wait-Seconds" in response.headers:
|
||||
self.assertEqual(403, response.status_int)
|
||||
self.assertEqual(http_client.FORBIDDEN, response.status_int)
|
||||
return response.headers["X-Wait-Seconds"]
|
||||
|
||||
self.assertEqual(204, response.status_int)
|
||||
self.assertEqual(http_client.NO_CONTENT, response.status_int)
|
||||
|
||||
def test_invalid_methods(self):
|
||||
"""Only POSTs should work."""
|
||||
for method in ["GET", "PUT", "DELETE", "HEAD", "OPTIONS"]:
|
||||
request = webob.Request.blank("/", method=method)
|
||||
response = request.get_response(self.app)
|
||||
self.assertEqual(405, response.status_int)
|
||||
self.assertEqual(http_client.METHOD_NOT_ALLOWED,
|
||||
response.status_int)
|
||||
|
||||
def test_good_url(self):
|
||||
delay = self._request("GET", "/something")
|
||||
|
|
|
@ -17,6 +17,7 @@ import uuid
|
|||
|
||||
import mock
|
||||
from oslo_serialization import jsonutils
|
||||
from six.moves import http_client
|
||||
import webob
|
||||
|
||||
from cinder.api import extensions
|
||||
|
@ -236,7 +237,7 @@ class SnapshotMetaDataTest(test.TestCase):
|
|||
req.method = 'DELETE'
|
||||
res = self.controller.delete(req, self.req_id, 'key2')
|
||||
|
||||
self.assertEqual(200, res.status_int)
|
||||
self.assertEqual(http_client.OK, res.status_int)
|
||||
|
||||
def test_delete_nonexistent_snapshot(self):
|
||||
self.mock_object(cinder.db, 'snapshot_get',
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
import ddt
|
||||
import mock
|
||||
from oslo_config import cfg
|
||||
from six.moves import http_client
|
||||
from six.moves.urllib import parse as urllib
|
||||
import webob
|
||||
|
||||
|
@ -283,7 +284,7 @@ class SnapshotApiTest(test.TestCase):
|
|||
snapshot_id = UUID
|
||||
req = fakes.HTTPRequest.blank('/v2/snapshots/%s' % snapshot_id)
|
||||
resp = self.controller.delete(req, snapshot_id)
|
||||
self.assertEqual(202, resp.status_int)
|
||||
self.assertEqual(http_client.ACCEPTED, resp.status_int)
|
||||
|
||||
def test_snapshot_delete_invalid_id(self):
|
||||
self.mock_object(volume.api.API, "delete_snapshot",
|
||||
|
|
|
@ -18,6 +18,7 @@ import uuid
|
|||
import mock
|
||||
from oslo_config import cfg
|
||||
from oslo_serialization import jsonutils
|
||||
from six.moves import http_client
|
||||
import webob
|
||||
|
||||
from cinder.api import extensions
|
||||
|
@ -200,7 +201,7 @@ class volumeMetaDataTest(test.TestCase):
|
|||
'get') as get_volume:
|
||||
get_volume.return_value = fake_volume
|
||||
res = self.controller.delete(req, self.req_id, 'key2')
|
||||
self.assertEqual(200, res.status_int)
|
||||
self.assertEqual(http_client.OK, res.status_int)
|
||||
get_volume.assert_called_once_with(fake_context, self.req_id)
|
||||
|
||||
@mock.patch.object(db, 'volume_metadata_delete')
|
||||
|
|
|
@ -21,6 +21,7 @@ import ddt
|
|||
import mock
|
||||
from oslo_config import cfg
|
||||
import six
|
||||
from six.moves import http_client
|
||||
from six.moves import range
|
||||
from six.moves import urllib
|
||||
import webob
|
||||
|
@ -1428,7 +1429,7 @@ class VolumeApiTest(test.TestCase):
|
|||
def test_volume_delete(self):
|
||||
req = fakes.HTTPRequest.blank('/v2/volumes/%s' % fake.VOLUME_ID)
|
||||
resp = self.controller.delete(req, fake.VOLUME_ID)
|
||||
self.assertEqual(202, resp.status_int)
|
||||
self.assertEqual(http_client.ACCEPTED, resp.status_int)
|
||||
|
||||
def test_volume_delete_attached(self):
|
||||
def fake_volume_attached(self, context, volume,
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
# under the License.
|
||||
|
||||
import ddt
|
||||
from six.moves import http_client
|
||||
import webob
|
||||
|
||||
from cinder.api.openstack import api_version_request as api_version
|
||||
|
@ -83,7 +84,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase):
|
|||
body)
|
||||
consistencygroup = objects.ConsistencyGroup.get_by_id(
|
||||
self.ctxt, consistencygroup.id)
|
||||
self.assertEqual(202, res_dict.status_int)
|
||||
self.assertEqual(http_client.ACCEPTED, res_dict.status_int)
|
||||
self.assertEqual("", consistencygroup.name)
|
||||
self.assertEqual("", consistencygroup.description)
|
||||
consistencygroup.destroy()
|
||||
|
|
|
@ -19,6 +19,7 @@ Tests for group_snapshot code.
|
|||
|
||||
import ddt
|
||||
import mock
|
||||
from six.moves import http_client
|
||||
import webob
|
||||
|
||||
from cinder.api.v3 import group_snapshots as v3_group_snapshots
|
||||
|
@ -413,7 +414,7 @@ class GroupSnapshotsAPITestCase(test.TestCase):
|
|||
|
||||
group_snapshot = objects.GroupSnapshot.get_by_id(self.context,
|
||||
group_snapshot.id)
|
||||
self.assertEqual(202, res_dict.status_int)
|
||||
self.assertEqual(http_client.ACCEPTED, res_dict.status_int)
|
||||
self.assertEqual('deleting', group_snapshot.status)
|
||||
|
||||
group_snapshot.destroy()
|
||||
|
@ -515,7 +516,7 @@ class GroupSnapshotsAPITestCase(test.TestCase):
|
|||
|
||||
g_snapshot = objects.GroupSnapshot.get_by_id(self.context,
|
||||
group_snapshot.id)
|
||||
self.assertEqual(202, response.status_int)
|
||||
self.assertEqual(http_client.ACCEPTED, response.status_int)
|
||||
self.assertEqual(fields.GroupSnapshotStatus.AVAILABLE,
|
||||
g_snapshot.status)
|
||||
group_snapshot.destroy()
|
||||
|
|
|
@ -19,6 +19,7 @@ Tests for group code.
|
|||
|
||||
import ddt
|
||||
import mock
|
||||
from six.moves import http_client
|
||||
import webob
|
||||
|
||||
from cinder.api.v3 import groups as v3_groups
|
||||
|
@ -442,7 +443,7 @@ class GroupsAPITestCase(test.TestCase):
|
|||
|
||||
group = objects.Group.get_by_id(
|
||||
self.ctxt, self.group1.id)
|
||||
self.assertEqual(202, res_dict.status_int)
|
||||
self.assertEqual(http_client.ACCEPTED, res_dict.status_int)
|
||||
self.assertEqual('deleting', group.status)
|
||||
|
||||
def test_delete_group_available_no_delete_volumes(self):
|
||||
|
@ -457,7 +458,7 @@ class GroupsAPITestCase(test.TestCase):
|
|||
|
||||
group = objects.Group.get_by_id(
|
||||
self.ctxt, self.group1.id)
|
||||
self.assertEqual(202, res_dict.status_int)
|
||||
self.assertEqual(http_client.ACCEPTED, res_dict.status_int)
|
||||
self.assertEqual(fields.GroupStatus.DELETING,
|
||||
group.status)
|
||||
|
||||
|
@ -492,7 +493,7 @@ class GroupsAPITestCase(test.TestCase):
|
|||
|
||||
group = objects.Group.get_by_id(
|
||||
self.ctxt, self.group1.id)
|
||||
self.assertEqual(202, res_dict.status_int)
|
||||
self.assertEqual(http_client.ACCEPTED, res_dict.status_int)
|
||||
self.assertEqual('deleting', group.status)
|
||||
|
||||
def test_delete_group_no_host(self):
|
||||
|
@ -507,7 +508,7 @@ class GroupsAPITestCase(test.TestCase):
|
|||
res_dict = self.controller.delete_group(
|
||||
req, self.group1.id, body)
|
||||
|
||||
self.assertEqual(202, res_dict.status_int)
|
||||
self.assertEqual(http_client.ACCEPTED, res_dict.status_int)
|
||||
group = objects.Group.get_by_id(
|
||||
context.get_admin_context(read_deleted='yes'),
|
||||
self.group1.id)
|
||||
|
@ -556,7 +557,7 @@ class GroupsAPITestCase(test.TestCase):
|
|||
ex = self.assertRaises(exception.GroupLimitExceeded,
|
||||
self.controller.create,
|
||||
req, body)
|
||||
self.assertEqual(413, ex.code)
|
||||
self.assertEqual(http_client.REQUEST_ENTITY_TOO_LARGE, ex.code)
|
||||
|
||||
def test_delete_group_with_invalid_body(self):
|
||||
self.group1.status = fields.GroupStatus.AVAILABLE
|
||||
|
@ -604,7 +605,7 @@ class GroupsAPITestCase(test.TestCase):
|
|||
|
||||
group = objects.Group.get_by_id(
|
||||
self.ctxt, self.group1.id)
|
||||
self.assertEqual(202, res_dict.status_int)
|
||||
self.assertEqual(http_client.ACCEPTED, res_dict.status_int)
|
||||
self.assertEqual('deleting', group.status)
|
||||
|
||||
vol.destroy()
|
||||
|
@ -654,7 +655,7 @@ class GroupsAPITestCase(test.TestCase):
|
|||
|
||||
group = objects.Group.get_by_id(
|
||||
self.ctxt, self.group1.id)
|
||||
self.assertEqual(202, res_dict.status_int)
|
||||
self.assertEqual(http_client.ACCEPTED, res_dict.status_int)
|
||||
self.assertEqual('deleting', group.status)
|
||||
|
||||
vol.destroy()
|
||||
|
@ -743,7 +744,7 @@ class GroupsAPITestCase(test.TestCase):
|
|||
|
||||
group = objects.Group.get_by_id(
|
||||
self.ctxt, self.group1.id)
|
||||
self.assertEqual(202, res_dict.status_int)
|
||||
self.assertEqual(http_client.ACCEPTED, res_dict.status_int)
|
||||
self.assertTrue(mock_validate.called)
|
||||
self.assertEqual(fields.GroupStatus.UPDATING,
|
||||
group.status)
|
||||
|
@ -915,7 +916,7 @@ class GroupsAPITestCase(test.TestCase):
|
|||
self.group2.id, body)
|
||||
|
||||
group = objects.Group.get_by_id(self.ctxt, self.group2.id)
|
||||
self.assertEqual(202, response.status_int)
|
||||
self.assertEqual(http_client.ACCEPTED, response.status_int)
|
||||
self.assertEqual(fields.GroupStatus.AVAILABLE, group.status)
|
||||
|
||||
@mock.patch(
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from six.moves import http_client
|
||||
|
||||
from cinder.api import extensions
|
||||
from cinder.api.v3 import messages
|
||||
from cinder import context
|
||||
|
@ -103,7 +105,7 @@ class MessageApiTest(test.TestCase):
|
|||
|
||||
resp = self.controller.delete(req, fakes.FAKE_UUID)
|
||||
|
||||
self.assertEqual(204, resp.status_int)
|
||||
self.assertEqual(http_client.NO_CONTENT, resp.status_int)
|
||||
self.assertTrue(message_api.API.delete.called)
|
||||
|
||||
def test_delete_not_found(self):
|
||||
|
|
|
@ -16,6 +16,7 @@ import ddt
|
|||
import mock
|
||||
from oslo_config import cfg
|
||||
from oslo_serialization import jsonutils
|
||||
from six.moves import http_client
|
||||
from six.moves.urllib.parse import urlencode
|
||||
import webob
|
||||
|
||||
|
@ -79,12 +80,12 @@ class SnapshotManageTest(test.TestCase):
|
|||
|
||||
body = {'snapshot': {'volume_id': fake.VOLUME_ID, 'ref': 'fake_ref'}}
|
||||
res = self._get_resp_post(body)
|
||||
self.assertEqual(202, res.status_int, res)
|
||||
self.assertEqual(http_client.ACCEPTED, res.status_int, res)
|
||||
|
||||
def test_manage_snapshot_previous_version(self):
|
||||
body = {'snapshot': {'volume_id': fake.VOLUME_ID, 'ref': 'fake_ref'}}
|
||||
res = self._get_resp_post(body, version="3.7")
|
||||
self.assertEqual(404, res.status_int, res)
|
||||
self.assertEqual(http_client.NOT_FOUND, res.status_int, res)
|
||||
|
||||
def _get_resp_get(self, host, detailed, paging, version="3.8", **kwargs):
|
||||
"""Helper to execute a GET os-snapshot-manage API call."""
|
||||
|
@ -116,11 +117,11 @@ class SnapshotManageTest(test.TestCase):
|
|||
than copying all the tests.
|
||||
"""
|
||||
res = self._get_resp_get('fakehost', False, False)
|
||||
self.assertEqual(200, res.status_int)
|
||||
self.assertEqual(http_client.OK, res.status_int)
|
||||
|
||||
def test_get_manageable_snapshots_previous_version(self):
|
||||
res = self._get_resp_get('fakehost', False, False, version="3.7")
|
||||
self.assertEqual(404, res.status_int)
|
||||
self.assertEqual(http_client.NOT_FOUND, res.status_int)
|
||||
|
||||
@mock.patch('cinder.volume.api.API.get_manageable_snapshots',
|
||||
wraps=test_contrib.api_get_manageable_snapshots)
|
||||
|
@ -132,11 +133,11 @@ class SnapshotManageTest(test.TestCase):
|
|||
than copying all the tests.
|
||||
"""
|
||||
res = self._get_resp_get('fakehost', True, True)
|
||||
self.assertEqual(200, res.status_int)
|
||||
self.assertEqual(http_client.OK, res.status_int)
|
||||
|
||||
def test_get_manageable_snapshots_detail_previous_version(self):
|
||||
res = self._get_resp_get('fakehost', True, True, version="3.7")
|
||||
self.assertEqual(404, res.status_int)
|
||||
self.assertEqual(http_client.NOT_FOUND, res.status_int)
|
||||
|
||||
@ddt.data((True, True, 'detail_list'), (True, False, 'summary_list'),
|
||||
(False, True, 'detail_list'), (False, False, 'summary_list'))
|
||||
|
@ -170,7 +171,7 @@ class SnapshotManageTest(test.TestCase):
|
|||
res = self._get_resp_get(host, is_detail, False, version=version,
|
||||
**kwargs)
|
||||
|
||||
self.assertEqual(200, res.status_int)
|
||||
self.assertEqual(http_client.OK, res.status_int)
|
||||
get_cctxt_mock.assert_called_once_with(service.service_topic_queue,
|
||||
version=('3.10', '3.0'))
|
||||
get_cctxt_mock.return_value.call.assert_called_once_with(
|
||||
|
@ -185,9 +186,9 @@ class SnapshotManageTest(test.TestCase):
|
|||
@ddt.data('3.8', '3.17')
|
||||
def test_get_manageable_missing_host(self, version):
|
||||
res = self._get_resp_get(None, True, False, version=version)
|
||||
self.assertEqual(400, res.status_int)
|
||||
self.assertEqual(http_client.BAD_REQUEST, res.status_int)
|
||||
|
||||
def test_get_manageable_both_host_cluster(self):
|
||||
res = self._get_resp_get('host', True, False, version='3.17',
|
||||
cluster='cluster')
|
||||
self.assertEqual(400, res.status_int)
|
||||
self.assertEqual(http_client.BAD_REQUEST, res.status_int)
|
||||
|
|
|
@ -16,6 +16,7 @@ import ddt
|
|||
import mock
|
||||
from oslo_config import cfg
|
||||
from oslo_serialization import jsonutils
|
||||
from six.moves import http_client
|
||||
from six.moves.urllib.parse import urlencode
|
||||
import webob
|
||||
|
||||
|
@ -80,12 +81,12 @@ class VolumeManageTest(test.TestCase):
|
|||
"""
|
||||
body = {'volume': {'host': 'host_ok', 'ref': 'fake_ref'}}
|
||||
res = self._get_resp_post(body)
|
||||
self.assertEqual(202, res.status_int, res)
|
||||
self.assertEqual(http_client.ACCEPTED, res.status_int, res)
|
||||
|
||||
def test_manage_volume_previous_version(self):
|
||||
body = {'volume': {'host': 'host_ok', 'ref': 'fake_ref'}}
|
||||
res = self._get_resp_post(body)
|
||||
self.assertEqual(400, res.status_int, res)
|
||||
self.assertEqual(http_client.BAD_REQUEST, res.status_int, res)
|
||||
|
||||
def _get_resp_get(self, host, detailed, paging, version="3.8", **kwargs):
|
||||
"""Helper to execute a GET os-volume-manage API call."""
|
||||
|
@ -118,11 +119,11 @@ class VolumeManageTest(test.TestCase):
|
|||
than copying all the tests.
|
||||
"""
|
||||
res = self._get_resp_get('fakehost', False, True)
|
||||
self.assertEqual(200, res.status_int)
|
||||
self.assertEqual(http_client.OK, res.status_int)
|
||||
|
||||
def test_get_manageable_volumes_previous_version(self):
|
||||
res = self._get_resp_get('fakehost', False, True, version="3.7")
|
||||
self.assertEqual(404, res.status_int)
|
||||
self.assertEqual(http_client.NOT_FOUND, res.status_int)
|
||||
|
||||
@mock.patch('cinder.volume.api.API.get_manageable_volumes',
|
||||
wraps=test_contrib.api_get_manageable_volumes)
|
||||
|
@ -134,11 +135,11 @@ class VolumeManageTest(test.TestCase):
|
|||
than copying all the tests.
|
||||
"""
|
||||
res = self._get_resp_get('fakehost', True, False)
|
||||
self.assertEqual(200, res.status_int)
|
||||
self.assertEqual(http_client.OK, res.status_int)
|
||||
|
||||
def test_get_manageable_volumes_detail_previous_version(self):
|
||||
res = self._get_resp_get('fakehost', True, False, version="3.7")
|
||||
self.assertEqual(404, res.status_int)
|
||||
self.assertEqual(http_client.NOT_FOUND, res.status_int)
|
||||
|
||||
@ddt.data((True, True, 'detail_list'), (True, False, 'summary_list'),
|
||||
(False, True, 'detail_list'), (False, False, 'summary_list'))
|
||||
|
@ -171,7 +172,7 @@ class VolumeManageTest(test.TestCase):
|
|||
res = self._get_resp_get(host, is_detail, False, version=version,
|
||||
**kwargs)
|
||||
|
||||
self.assertEqual(200, res.status_int)
|
||||
self.assertEqual(http_client.OK, res.status_int)
|
||||
get_cctxt_mock.assert_called_once_with(service.service_topic_queue,
|
||||
version=('3.10', '3.0'))
|
||||
get_cctxt_mock.return_value.call.assert_called_once_with(
|
||||
|
@ -187,9 +188,9 @@ class VolumeManageTest(test.TestCase):
|
|||
@ddt.data('3.8', '3.17')
|
||||
def test_get_manageable_missing_host(self, version):
|
||||
res = self._get_resp_get(None, True, False, version=version)
|
||||
self.assertEqual(400, res.status_int)
|
||||
self.assertEqual(http_client.BAD_REQUEST, res.status_int)
|
||||
|
||||
def test_get_manageable_both_host_cluster(self):
|
||||
res = self._get_resp_get('host', True, False, version='3.17',
|
||||
cluster='cluster')
|
||||
self.assertEqual(400, res.status_int)
|
||||
self.assertEqual(http_client.BAD_REQUEST, res.status_int)
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
import ddt
|
||||
import mock
|
||||
from oslo_serialization import jsonutils
|
||||
from six.moves import http_client
|
||||
import webob
|
||||
|
||||
from cinder.api.v3 import router as router_v3
|
||||
|
@ -74,7 +75,7 @@ class WorkersTestCase(test.TestCase):
|
|||
@mock.patch('cinder.scheduler.rpcapi.SchedulerAPI.work_cleanup')
|
||||
def test_cleanup_old_api_version(self, rpc_mock):
|
||||
res = self._get_resp_post({}, '3.19')
|
||||
self.assertEqual(404, res.status_code)
|
||||
self.assertEqual(http_client.NOT_FOUND, res.status_code)
|
||||
rpc_mock.assert_not_called()
|
||||
|
||||
@mock.patch('cinder.scheduler.rpcapi.SchedulerAPI.work_cleanup')
|
||||
|
@ -85,7 +86,7 @@ class WorkersTestCase(test.TestCase):
|
|||
read_deleted='no',
|
||||
overwrite=False)
|
||||
res = self._get_resp_post({}, ctxt=ctxt)
|
||||
self.assertEqual(403, res.status_code)
|
||||
self.assertEqual(http_client.FORBIDDEN, res.status_code)
|
||||
rpc_mock.assert_not_called()
|
||||
|
||||
@ddt.data({'fake_key': 'value'}, {'binary': 'nova-scheduler'},
|
||||
|
@ -94,7 +95,7 @@ class WorkersTestCase(test.TestCase):
|
|||
@mock.patch('cinder.scheduler.rpcapi.SchedulerAPI.work_cleanup')
|
||||
def test_cleanup_wrong_param(self, body, rpc_mock):
|
||||
res = self._get_resp_post(body)
|
||||
self.assertEqual(400, res.status_code)
|
||||
self.assertEqual(http_client.BAD_REQUEST, res.status_code)
|
||||
if 'disabled' in body or 'is_up' in body:
|
||||
expected = 'is not a boolean'
|
||||
else:
|
||||
|
@ -119,7 +120,7 @@ class WorkersTestCase(test.TestCase):
|
|||
return_value=SERVICES)
|
||||
def test_cleanup_params(self, body, rpc_mock):
|
||||
res = self._get_resp_post(body)
|
||||
self.assertEqual(202, res.status_code)
|
||||
self.assertEqual(http_client.ACCEPTED, res.status_code)
|
||||
rpc_mock.assert_called_once_with(self.context, mock.ANY)
|
||||
cleanup_request = rpc_mock.call_args[0][1]
|
||||
for key, value in body.items():
|
||||
|
@ -134,7 +135,7 @@ class WorkersTestCase(test.TestCase):
|
|||
return_value=SERVICES)
|
||||
def test_cleanup_missing_location_ok(self, rpc_mock, worker_mock):
|
||||
res = self._get_resp_post({'resource_id': fake.VOLUME_ID})
|
||||
self.assertEqual(202, res.status_code)
|
||||
self.assertEqual(http_client.ACCEPTED, res.status_code)
|
||||
rpc_mock.assert_called_once_with(self.context, mock.ANY)
|
||||
cleanup_request = rpc_mock.call_args[0][1]
|
||||
self.assertEqual(fake.VOLUME_ID, cleanup_request.resource_id)
|
||||
|
@ -145,7 +146,7 @@ class WorkersTestCase(test.TestCase):
|
|||
@mock.patch('cinder.scheduler.rpcapi.SchedulerAPI.work_cleanup')
|
||||
def test_cleanup_missing_location_fail_none(self, rpc_mock):
|
||||
res = self._get_resp_post({'resource_id': fake.VOLUME_ID})
|
||||
self.assertEqual(400, res.status_code)
|
||||
self.assertEqual(http_client.BAD_REQUEST, res.status_code)
|
||||
self.assertIn('Invalid input', res.json['badRequest']['message'])
|
||||
rpc_mock.assert_not_called()
|
||||
|
||||
|
@ -153,6 +154,6 @@ class WorkersTestCase(test.TestCase):
|
|||
return_value=[1, 2])
|
||||
def test_cleanup_missing_location_fail_multiple(self, rpc_mock):
|
||||
res = self._get_resp_post({'resource_id': fake.VOLUME_ID})
|
||||
self.assertEqual(400, res.status_code)
|
||||
self.assertEqual(http_client.BAD_REQUEST, res.status_code)
|
||||
self.assertIn('Invalid input', res.json['badRequest']['message'])
|
||||
rpc_mock.assert_not_called()
|
||||
|
|
Loading…
Reference in New Issue