exceptions: make sure resource type not found is checked before resource not found

The error string is too close so it's never matched otherwise.

Change-Id: I0ef12c1a9588b074b003df915a4b909822e0b230
This commit is contained in:
Julien Danjou 2017-02-03 16:31:38 +01:00
parent add8ec1d80
commit 7282f8436c
2 changed files with 12 additions and 2 deletions

View File

@ -171,8 +171,8 @@ _error_classes = [BadRequest, Unauthorized, Forbidden, NotFound,
MethodNotAllowed, NotAcceptable, Conflict, OverLimit,
RateLimit, NotImplemented]
_error_classes_enhanced = {
NotFound: [MetricNotFound, ResourceNotFound, ArchivePolicyRuleNotFound,
ArchivePolicyNotFound, ResourceTypeNotFound],
NotFound: [MetricNotFound, ResourceTypeNotFound, ResourceNotFound,
ArchivePolicyRuleNotFound, ArchivePolicyNotFound],
Conflict: [NamedMetricAlreadyExists, ResourceAlreadyExists,
ArchivePolicyAlreadyExists,
ArchivePolicyRuleAlreadyExists]

View File

@ -30,6 +30,16 @@ class ExceptionsTest(base.BaseTestCase):
exc = exceptions.from_response(r)
self.assertIsInstance(exc, exceptions.ArchivePolicyRuleNotFound)
def test_resource_type_before_resource(self):
r = models.Response()
r.status_code = 404
r.headers['Content-Type'] = "application/json"
r._content = json.dumps(
{"description": "Resource type foobar does not exist"}
).encode('utf-8')
exc = exceptions.from_response(r)
self.assertIsInstance(exc, exceptions.ResourceTypeNotFound)
def test_from_response_keystone_401(self):
r = models.Response()
r.status_code = 401