Merge "Remove six.assertRaisesRegex usage"

This commit is contained in:
Zuul 2022-02-14 06:46:15 +00:00 committed by Gerrit Code Review
commit 4f4fc9b15d

View File

@ -26,7 +26,6 @@ import glance_store as store
from oslo_config import cfg from oslo_config import cfg
from oslo_serialization import jsonutils from oslo_serialization import jsonutils
from oslo_utils import fixture from oslo_utils import fixture
import six
import testtools import testtools
import webob import webob
import webob.exc import webob.exc
@ -2313,12 +2312,11 @@ class TestImagesController(base.IsolatedUnitTest):
'os_hash_value': MULTIHASH1}} 'os_hash_value': MULTIHASH1}}
changes = [{'op': 'add', 'path': ['locations', '-'], changes = [{'op': 'add', 'path': ['locations', '-'],
'value': new_location}] 'value': new_location}]
six.assertRaisesRegex(self, self.assertRaisesRegex(
webob.exc.HTTPConflict, webob.exc.HTTPConflict,
"may only be provided when image status " "may only be provided when image status is 'queued'",
"is 'queued'", self.controller.update,
self.controller.update, request, image_id, changes)
request, image_id, changes)
@mock.patch.object(glance.quota, '_calc_required_size') @mock.patch.object(glance.quota, '_calc_required_size')
@mock.patch.object(glance.location, '_check_image_location') @mock.patch.object(glance.location, '_check_image_location')
@ -2355,11 +2353,11 @@ class TestImagesController(base.IsolatedUnitTest):
'os_hash_value': MULTIHASH2}} 'os_hash_value': MULTIHASH2}}
changes = [{'op': 'replace', 'path': ['locations'], changes = [{'op': 'replace', 'path': ['locations'],
'value': [new_location]}] 'value': [new_location]}]
six.assertRaisesRegex(self, self.assertRaisesRegex(
webob.exc.HTTPConflict, webob.exc.HTTPConflict,
"already set with a different value", "already set with a different value",
self.controller.update, self.controller.update,
request, image_id, changes) request, image_id, changes)
@mock.patch.object(glance.quota, '_calc_required_size') @mock.patch.object(glance.quota, '_calc_required_size')
@mock.patch.object(glance.location, '_check_image_location') @mock.patch.object(glance.location, '_check_image_location')
@ -2527,57 +2525,55 @@ class TestImagesController(base.IsolatedUnitTest):
'os_hash_algo': 'sha512', 'os_hash_algo': 'sha512',
'os_hash_value': MULTIHASH1, 'os_hash_value': MULTIHASH1,
} }
six.assertRaisesRegex(self, self.assertRaisesRegex(
webob.exc.HTTPConflict, webob.exc.HTTPConflict,
'checksum .* is not a valid hexadecimal value', 'checksum .* is not a valid hexadecimal value',
self.controller.update, self.controller.update,
request, image_id, changes) request, image_id, changes)
changes[0]['value']['validation_data'] = { changes[0]['value']['validation_data'] = {
'checksum': '0123456789abcdef', 'checksum': '0123456789abcdef',
'os_hash_algo': 'sha512', 'os_hash_algo': 'sha512',
'os_hash_value': MULTIHASH1, 'os_hash_value': MULTIHASH1,
} }
six.assertRaisesRegex(self, self.assertRaisesRegex(
webob.exc.HTTPConflict, webob.exc.HTTPConflict,
'checksum .* is not the correct size', 'checksum .* is not the correct size',
self.controller.update, self.controller.update,
request, image_id, changes) request, image_id, changes)
changes[0]['value']['validation_data'] = { changes[0]['value']['validation_data'] = {
'checksum': CHKSUM, 'checksum': CHKSUM,
'os_hash_algo': 'sha256', 'os_hash_algo': 'sha256',
'os_hash_value': MULTIHASH1, 'os_hash_value': MULTIHASH1,
} }
six.assertRaisesRegex(self, self.assertRaisesRegex(
webob.exc.HTTPConflict, webob.exc.HTTPConflict,
'os_hash_algo must be sha512', 'os_hash_algo must be sha512',
self.controller.update, self.controller.update,
request, image_id, changes) request, image_id, changes)
changes[0]['value']['validation_data'] = { changes[0]['value']['validation_data'] = {
'checksum': CHKSUM, 'checksum': CHKSUM,
'os_hash_algo': 'sha512', 'os_hash_algo': 'sha512',
'os_hash_value': 'not a hex value', 'os_hash_value': 'not a hex value',
} }
six.assertRaisesRegex(self, self.assertRaisesRegex(
webob.exc.HTTPConflict, webob.exc.HTTPConflict,
'os_hash_value .* is not a valid hexadecimal ' 'os_hash_value .* is not a valid hexadecimal value',
'value', self.controller.update,
self.controller.update, request, image_id, changes)
request, image_id, changes)
changes[0]['value']['validation_data'] = { changes[0]['value']['validation_data'] = {
'checksum': CHKSUM, 'checksum': CHKSUM,
'os_hash_algo': 'sha512', 'os_hash_algo': 'sha512',
'os_hash_value': '0123456789abcdef', 'os_hash_value': '0123456789abcdef',
} }
six.assertRaisesRegex(self, self.assertRaisesRegex(
webob.exc.HTTPConflict, webob.exc.HTTPConflict,
'os_hash_value .* is not the correct size ' 'os_hash_value .* is not the correct size for sha512',
'for sha512', self.controller.update,
self.controller.update, request, image_id, changes)
request, image_id, changes)
@mock.patch.object(glance.quota, '_calc_required_size') @mock.patch.object(glance.quota, '_calc_required_size')
@mock.patch.object(glance.location, '_check_image_location') @mock.patch.object(glance.location, '_check_image_location')
@ -2658,11 +2654,11 @@ class TestImagesController(base.IsolatedUnitTest):
'os_hash_value': MULTIHASH2}} 'os_hash_value': MULTIHASH2}}
changes = [{'op': 'add', 'path': ['locations', '-'], changes = [{'op': 'add', 'path': ['locations', '-'],
'value': new_location}] 'value': new_location}]
six.assertRaisesRegex(self, self.assertRaisesRegex(
webob.exc.HTTPConflict, webob.exc.HTTPConflict,
"already set with a different value", "already set with a different value",
self.controller.update, self.controller.update,
request, image_id, changes) request, image_id, changes)
def _test_update_locations_status(self, image_status, update): def _test_update_locations_status(self, image_status, update):
self.config(show_multiple_locations=True) self.config(show_multiple_locations=True)
@ -4170,19 +4166,19 @@ class TestImagesDeserializer(test_utils.BaseTestCase):
'bogus_key': 'bogus_value', 'bogus_key': 'bogus_value',
} }
request.body = jsonutils.dump_as_bytes(changes) request.body = jsonutils.dump_as_bytes(changes)
six.assertRaisesRegex(self, self.assertRaisesRegex(
webob.exc.HTTPBadRequest, webob.exc.HTTPBadRequest,
'Additional properties are not allowed', 'Additional properties are not allowed',
self.deserializer.update, request) self.deserializer.update, request)
changes[0]['value']['validation_data'] = { changes[0]['value']['validation_data'] = {
'checksum': CHKSUM, 'checksum': CHKSUM,
} }
request.body = jsonutils.dump_as_bytes(changes) request.body = jsonutils.dump_as_bytes(changes)
six.assertRaisesRegex(self, self.assertRaisesRegex(
webob.exc.HTTPBadRequest, webob.exc.HTTPBadRequest,
'os_hash.* is a required property', 'os_hash.* is a required property',
self.deserializer.update, request) self.deserializer.update, request)
def test_update(self): def test_update(self):
request = self._get_fake_patch_request() request = self._get_fake_patch_request()