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
This commit is contained in:
Kannan Manickam
2013-04-14 00:45:14 -07:00
parent 5c37d85944
commit d10218ff29
2 changed files with 37 additions and 0 deletions

View File

@@ -136,6 +136,7 @@ _code_map = dict((c.http_status, c) for c in [BadRequest,
Forbidden,
NotFound,
MethodNotAllowed,
Conflict,
OverLimit,
HTTPNotImplemented,
ServiceUnavailable])

View File

@@ -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,