auth-server: Change 400 to 409 when trying to add an existing user

This commit is contained in:
gholt 2010-09-15 20:37:06 +00:00 committed by Tarmac
commit a8b37dfecd
2 changed files with 8 additions and 3 deletions

View File

@ -23,8 +23,8 @@ from urlparse import urlparse
import sqlite3
from webob import Request, Response
from webob.exc import HTTPBadRequest, HTTPForbidden, HTTPNoContent, \
HTTPUnauthorized, HTTPServiceUnavailable, HTTPNotFound
from webob.exc import HTTPBadRequest, HTTPConflict, HTTPForbidden, \
HTTPNoContent, HTTPUnauthorized, HTTPServiceUnavailable, HTTPNotFound
from swift.common.bufferedhttp import http_connect_raw as http_connect
from swift.common.db import get_db_connection
@ -433,7 +433,7 @@ class AuthController(object):
storage_url = self.create_user(account_name, user_name, password,
create_account_admin, create_reseller_admin)
if storage_url == 'already exists':
return HTTPBadRequest(body=storage_url)
return HTTPConflict(body=storage_url)
if not storage_url:
return HTTPServiceUnavailable()
return HTTPNoContent(headers={'x-storage-url': storage_url})

View File

@ -656,6 +656,11 @@ class TestAuthServer(unittest.TestCase):
self.assertEquals(
self.controller.create_user('test', 'tester', 'testing'),
'already exists')
req = Request.blank('/account/test/tester',
headers={'X-Auth-User-Key': 'testing'})
resp = self.controller.handle_add_user(req)
self.assertEquals(resp.status_int, 409)
def test_create_2users_1account(self):
auth_server.http_connect = fake_http_connect(201)