Skip to content

Commit

Permalink
Fixing pep8 errors in tests/*py
Browse files Browse the repository at this point in the history
Fixes bug 1022575

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

Change-Id: I2d7dec0a87f1ae9b5f828d7f321b65bf8c06a421
  • Loading branch information
derekhiggins committed Jul 9, 2012
1 parent 41f8843 commit 7cdae1b
Show file tree
Hide file tree
Showing 14 changed files with 129 additions and 99 deletions.
8 changes: 4 additions & 4 deletions tests/default_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{'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 = [
Expand All @@ -28,17 +28,17 @@
'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 = [
{
Expand Down
60 changes: 34 additions & 26 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def test_authenticate_bad_tenant(self):

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
Expand All @@ -57,9 +57,9 @@ def test_authenticate_no_tenant(self):

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
Expand All @@ -72,9 +72,9 @@ def test_authenticate_no_metadata(self):
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
Expand All @@ -99,7 +99,7 @@ def test_get_tenant_404(self):

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):
Expand Down Expand Up @@ -127,7 +127,7 @@ def test_get_user_404(self):

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
Expand All @@ -141,8 +141,8 @@ def test_get_user_by_name_404(self):

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):
Expand All @@ -159,7 +159,7 @@ def test_get_metadata_404(self):

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)

Expand All @@ -179,10 +179,14 @@ def test_create_duplicate_role_name_fails(self):
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'
Expand Down Expand Up @@ -538,9 +542,9 @@ def test_token_crud(self):

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,
Expand All @@ -559,7 +563,7 @@ def test_expired_token(self):
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
Expand All @@ -572,17 +576,21 @@ def test_null_expires_token(self):

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,
Expand All @@ -598,8 +606,8 @@ def test_delete_service_404(self):

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,
Expand Down
12 changes: 8 additions & 4 deletions tests/test_backend_ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ def test_delete_user_404(self):
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'
Expand Down
4 changes: 2 additions & 2 deletions tests/test_backend_templated.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
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):
Expand Down
58 changes: 37 additions & 21 deletions tests/test_content_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def setUp(self):
# 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."""
Expand Down Expand Up @@ -123,7 +123,8 @@ def assertResponseSuccessful(self, response):
>>> 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))

Expand All @@ -137,7 +138,9 @@ def assertResponseStatus(self, response, expected_status):
>>> 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))

Expand Down Expand Up @@ -225,7 +228,10 @@ def admin_request(self, port=None, **kwargs):

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'],
Expand Down Expand Up @@ -341,7 +347,10 @@ def test_admin_osksadm_extension(self):
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'],
Expand All @@ -356,12 +365,13 @@ def test_authenticate(self):

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)
Expand Down Expand Up @@ -390,7 +400,9 @@ def test_validate_token_head(self):
"""
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,
Expand All @@ -400,15 +412,17 @@ def test_endpoints(self):
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)
self.assertValidTokenCatalogResponse(r)

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)
Expand All @@ -418,7 +432,8 @@ def test_get_user_roles(self):
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)
Expand All @@ -436,7 +451,8 @@ def test_get_user_roles_with_tenant(self):

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)
Expand Down Expand Up @@ -567,11 +583,11 @@ def test_service_crud_requires_auth(self):
# 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',
Expand All @@ -598,8 +614,8 @@ def test_user_role_list_requires_auth(self):
"""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)
Expand Down

0 comments on commit 7cdae1b

Please sign in to comment.