pep8 cleanups after the rebase

This commit is contained in:
Christopher MacGown 2011-08-07 10:59:11 -07:00 committed by termie
parent 39291fe0e8
commit 2d785404ed
2 changed files with 18 additions and 15 deletions

View File

@ -134,7 +134,7 @@ class HTTPClient(httplib2.Http):
self.version = part self.version = part
break break
if not self.version == "v2.0": #FIXME(chris): This should be better. if not self.version == "v2.0": # FIXME(chris): This should be better.
headers = {'X-Auth-User': self.user, headers = {'X-Auth-User': self.user,
'X-Auth-Key': self.apikey} 'X-Auth-Key': self.apikey}
if self.projectid: if self.projectid:
@ -158,7 +158,7 @@ class HTTPClient(httplib2.Http):
["nova"][0]["publicURL"] ["nova"][0]["publicURL"]
self.auth_token = body["auth"]["token"]["id"] self.auth_token = body["auth"]["token"]["id"]
#TODO(chris): Implement service_catalog #TODO(chris): Implement service_catalog
self.service_catalog = None self.service_catalog = None
def _munge_get_url(self, url): def _munge_get_url(self, url):

View File

@ -12,27 +12,30 @@ from tests import utils
class AuthenticateAgainstKeystoneTests(utils.TestCase): class AuthenticateAgainstKeystoneTests(utils.TestCase):
def test_authenticate_success(self): def test_authenticate_success(self):
cs = client.Client("username", "apikey", "project_id", "auth_url/v2.0") cs = client.Client("username", "apikey", "project_id", "auth_url/v2.0")
resp = {"auth": {"token": {"expires": "12345", "id": "FAKE_ID"}, resp = {"auth":
"serviceCatalog": { {"token": {"expires": "12345", "id": "FAKE_ID"},
"nova": [{"adminURL": "http://localhost:8774/v1.1", "serviceCatalog": {
"region": "RegionOne", "nova": [
"internalURL": "http://localhost:8774/v1.1", {"adminURL": "http://localhost:8774/v1.1",
"publicURL": "http://localhost:8774/v1.1/"}]}}} "region": "RegionOne",
"internalURL": "http://localhost:8774/v1.1",
"publicURL": "http://localhost:8774/v1.1/"}]}}}
auth_response = httplib2.Response({ auth_response = httplib2.Response({
"status": 204, "status": 204,
"body": json.dumps(resp), "body": json.dumps(resp),
}) })
mock_request = mock.Mock(return_value=(auth_response, json.dumps(resp))) mock_request = mock.Mock(return_value=(auth_response,
json.dumps(resp)))
@mock.patch.object(httplib2.Http, "request", mock_request) @mock.patch.object(httplib2.Http, "request", mock_request)
def test_auth_call(): def test_auth_call():
cs.client.authenticate() cs.client.authenticate()
headers = {'User-Agent': cs.client.USER_AGENT, headers = {'User-Agent': cs.client.USER_AGENT,
'Content-Type': 'application/json',} 'Content-Type': 'application/json', }
body = {'passwordCredentials': {'username': cs.client.user, body = {'passwordCredentials': {'username': cs.client.user,
'password': cs.client.apikey, 'password': cs.client.apikey,
'tenantId': cs.client.projectid,}} 'tenantId': cs.client.projectid, }}
token_url = urlparse.urljoin(cs.client.auth_url, "tokens") token_url = urlparse.urljoin(cs.client.auth_url, "tokens")
mock_request.assert_called_with(token_url, "POST", mock_request.assert_called_with(token_url, "POST",
@ -40,12 +43,11 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
body=json.dumps(body)) body=json.dumps(body))
self.assertEqual(cs.client.management_url, self.assertEqual(cs.client.management_url,
resp["auth"]["serviceCatalog"]["nova"][0]["publicURL"]) resp["auth"]["serviceCatalog"]["nova"][0]["publicURL"])
self.assertEqual(cs.client.auth_token, resp["auth"]["token"]["id"]) self.assertEqual(cs.client.auth_token, resp["auth"]["token"]["id"])
test_auth_call() test_auth_call()
def test_authenticate_failure(self): def test_authenticate_failure(self):
cs = client.Client("username", "apikey", "project_id", "auth_url/v2.0") cs = client.Client("username", "apikey", "project_id", "auth_url/v2.0")
resp = {"unauthorized": {"message": "Unauthorized", "code": "401"}} resp = {"unauthorized": {"message": "Unauthorized", "code": "401"}}
@ -54,7 +56,8 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
"body": json.dumps(resp), "body": json.dumps(resp),
}) })
mock_request = mock.Mock(return_value=(auth_response, json.dumps(resp))) mock_request = mock.Mock(return_value=(auth_response,
json.dumps(resp)))
@mock.patch.object(httplib2.Http, "request", mock_request) @mock.patch.object(httplib2.Http, "request", mock_request)
def test_auth_call(): def test_auth_call():