diff options
author | Kannan Manickam <arangamani.kannan@gmail.com> | 2013-04-14 00:45:14 -0700 |
---|---|---|
committer | Kannan Manickam <arangamani.kannan@gmail.com> | 2013-05-07 10:56:59 +0530 |
commit | d10218ff29a99bd706d32c7a514aa7c2b3f642e1 (patch) | |
tree | 0174b9a429e5ee05488c6fbe055ff92c0f17c8db | |
parent | 5c37d85944d9eed73ec6dd6254842108386bcc4f (diff) | |
download | python-keystoneclient-d10218ff29a99bd706d32c7a514aa7c2b3f642e1.tar.gz |
Added Conflict Exception to the exception code map
The Conflict Exception is added for HTTP error code 409.
However this exception is never raised as this class is not added to
the error_code map and always raises the ClientException whenever a
409 code is returned.
Fixes bug #1168826
Change-Id: I7045eae33533ff603f4aab61ea988264b46f0d09
-rw-r--r-- | keystoneclient/exceptions.py | 1 | ||||
-rw-r--r-- | tests/v2_0/test_tenants.py | 36 |
2 files changed, 37 insertions, 0 deletions
diff --git a/keystoneclient/exceptions.py b/keystoneclient/exceptions.py index 86667d9..4b33ae0 100644 --- a/keystoneclient/exceptions.py +++ b/keystoneclient/exceptions.py @@ -136,6 +136,7 @@ _code_map = dict((c.http_status, c) for c in [BadRequest, Forbidden, NotFound, MethodNotAllowed, + Conflict, OverLimit, HTTPNotImplemented, ServiceUnavailable]) diff --git a/tests/v2_0/test_tenants.py b/tests/v2_0/test_tenants.py index 246a65f..ed03c9e 100644 --- a/tests/v2_0/test_tenants.py +++ b/tests/v2_0/test_tenants.py @@ -4,6 +4,7 @@ import json import requests +from keystoneclient import exceptions from keystoneclient.v2_0 import tenants from tests import utils @@ -83,6 +84,41 @@ class TenantTests(utils.TestCase): self.assertEqual(tenant.name, "tenantX") self.assertEqual(tenant.description, "Like tenant 9, but better.") + def test_duplicate_create(self): + req_body = { + "tenant": { + "name": "tenantX", + "description": "The duplicate tenant.", + "enabled": True + }, + } + resp_body = { + "error": { + "message": "Conflict occurred attempting to store project.", + "code": 409, + "title": "Conflict", + } + } + resp = utils.TestResponse({ + "status_code": 409, + "text": json.dumps(resp_body), + }) + + kwargs = copy.copy(self.TEST_REQUEST_BASE) + kwargs['headers'] = self.TEST_POST_HEADERS + kwargs['data'] = json.dumps(req_body) + requests.request('POST', + urlparse.urljoin(self.TEST_URL, 'v2.0/tenants'), + **kwargs).AndReturn((resp)) + self.mox.ReplayAll() + + def create_duplicate_tenant(): + self.client.tenants.create(req_body['tenant']['name'], + req_body['tenant']['description'], + req_body['tenant']['enabled']) + + self.assertRaises(exceptions.Conflict, create_duplicate_tenant) + def test_delete(self): resp = utils.TestResponse({ "status_code": 204, |