From d10218ff29a99bd706d32c7a514aa7c2b3f642e1 Mon Sep 17 00:00:00 2001 From: Kannan Manickam Date: Sun, 14 Apr 2013 00:45:14 -0700 Subject: [PATCH] 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 --- keystoneclient/exceptions.py | 1 + tests/v2_0/test_tenants.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/keystoneclient/exceptions.py b/keystoneclient/exceptions.py index 86667d970..4b33ae0a9 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 246a65ff7..ed03c9e0b 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,