Remove six.assertRaisesRegex usage

Change-Id: I172d640b7155913ad20599fd99825e501ed82631
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
Stephen Finucane 2021-12-21 12:29:00 +00:00
parent 931809c037
commit f68e04f268
1 changed files with 48 additions and 52 deletions

View File

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