Fixing pep8 errors in tests/*py

Fixes bug 1022575

Making change to tests/*py to pass pep8 tests.
pep8 tests started failing following
39b20acc93 update pep8 to 1.3.3
04df79b64e include tests dir in pep8 tests

Change-Id: I2d7dec0a87f1ae9b5f828d7f321b65bf8c06a421
This commit is contained in:
Derek Higgins 2012-07-09 16:05:59 +01:00
parent 41f8843b82
commit 7cdae1bc02
14 changed files with 129 additions and 99 deletions

View File

@ -18,7 +18,7 @@ TENANTS = [
{'id': 'bar', 'name': 'BAR'},
{'id': 'baz', 'name': 'BAZ'},
{'id': 'tenent4add', 'name': 'tenant4add'},
]
]
# NOTE(ja): a role of keystone_admin and attribute "is_admin" is done in setUp
USERS = [
@ -28,17 +28,17 @@ USERS = [
'name': 'NO_META',
'password': 'no_meta2',
'tenants': ['baz']},
]
]
METADATA = [
{'user_id': 'foo', 'tenant_id': 'bar', 'extra': 'extra'},
{'user_id': 'two', 'tenant_id': 'baz', 'extra': 'extra'},
]
]
ROLES = [
{'id': 'keystone_admin', 'name': 'Keystone Admin'},
{'id': 'useless', 'name': 'Useless'},
]
]
SERVICES = [
{

View File

@ -45,8 +45,8 @@ class IdentityTests(object):
def test_authenticate_no_tenant(self):
user_ref, tenant_ref, metadata_ref = self.identity_api.authenticate(
user_id=self.user_foo['id'],
password=self.user_foo['password'])
user_id=self.user_foo['id'],
password=self.user_foo['password'])
# NOTE(termie): the password field is left in user_foo to make
# it easier to authenticate in tests, but should
# not be returned by the api
@ -57,9 +57,9 @@ class IdentityTests(object):
def test_authenticate(self):
user_ref, tenant_ref, metadata_ref = self.identity_api.authenticate(
user_id=self.user_foo['id'],
tenant_id=self.tenant_bar['id'],
password=self.user_foo['password'])
user_id=self.user_foo['id'],
tenant_id=self.tenant_bar['id'],
password=self.user_foo['password'])
# NOTE(termie): the password field is left in user_foo to make
# it easier to authenticate in tests, but should
# not be returned by the api
@ -72,9 +72,9 @@ class IdentityTests(object):
user = self.user_no_meta
tenant = self.tenant_baz
user_ref, tenant_ref, metadata_ref = self.identity_api.authenticate(
user_id=user['id'],
tenant_id=tenant['id'],
password=user['password'])
user_id=user['id'],
tenant_id=tenant['id'],
password=user['password'])
# NOTE(termie): the password field is left in user_foo to make
# it easier to authenticate in tests, but should
# not be returned by the api
@ -99,7 +99,7 @@ class IdentityTests(object):
def test_get_tenant_by_name(self):
tenant_ref = self.identity_api.get_tenant_by_name(
tenant_name=self.tenant_bar['name'])
tenant_name=self.tenant_bar['name'])
self.assertDictEqual(tenant_ref, self.tenant_bar)
def test_get_tenant_by_name_404(self):
@ -127,7 +127,7 @@ class IdentityTests(object):
def test_get_user_by_name(self):
user_ref = self.identity_api.get_user_by_name(
user_name=self.user_foo['name'])
user_name=self.user_foo['name'])
# NOTE(termie): the password field is left in user_foo to make
# it easier to authenticate in tests, but should
# not be returned by the api
@ -141,8 +141,8 @@ class IdentityTests(object):
def test_get_metadata(self):
metadata_ref = self.identity_api.get_metadata(
user_id=self.user_foo['id'],
tenant_id=self.tenant_bar['id'])
user_id=self.user_foo['id'],
tenant_id=self.tenant_bar['id'])
self.assertDictEqual(metadata_ref, self.metadata_foobar)
def test_get_metadata_404(self):
@ -159,7 +159,7 @@ class IdentityTests(object):
def test_get_role(self):
role_ref = self.identity_api.get_role(
role_id=self.role_keystone_admin['id'])
role_id=self.role_keystone_admin['id'])
role_ref_dict = dict((x, role_ref[x]) for x in role_ref)
self.assertDictEqual(role_ref_dict, self.role_keystone_admin)
@ -179,10 +179,14 @@ class IdentityTests(object):
role)
def test_rename_duplicate_role_name_fails(self):
role1 = {'id': 'fake1',
'name': 'fake1name'}
role2 = {'id': 'fake2',
'name': 'fake2name'}
role1 = {
'id': 'fake1',
'name': 'fake1name'
}
role2 = {
'id': 'fake2',
'name': 'fake2name'
}
self.identity_api.create_role('fake1', role1)
self.identity_api.create_role('fake2', role2)
role1['name'] = 'fake2name'
@ -538,9 +542,9 @@ class TokenTests(object):
self.token_api.delete_token(token_id)
self.assertRaises(exception.TokenNotFound,
self.token_api.get_token, token_id)
self.token_api.get_token, token_id)
self.assertRaises(exception.TokenNotFound,
self.token_api.delete_token, token_id)
self.token_api.delete_token, token_id)
def test_get_token_404(self):
self.assertRaises(exception.TokenNotFound,
@ -559,7 +563,7 @@ class TokenTests(object):
data_ref = self.token_api.create_token(token_id, data)
self.assertDictEqual(data_ref, data)
self.assertRaises(exception.TokenNotFound,
self.token_api.get_token, token_id)
self.token_api.get_token, token_id)
def test_null_expires_token(self):
token_id = uuid.uuid4().hex
@ -572,17 +576,21 @@ class TokenTests(object):
class CatalogTests(object):
def test_service_crud(self):
new_service = {'id': 'MY_SERVICE', 'type': 'myservice',
'name': 'My Service', 'description': 'My description'}
new_service = {
'id': 'MY_SERVICE',
'type': 'myservice',
'name': 'My Service',
'description': 'My description'
}
res = self.catalog_api.create_service(new_service['id'], new_service)
self.assertDictEqual(res, new_service)
service_id = new_service['id']
self.catalog_api.delete_service(service_id)
self.assertRaises(exception.ServiceNotFound,
self.catalog_man.delete_service, {}, service_id)
self.catalog_man.delete_service, {}, service_id)
self.assertRaises(exception.ServiceNotFound,
self.catalog_man.get_service, {}, service_id)
self.catalog_man.get_service, {}, service_id)
def test_get_service_404(self):
self.assertRaises(exception.ServiceNotFound,
@ -598,8 +606,8 @@ class CatalogTests(object):
def test_create_endpoint_404(self):
endpoint = {
'id': uuid.uuid4().hex,
'service_id': uuid.uuid4().hex,
'id': uuid.uuid4().hex,
'service_id': uuid.uuid4().hex,
}
self.assertRaises(exception.ServiceNotFound,
self.catalog_api.create_endpoint,

View File

@ -55,10 +55,14 @@ class LDAPIdentity(test.TestCase, test_backend.IdentityTests):
uuid.uuid4().hex)
def test_rename_duplicate_role_name_fails(self):
role1 = {'id': 'fake1',
'name': 'fake1name'}
role2 = {'id': 'fake2',
'name': 'fake2name'}
role1 = {
'id': 'fake1',
'name': 'fake1name'
}
role2 = {
'id': 'fake2',
'name': 'fake2name'
}
self.identity_api.create_role('fake1', role1)
self.identity_api.create_role('fake2', role2)
role1['name'] = 'fake2name'

View File

@ -26,8 +26,8 @@ import default_fixtures
import test_backend
DEFAULT_CATALOG_TEMPLATES = os.path.abspath(os.path.join(
os.path.dirname(__file__),
'default_catalog.templates'))
os.path.dirname(__file__),
'default_catalog.templates'))
class TestTemplatedCatalog(test.TestCase, test_backend.CatalogTests):

View File

@ -71,9 +71,9 @@ class RestfulTestCase(test.TestCase):
# TODO(termie): add an admin user to the fixtures and use that user
# override the fixtures, for now
self.metadata_foobar = self.identity_api.update_metadata(
self.user_foo['id'],
self.tenant_bar['id'],
dict(roles=['keystone_admin'], is_admin='1'))
self.user_foo['id'],
self.tenant_bar['id'],
dict(roles=['keystone_admin'], is_admin='1'))
def tearDown(self):
"""Kill running servers and release references to avoid leaks."""
@ -123,7 +123,8 @@ class RestfulTestCase(test.TestCase):
>>> self.assertResponseSuccessful(response, 203)
"""
self.assertTrue(response.status >= 200 and response.status <= 299,
self.assertTrue(
response.status >= 200 and response.status <= 299,
'Status code %d is outside of the expected range (2xx)\n\n%s' %
(response.status, response.body))
@ -137,7 +138,9 @@ class RestfulTestCase(test.TestCase):
>>> self.assertResponseStatus(response, 203)
"""
self.assertEqual(response.status, expected_status,
self.assertEqual(
response.status,
expected_status,
'Status code %s is not %s, as expected)\n\n%s' %
(response.status, expected_status, response.body))
@ -225,7 +228,10 @@ class RestfulTestCase(test.TestCase):
def get_scoped_token(self):
"""Convenience method so that we can test authenticated requests."""
r = self.public_request(method='POST', path='/v2.0/tokens', body={
r = self.public_request(
method='POST',
path='/v2.0/tokens',
body={
'auth': {
'passwordCredentials': {
'username': self.user_foo['name'],
@ -341,7 +347,10 @@ class CoreApiTests(object):
self.assertValidExtensionResponse(r)
def test_authenticate(self):
r = self.public_request(method='POST', path='/v2.0/tokens', body={
r = self.public_request(
method='POST',
path='/v2.0/tokens',
body={
'auth': {
'passwordCredentials': {
'username': self.user_foo['name'],
@ -356,12 +365,13 @@ class CoreApiTests(object):
def test_get_tenants_for_token(self):
r = self.public_request(path='/v2.0/tenants',
token=self.get_scoped_token())
token=self.get_scoped_token())
self.assertValidTenantListResponse(r)
def test_validate_token(self):
token = self.get_scoped_token()
r = self.admin_request(path='/v2.0/tokens/%(token_id)s' % {
r = self.admin_request(
path='/v2.0/tokens/%(token_id)s' % {
'token_id': token,
},
token=token)
@ -390,7 +400,9 @@ class CoreApiTests(object):
"""
token = self.get_scoped_token()
self.admin_request(method='HEAD', path='/v2.0/tokens/%(token_id)s' % {
self.admin_request(
method='HEAD',
path='/v2.0/tokens/%(token_id)s' % {
'token_id': token,
},
token=token,
@ -400,7 +412,8 @@ class CoreApiTests(object):
raise nose.exc.SkipTest('Blocked by bug 933555')
token = self.get_scoped_token()
r = self.admin_request(path='/v2.0/tokens/%(token_id)s/endpoints' % {
r = self.admin_request(
path='/v2.0/tokens/%(token_id)s/endpoints' % {
'token_id': token,
},
token=token)
@ -408,7 +421,8 @@ class CoreApiTests(object):
def test_get_tenant(self):
token = self.get_scoped_token()
r = self.admin_request(path='/v2.0/tenants/%(tenant_id)s' % {
r = self.admin_request(
path='/v2.0/tenants/%(tenant_id)s' % {
'tenant_id': self.tenant_bar['id'],
},
token=token)
@ -418,7 +432,8 @@ class CoreApiTests(object):
raise nose.exc.SkipTest('Blocked by bug 933565')
token = self.get_scoped_token()
r = self.admin_request(path='/v2.0/users/%(user_id)s/roles' % {
r = self.admin_request(
path='/v2.0/users/%(user_id)s/roles' % {
'user_id': self.user_foo['id'],
},
token=token)
@ -436,7 +451,8 @@ class CoreApiTests(object):
def test_get_user(self):
token = self.get_scoped_token()
r = self.admin_request(path='/v2.0/users/%(user_id)s' % {
r = self.admin_request(
path='/v2.0/users/%(user_id)s' % {
'user_id': self.user_foo['id'],
},
token=token)
@ -567,11 +583,11 @@ class JsonTestCase(RestfulTestCase, CoreApiTests):
# values here don't matter because we should 401 before they're checked
service_path = '/v2.0/OS-KSADM/services/%s' % uuid.uuid4().hex
service_body = {
'OS-KSADM:service': {
'name': uuid.uuid4().hex,
'type': uuid.uuid4().hex,
},
}
'OS-KSADM:service': {
'name': uuid.uuid4().hex,
'type': uuid.uuid4().hex,
},
}
r = self.admin_request(method='GET',
path='/v2.0/OS-KSADM/services',
@ -598,8 +614,8 @@ class JsonTestCase(RestfulTestCase, CoreApiTests):
"""User role list should 401 without an X-Auth-Token (bug 1006815)."""
# values here don't matter because we should 401 before they're checked
path = '/v2.0/tenants/%(tenant_id)s/users/%(user_id)s/roles' % {
'tenant_id': uuid.uuid4().hex,
'user_id': uuid.uuid4().hex,
'tenant_id': uuid.uuid4().hex,
'user_id': uuid.uuid4().hex,
}
r = self.admin_request(path=path, expected_status=401)

View File

@ -235,7 +235,7 @@ class KeystoneClientTests(object):
self.assertRaises(client_exceptions.NotFound, client.tenants.get,
tenant.id)
self.assertFalse([t for t in client.tenants.list()
if t.id == tenant.id])
if t.id == tenant.id])
def test_tenant_create_no_name(self):
from keystoneclient import exceptions as client_exceptions
@ -341,7 +341,7 @@ class KeystoneClientTests(object):
time.sleep(1.01)
reauthenticated_token = foo_client.tokens.authenticate(
token=foo_client.auth_token)
token=foo_client.auth_token)
self.assertEquals(orig_token['expires'],
reauthenticated_token.expires)
@ -370,9 +370,9 @@ class KeystoneClientTests(object):
self.assertFalse(user.enabled)
self.assertRaises(client_exceptions.Unauthorized,
self._client,
username=test_username,
password='password')
self._client,
username=test_username,
password='password')
client.users.update_enabled(user, True)
user = client.users.update_password(user=user, password='password2')
@ -868,16 +868,16 @@ class KcEssex3TestCase(CompatTestCase, KeystoneClientTests):
user_id=self.user_foo['id'],
role_id=self.role_useless['id'])
role_refs = client.roles.get_user_role_refs(
user_id=self.user_foo['id'])
user_id=self.user_foo['id'])
self.assert_(self.tenant_baz['id'] in [x.tenantId for x in role_refs])
# get the "role_refs" so we get the proper id, this is how the clients
# do it
roleref_refs = client.roles.get_user_role_refs(
user_id=self.user_foo['id'])
user_id=self.user_foo['id'])
for roleref_ref in roleref_refs:
if (roleref_ref.roleId == self.role_useless['id']
and roleref_ref.tenantId == self.tenant_baz['id']):
and roleref_ref.tenantId == self.tenant_baz['id']):
# use python's scope fall through to leave roleref_ref set
break
@ -886,7 +886,7 @@ class KcEssex3TestCase(CompatTestCase, KeystoneClientTests):
role_id=roleref_ref.id)
role_refs = client.roles.get_user_role_refs(
user_id=self.user_foo['id'])
user_id=self.user_foo['id'])
self.assert_(self.tenant_baz['id'] not in
[x.tenantId for x in role_refs])
@ -923,9 +923,9 @@ class KcEssex3TestCase(CompatTestCase, KeystoneClientTests):
self.assertFalse(user.enabled)
self.assertRaises(client_exceptions.Unauthorized,
self._client,
username=test_username,
password='password')
self._client,
username=test_username,
password='password')
client.users.update_enabled(user, True)
user = client.users.update_password(user=user, password='password2')

View File

@ -29,9 +29,9 @@ CONF = config.CONF
class KcMasterSqlTestCase(test_keystoneclient.KcMasterTestCase):
def config(self, config_files):
super(KcMasterSqlTestCase, self).config([
test.etcdir('keystone.conf.sample'),
test.testsdir('test_overrides.conf'),
test.testsdir('backend_sql.conf')])
test.etcdir('keystone.conf.sample'),
test.testsdir('test_overrides.conf'),
test.testsdir('backend_sql.conf')])
sql_util.setup_test_database()
def test_endpoint_crud(self):

View File

@ -145,9 +145,9 @@ class XmlBodyMiddlewareTest(test.TestCase):
def test_xml_replaced_by_json(self):
"""XML requests should be replaced by JSON requests."""
req = make_request(
body='<container><element attribute="value" /></container>',
content_type='application/xml',
method='POST')
body='<container><element attribute="value" /></container>',
content_type='application/xml',
method='POST')
middleware.XmlBodyMiddleware(None).process_request(req)
self.assertTrue(req.content_type, 'application/json')
self.assertTrue(jsonutils.loads(req.body))

View File

@ -138,7 +138,7 @@ class MigrateNovaAuth(test.TestCase):
user = users[old_user]
tenant = tenants[tenant_name]
roles = self.identity_api.get_roles_for_user_and_tenant(
user['id'], tenant['id'])
user['id'], tenant['id'])
actual = [self.identity_api.get_role(role_id)['name']
for role_id in roles]
expected = old_tenant_map.get(tenant_name, [])

View File

@ -28,11 +28,9 @@ from keystone.openstack.common import jsonutils
def denied_request(code):
error_table = {
'AccessDenied':
(401, 'Access denied'),
'InvalidURI':
(400, 'Could not parse the specified URI'),
}
'AccessDenied': (401, 'Access denied'),
'InvalidURI': (400, 'Could not parse the specified URI'),
}
xml = '<?xml version="1.0" encoding="UTF-8"?>\r\n<Error>\r\n ' \
'<Code>%s</Code>\r\n <Message>%s</Message>\r\n</Error>\r\n' \
% (code, error_table[code][1])

View File

@ -40,11 +40,11 @@ class XmlSerializerTestCase(test.TestCase):
# operations should be invertable
self.assertEqual(
serializer.from_xml(serializer.to_xml(d, xmlns)),
d)
serializer.from_xml(serializer.to_xml(d, xmlns)),
d)
self.assertEqualIgnoreWhitespace(
serializer.to_xml(serializer.from_xml(xml), xmlns),
xml)
serializer.to_xml(serializer.from_xml(xml), xmlns),
xml)
def test_none(self):
d = None

View File

@ -37,19 +37,19 @@ class SetupTest(unittest.TestCase):
with open(self.mailmap, 'w') as mm_fh:
mm_fh.write("Foo Bar <email@foo.com> Foo Bar <email@bar.com>\n")
self.assertEqual({'<email@bar.com>': '<email@foo.com>'},
parse_mailmap(self.mailmap))
parse_mailmap(self.mailmap))
def test_mailmap_with_firstname(self):
with open(self.mailmap, 'w') as mm_fh:
mm_fh.write("Foo <email@foo.com> Foo <email@bar.com>\n")
self.assertEqual({'<email@bar.com>': '<email@foo.com>'},
parse_mailmap(self.mailmap))
parse_mailmap(self.mailmap))
def test_mailmap_with_noname(self):
with open(self.mailmap, 'w') as mm_fh:
mm_fh.write("<email@foo.com> <email@bar.com>\n")
self.assertEqual({'<email@bar.com>': '<email@foo.com>'},
parse_mailmap(self.mailmap))
parse_mailmap(self.mailmap))
def tearDown(self):
if os.path.exists(self.mailmap):

View File

@ -43,9 +43,9 @@ class SSLTestCase(test.TestCase):
Make sure both public and admin API work with 1-way SSL.
"""
self.public_server = self.serveapp('keystone', name='main',
cert=CERT, key=KEY, ca=CA)
cert=CERT, key=KEY, ca=CA)
self.admin_server = self.serveapp('keystone', name='admin',
cert=CERT, key=KEY, ca=CA)
cert=CERT, key=KEY, ca=CA)
# Verify Admin
conn = httplib.HTTPSConnection('127.0.0.1', CONF.admin_port)
conn.request('GET', '/')
@ -62,10 +62,12 @@ class SSLTestCase(test.TestCase):
Make sure both public and admin API work with 2-way SSL. Requires
client certificate.
"""
self.public_server = self.serveapp('keystone', name='main',
cert=CERT, key=KEY, ca=CA, cert_required=True)
self.admin_server = self.serveapp('keystone', name='admin',
cert=CERT, key=KEY, ca=CA, cert_required=True)
self.public_server = self.serveapp(
'keystone', name='main', cert=CERT,
key=KEY, ca=CA, cert_required=True)
self.admin_server = self.serveapp(
'keystone', name='admin', cert=CERT,
key=KEY, ca=CA, cert_required=True)
# Verify Admin
conn = httplib.HTTPSConnection(
'127.0.0.1', CONF.admin_port, CLIENT, CLIENT)
@ -83,10 +85,12 @@ class SSLTestCase(test.TestCase):
"""
Expect to fail when client does not present proper certificate.
"""
self.public_server = self.serveapp('keystone', name='main',
cert=CERT, key=KEY, ca=CA, cert_required=True)
self.admin_server = self.serveapp('keystone', name='admin',
cert=CERT, key=KEY, ca=CA, cert_required=True)
self.public_server = self.serveapp(
'keystone', name='main', cert=CERT,
key=KEY, ca=CA, cert_required=True)
self.admin_server = self.serveapp(
'keystone', name='admin', cert=CERT,
key=KEY, ca=CA, cert_required=True)
# Verify Admin
conn = httplib.HTTPSConnection('127.0.0.1', CONF.admin_port)
try:

View File

@ -67,7 +67,7 @@ class SwiftAuth(unittest.TestCase):
return webob.Request.blank(path, headers=headers, **kwargs)
def _get_identity_headers(self, status='Confirmed', tenant_id='1',
tenant_name='acct', user='usr', role=''):
tenant_name='acct', user='usr', role=''):
return dict(X_IDENTITY_STATUS=status,
X_TENANT_ID=tenant_id,
X_TENANT_NAME=tenant_name,