Fixing all remaining pep8 errors

Change-Id: Iaf50bce4a6d458b37bc5e790b7d3ee56085c3e36
This commit is contained in:
Brian Waldon 2011-12-07 14:37:17 -05:00
parent f866c6ec3f
commit 596eb3c0a5
8 changed files with 162 additions and 113 deletions

View File

@ -357,7 +357,7 @@ def do_image_list(cs, args):
if hasattr(image_list[i], 'serverId'):
image_list[i].serverId = server_list[image_list[i].serverId] + \
' (' + str(image_list[i].serverId) + ')'
utils.print_list(image_list, ['ID', 'Name', 'serverId','Status'])
utils.print_list(image_list, ['ID', 'Name', 'serverId', 'Status'])
@utils.arg('server', metavar='<server>', help='Name or ID of server.')

View File

@ -7,89 +7,95 @@ from tests import utils
# Do not edit this structure. Instead, grab the latest from there.
SERVICE_CATALOG = {
"access":{
"token":{
"id":"ab48a9efdfedb23ty3494",
"expires":"2010-11-01T03:32:15-05:00",
"tenant":{
"access": {
"token": {
"id": "ab48a9efdfedb23ty3494",
"expires": "2010-11-01T03:32:15-05:00",
"tenant": {
"id": "345",
"name": "My Project"
}
},
"user":{
"id":"123",
"name":"jqsmith",
"roles":[{
"id":"234",
"name":"compute:admin"
"user": {
"id": "123",
"name": "jqsmith",
"roles": [
{
"id": "234",
"name": "compute:admin",
},
{
"id":"235",
"name":"object-store:admin",
"tenantId":"1"
"id": "235",
"name": "object-store:admin",
"tenantId": "1",
}
],
"roles_links":[]
"roles_links": [],
},
"serviceCatalog":[{
"name":"Cloud Servers",
"type":"compute",
"endpoints":[{
"tenantId":"1",
"publicURL":"https://compute.north.host/v1/1234",
"internalURL":"https://compute.north.host/v1/1234",
"region":"North",
"versionId":"1.0",
"versionInfo":"https://compute.north.host/v1.0/",
"versionList":"https://compute.north.host/"
"serviceCatalog": [
{
"name": "Cloud Servers",
"type": "compute",
"endpoints": [
{
"tenantId": "1",
"publicURL": "https://compute1.host/v1/1234",
"internalURL": "https://compute1.host/v1/1234",
"region": "North",
"versionId": "1.0",
"versionInfo": "https://compute1.host/v1.0/",
"versionList": "https://compute1.host/"
},
{
"tenantId":"2",
"publicURL":"https://compute.north.host/v1.1/3456",
"internalURL":"https://compute.north.host/v1.1/3456",
"region":"North",
"versionId":"1.1",
"versionInfo":"https://compute.north.host/v1.1/",
"versionList":"https://compute.north.host/"
}
"tenantId": "2",
"publicURL": "https://compute1.host/v1.1/3456",
"internalURL": "https://compute1.host/v1.1/3456",
"region": "North",
"versionId": "1.1",
"versionInfo": "https://compute1.host/v1.1/",
"versionList": "https://compute1.host/"
},
],
"endpoints_links":[]
"endpoints_links": [],
},
{
"name":"Cloud Files",
"type":"object-store",
"endpoints":[{
"tenantId":"11",
"publicURL":"https://compute.north.host/v1/blah-blah",
"internalURL":"https://compute.north.host/v1/blah-blah",
"region":"South",
"versionId":"1.0",
"versionInfo":"uri",
"versionList":"uri"
"name": "Cloud Files",
"type": "object-store",
"endpoints": [
{
"tenantId": "11",
"publicURL": "https://compute1.host/v1/blah-blah",
"internalURL": "https://compute1.host/v1/blah-blah",
"region": "South",
"versionId": "1.0",
"versionInfo": "uri",
"versionList": "uri"
},
{
"tenantId":"2",
"publicURL":"https://compute.north.host/v1.1/blah-blah",
"internalURL":"https://compute.north.host/v1.1/blah-blah",
"region":"South",
"versionId":"1.1",
"versionInfo":"https://compute.north.host/v1.1/",
"versionList":"https://compute.north.host/"
}
"tenantId": "2",
"publicURL": "https://compute1.host/v1.1/blah-blah",
"internalURL": "https://compute1.host/v1.1/blah-blah",
"region": "South",
"versionId": "1.1",
"versionInfo": "https://compute1.host/v1.1/",
"versionList": "https://compute1.host/"
},
],
"endpoints_links":[{
"rel":"next",
"href":"https://identity.north.host/v2.0/endpoints?marker=2"
}
]
}
"endpoints_links": [
{
"rel": "next",
"href": "https://identity1.host/v2.0/endpoints"
},
],
},
],
"serviceCatalog_links":[{
"rel":"next",
"href":"https://identity.host/v2.0/endpoints?session=2hfh8Ar&marker=2"
}
]
}
"serviceCatalog_links": [
{
"rel": "next",
"href": "https://identity.host/v2.0/endpoints?session=2hfh8Ar",
},
],
},
}
@ -98,11 +104,11 @@ class ServiceCatalogTest(utils.TestCase):
sc = service_catalog.ServiceCatalog(SERVICE_CATALOG)
self.assertEquals(sc.url_for(),
"https://compute.north.host/v1/1234")
"https://compute1.host/v1/1234")
self.assertEquals(sc.url_for('tenantId', '1'),
"https://compute.north.host/v1/1234")
"https://compute1.host/v1/1234")
self.assertEquals(sc.url_for('tenantId', '2'),
"https://compute.north.host/v1.1/3456")
"https://compute1.host/v1.1/3456")
self.assertRaises(exceptions.EndpointNotFound,
sc.url_for, "region", "South")

View File

@ -334,7 +334,6 @@ class ShellTest(utils.TestCase):
'weight_offset': 0.0, 'weight_scale': 1.0}}
)
def test_zone_delete(self):
self.run_command('zone-delete 1')
self.assert_called('DELETE', '/zones/1')

View File

@ -223,7 +223,7 @@ class FakeHTTPClient(base_client.HTTPClient):
return (204, None)
def post_servers_1234_metadata(self, **kw):
return (204, {'metadata': { 'test_key': 'test_value'}})
return (204, {'metadata': {'test_key': 'test_value'}})
#
# Server Addresses

View File

@ -10,7 +10,7 @@ from tests import utils
def to_http_response(resp_dict):
"""Handy converts dict {'status':status, 'body': body, 'headers':headers} to httplib response."""
"""Converts dict of response attributes to httplib response."""
resp = httplib2.Response(resp_dict)
for k, v in resp_dict['headers'].items():
resp[k] = v
@ -19,16 +19,29 @@ def to_http_response(resp_dict):
class AuthenticateAgainstKeystoneTests(utils.TestCase):
def test_authenticate_success(self):
cs = client.Client("username", "password", "project_id", "auth_url/v2.0")
resp = {"access":
{"token": {"expires": "12345", "id": "FAKE_ID"},
"serviceCatalog": [
{"adminURL": "http://localhost:8774/v1.1",
"type": "compute",
"endpoints" : [{
"region": "RegionOne",
"internalURL": "http://localhost:8774/v1.1",
"publicURL": "http://localhost:8774/v1.1/"},]},]}}
cs = client.Client("username", "password", "project_id",
"auth_url/v2.0")
resp = {
"access": {
"token": {
"expires": "12345",
"id": "FAKE_ID",
},
"serviceCatalog": [
{
"adminURL": "http://localhost:8774/v1.1",
"type": "compute",
"endpoints": [
{
"region": "RegionOne",
"internalURL": "http://localhost:8774/v1.1",
"publicURL": "http://localhost:8774/v1.1/",
},
],
},
],
},
}
auth_response = httplib2.Response({
"status": 200,
"body": json.dumps(resp),
@ -40,12 +53,19 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
@mock.patch.object(httplib2.Http, "request", mock_request)
def test_auth_call():
cs.client.authenticate()
headers = {'User-Agent': cs.client.USER_AGENT,
'Content-Type': 'application/json', }
body = {'auth': {
'passwordCredentials': {'username': cs.client.user,
'password': cs.client.password},
'tenantName': cs.client.projectid, }}
headers = {
'User-Agent': cs.client.USER_AGENT,
'Content-Type': 'application/json',
}
body = {
'auth': {
'passwordCredentials': {
'username': cs.client.user,
'password': cs.client.password,
},
'tenantName': cs.client.projectid,
},
}
token_url = urlparse.urljoin(cs.client.auth_url, "tokens")
mock_request.assert_called_with(token_url, "POST",
@ -55,12 +75,14 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
self.assertEqual(cs.client.management_url,
resp["access"]["serviceCatalog"][0]
['endpoints'][0]["publicURL"])
self.assertEqual(cs.client.auth_token, resp["access"]["token"]["id"])
token_id = resp["access"]["token"]["id"]
self.assertEqual(cs.client.auth_token, token_id)
test_auth_call()
def test_authenticate_failure(self):
cs = client.Client("username", "password", "project_id", "auth_url/v2.0")
cs = client.Client("username", "password", "project_id",
"auth_url/v2.0")
resp = {"unauthorized": {"message": "Unauthorized", "code": "401"}}
auth_response = httplib2.Response({
"status": 401,
@ -77,14 +99,29 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
test_auth_call()
def test_auth_redirect(self):
cs = client.Client("username", "password", "project_id", "auth_url/v1.0")
dict_correct_response = {"access": {"token": {"expires": "12345", "id": "FAKE_ID"},
"serviceCatalog": [{
"type": "compute",
"endpoints": [{"adminURL": "http://localhost:8774/v1.1",
"region": "RegionOne",
"internalURL": "http://localhost:8774/v1.1",
"publicURL": "http://localhost:8774/v1.1/"},]},]}}
cs = client.Client("username", "password", "project_id",
"auth_url/v1.0")
dict_correct_response = {
"access": {
"token": {
"expires": "12345",
"id": "FAKE_ID",
},
"serviceCatalog": [
{
"type": "compute",
"endpoints": [
{
"adminURL": "http://localhost:8774/v1.1",
"region": "RegionOne",
"internalURL": "http://localhost:8774/v1.1",
"publicURL": "http://localhost:8774/v1.1/",
},
],
},
],
},
}
correct_response = json.dumps(dict_correct_response)
dict_responses = [
{"headers": {'location':'http://127.0.0.1:5001'},
@ -102,7 +139,8 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
"body": correct_response}
]
responses = [ (to_http_response(resp), resp['body']) for resp in dict_responses ]
responses = [(to_http_response(resp), resp['body']) \
for resp in dict_responses]
def side_effect(*args, **kwargs):
return responses.pop(0)
@ -112,12 +150,19 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
@mock.patch.object(httplib2.Http, "request", mock_request)
def test_auth_call():
cs.client.authenticate()
headers = {'User-Agent': cs.client.USER_AGENT,
'Content-Type': 'application/json',}
body = {'auth': {
'passwordCredentials': {'username': cs.client.user,
'password': cs.client.password},
'tenantName': cs.client.projectid,}}
headers = {
'User-Agent': cs.client.USER_AGENT,
'Content-Type': 'application/json',
}
body = {
'auth': {
'passwordCredentials': {
'username': cs.client.user,
'password': cs.client.password,
},
'tenantName': cs.client.projectid,
},
}
token_url = urlparse.urljoin(cs.client.auth_url, "tokens")
mock_request.assert_called_with(token_url, "POST",
@ -128,7 +173,8 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
self.assertEqual(cs.client.management_url,
resp["access"]["serviceCatalog"][0]
['endpoints'][0]["publicURL"])
self.assertEqual(cs.client.auth_token, resp["access"]["token"]["id"])
token_id = resp["access"]["token"]["id"]
self.assertEqual(cs.client.auth_token, token_id)
test_auth_call()

View File

@ -27,9 +27,7 @@ class KeypairsTest(utils.TestCase):
cs.assert_called('POST', '/os-keypairs')
self.assertTrue(isinstance(kp, keypairs.Keypair))
def test_import_keypair(self):
kp = cs.keypairs.create("foo", "fake-public-key")
cs.assert_called('POST', '/os-keypairs')
self.assertTrue(isinstance(kp, keypairs.Keypair))

View File

@ -90,7 +90,7 @@ class ServersTest(utils.TestCase):
def test_set_server_meta(self):
s = cs.servers.set_meta(1234, {'test_key': 'test_value'})
reval = cs.assert_called('POST', '/servers/1234/metadata',
{'metadata': { 'test_key': 'test_value' }})
{'metadata': {'test_key': 'test_value'}})
def test_find(self):
s = cs.servers.find(name='sample-server')

View File

@ -109,7 +109,8 @@ class ShellTest(utils.TestCase):
@mock.patch('os.path.exists', mock_exists)
@mock.patch('__builtin__.open', mock_open)
def test_shell_call():
self.run_command('boot some-server --flavor 1 --image 1 --key_path')
cmd = 'boot some-server --flavor 1 --image 1 --key_path'
self.run_command(cmd)
self.assert_called_anytime(
'POST', '/servers',
{'server': {
@ -132,8 +133,8 @@ class ShellTest(utils.TestCase):
@mock.patch('os.path.exists', mock_exists)
def test_shell_call():
self.assertRaises(exceptions.CommandError, self.run_command,
'boot some-server --flavor 1 --image 1 --key_path')
cmd = 'boot some-server --flavor 1 --image 1 --key_path'
self.assertRaises(exceptions.CommandError, self.run_command, cmd)
test_shell_call()
@ -276,7 +277,6 @@ class ShellTest(utils.TestCase):
self.run_command('delete sample-server')
self.assert_called('DELETE', '/servers/1234')
def test_set_meta_set(self):
self.run_command('meta 1234 set key1=val1 key2=val2')
self.assert_called('POST', '/servers/1234/metadata',