Permalink
Browse files

Merge pull request #2 from 4P/pep8cleanup

PEP8 cleanup and test fixes.
  • Loading branch information...
2 parents 0d228cf + 8aac166 commit 553947100377ffbb84d9dbbb457e65423365d39f @gabrielhurley gabrielhurley committed Nov 17, 2011
View
@@ -16,3 +16,4 @@ Lvov Maxim <mlvov@mirantis.com>
Matt Dietz <matt.dietz@rackspace.com>
Sandy Walsh <sandy@darksecretsoftware.com>
Gabriel Hurley <gabriel@strikeawe.com>
+Joe Heck <heckj@mac.com>
View
@@ -109,7 +109,9 @@ def request(self, url, method, **kwargs):
request_kwargs['headers']['Content-Type'] = 'application/json'
request_kwargs['body'] = json.dumps(kwargs['body'])
- resp, body = super(HTTPClient, self).request(url, method, **request_kwargs)
+ resp, body = super(HTTPClient, self).request(url,
+ method,
+ **request_kwargs)
self.http_log((url, method,), request_kwargs, resp, body)
View
@@ -21,7 +21,6 @@
import argparse
import httplib2
import os
-import prettytable
import sys
from keystoneclient import exceptions as exc
@@ -171,9 +170,11 @@ def main(self, argv):
"via --url or via"
"env[KEYSTONE_URL")
- self.cs = self.get_api_class(options.version) \
- (user, apikey, projectid, url,
- region_name=region_name)
+ self.cs = self.get_api_class(options.version)(user,
+ apikey,
+ projectid,
+ url,
+ region_name=region_name)
try:
self.cs.authenticate()
@@ -1,2 +1 @@
from keystoneclient.v2_0.client import Client
-
@@ -32,7 +32,9 @@ def get(self, id):
return self._get("/OS-KSADM/services/%s" % id, "OS-KSADM:service")
def create(self, name, service_type, description):
- body = {"OS-KSADM:service": {'name': name, 'type':service_type, 'description': description}}
+ body = {"OS-KSADM:service": {'name': name,
+ 'type': service_type,
+ 'description': description}}
return self._create("/OS-KSADM/services", body, "OS-KSADM:service")
def delete(self, id):
@@ -15,13 +15,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import getpass
-import os
-
-from keystoneclient import exceptions
-from keystoneclient import utils
from keystoneclient.v2_0 import client
-
CLIENT_CLASS = client.Client
-
@@ -55,11 +55,12 @@ def list(self):
"""
return self._list("/tenants", "tenants")
- def update(self, tenant_id, tenant_name=None, description=None, enabled=None):
+ def update(self, tenant_id, tenant_name=None, description=None,
+ enabled=None):
"""
update a tenant with a new name and description
"""
- body = {"tenant": {'id': tenant_id }}
+ body = {"tenant": {'id': tenant_id}}
if tenant_name is not None:
body['tenant']['name'] = tenant_name
if enabled is not None:
@@ -1,5 +1,6 @@
from keystoneclient import base
+
class Token(base.Resource):
def __repr__(self):
return "<Token %s>" % self._info
@@ -16,6 +17,7 @@ def expires(self):
def tenant(self):
return self._info['token'].get('tenant', None)
+
class TokenManager(base.ManagerWithFind):
resource_class = Token
View
@@ -2,7 +2,6 @@
import mock
from keystoneclient import client
-from keystoneclient import exceptions
from tests import utils
@@ -37,7 +36,8 @@ def test_get_call():
"X-Auth-Project-Id": "project_id",
"User-Agent": cl.USER_AGENT,
}
- mock_request.assert_called_with("http://127.0.0.1:5000/hi?fresh=1234",
+ mock_request.assert_called_with("http://127.0.0.1:5000/"
+ "hi?fresh=1234",
"GET", headers=headers)
# Automatic JSON parsing
self.assertEqual(body, {"hi": "there"})
@@ -60,4 +60,3 @@ def test_post_call():
headers=headers, body='[1, 2, 3]')
test_post_call()
-
@@ -7,87 +7,88 @@
# 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://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/"
},
{
- "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://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/"
}
],
- "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"
- },
- {
- "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/"
- }
+ "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"
+ },
+ {
+ "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/"
+ }
],
"endpoints_links":[{
- "rel":"next",
- "href":"https://identity.north.host/v2.0/endpoints?marker=2"
- }
+ "rel":"next",
+ "href":"https://identity.north.host/v2.0/endpoints?marker=2"
+ }
]
}
],
- "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&marker=2")
+ }
]
}
}
View
@@ -45,7 +45,8 @@ def setUp(self):
}
def test_authenticate_failure(self):
- self.TEST_REQUEST_BODY['auth']['passwordCredentials']['password'] = 'bad_key'
+ self.TEST_REQUEST_BODY['auth']['passwordCredentials']['password'] = \
+ 'bad_key'
self.TEST_REQUEST_HEADERS['X-Auth-Project-Id'] = '1'
resp = httplib2.Response({
"status": 401,
@@ -72,7 +73,6 @@ def test_authenticate_failure(self):
project_id=self.TEST_TENANT,
auth_url=self.TEST_URL)
-
def test_auth_redirect(self):
self.TEST_REQUEST_HEADERS['X-Auth-Project-Id'] = '1'
correct_response = json.dumps(self.TEST_RESPONSE_DICT)
@@ -154,7 +154,7 @@ def test_authenticate_success_password_unscoped(self):
auth_url=self.TEST_URL)
self.assertEqual(cs.auth_token,
self.TEST_RESPONSE_DICT["access"]["token"]["id"])
- self.assertFalse(cs.service_catalog.catalog.has_key('serviceCatalog'))
+ self.assertFalse('serviceCatalog' in cs.service_catalog.catalog)
def test_authenticate_success_token_scoped(self):
del self.TEST_REQUEST_BODY['auth']['passwordCredentials']
@@ -204,4 +204,4 @@ def test_authenticate_success_token_unscoped(self):
auth_url=self.TEST_URL)
self.assertEqual(cs.auth_token,
self.TEST_RESPONSE_DICT["access"]["token"]["id"])
- self.assertFalse(cs.service_catalog.catalog.has_key('serviceCatalog'))
+ self.assertFalse('serviceCatalog' in cs.service_catalog.catalog)
View
@@ -12,11 +12,11 @@ def setUp(self):
super(RoleTests, self).setUp()
self.TEST_REQUEST_HEADERS = {'X-Auth-Project-Id': '1',
'X-Auth-Token': 'aToken',
- 'User-Agent': 'python-keystoneclient',}
+ 'User-Agent': 'python-keystoneclient'}
self.TEST_POST_HEADERS = {'X-Auth-Project-Id': '1',
'Content-Type': 'application/json',
'X-Auth-Token': 'aToken',
- 'User-Agent': 'python-keystoneclient',}
+ 'User-Agent': 'python-keystoneclient'}
self.TEST_ROLES = {
"roles": {
"values": [
@@ -33,14 +33,15 @@ def setUp(self):
}
def test_create(self):
- req_body = {"role": {"name": "sysadmin",}}
- resp_body = {"role": {"name": "sysadmin", "id": 3,}}
+ req_body = {"role": {"name": "sysadmin"}}
+ resp_body = {"role": {"name": "sysadmin", "id": 3}}
resp = httplib2.Response({
"status": 200,
"body": json.dumps(resp_body),
})
- httplib2.Http.request(urlparse.urljoin(self.TEST_URL, 'v2.0/OS-KSADM/roles'),
+ httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
+ 'v2.0/OS-KSADM/roles'),
'POST',
body=json.dumps(req_body),
headers=self.TEST_POST_HEADERS) \
@@ -57,7 +58,8 @@ def test_delete(self):
"status": 200,
"body": ""
})
- httplib2.Http.request(urlparse.urljoin(self.TEST_URL, 'v2.0/OS-KSADM/roles/1'),
+ httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
+ 'v2.0/OS-KSADM/roles/1'),
'DELETE',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
@@ -68,9 +70,11 @@ def test_delete(self):
def test_get(self):
resp = httplib2.Response({
"status": 200,
- "body": json.dumps({'role':self.TEST_ROLES['roles']['values'][0]}),
+ "body": json.dumps({'role':
+ self.TEST_ROLES['roles']['values'][0]}),
})
- httplib2.Http.request(urlparse.urljoin(self.TEST_URL, 'v2.0/OS-KSADM/roles/1?fresh=1234'),
+ httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
+ 'v2.0/OS-KSADM/roles/1?fresh=1234'),
'GET',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
@@ -81,19 +85,18 @@ def test_get(self):
self.assertEqual(role.id, 1)
self.assertEqual(role.name, 'admin')
-
def test_list(self):
resp = httplib2.Response({
"status": 200,
"body": json.dumps(self.TEST_ROLES),
})
- httplib2.Http.request(urlparse.urljoin(self.TEST_URL, 'v2.0/OS-KSADM/roles?fresh=1234'),
+ httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
+ 'v2.0/OS-KSADM/roles?fresh=1234'),
'GET',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
role_list = self.client.roles.list()
[self.assertTrue(isinstance(r, roles.Role)) for r in role_list]
-
Oops, something went wrong.

0 comments on commit 5539471

Please sign in to comment.