Fixed pep8 errors in test directory.

Files test_swiftclient.py and utils.py had all pep8 errors
fixed.

Also added tests directory to tox.ini file, so that
pep8 would monitor tests directory by default.

Change-Id: Id60a2cd88bd814d1dcbeca951764c9d236500837
Fixes: bug #1158819
This commit is contained in:
jola-mirecka 2013-03-22 14:59:57 +00:00
parent 4f57f815b3
commit 8ea9c4aae8
3 changed files with 27 additions and 33 deletions

@ -47,7 +47,7 @@ class TestClientException(testtools.TestCase):
)
for value in test_kwargs:
kwargs = {
'http_%s' % value: value,
'http_%s' % value: value,
}
exc = c.ClientException('test', **kwargs)
self.assertTrue(value in str(exc))
@ -71,7 +71,6 @@ class TestJsonImport(testtools.TestCase):
reload(simplejson)
super(TestJsonImport, self).tearDown()
def test_any(self):
self.assertTrue(hasattr(c, 'json_loads'))
@ -119,7 +118,6 @@ class MockHttpTest(testtools.TestCase):
def setUp(self):
super(MockHttpTest, self).setUp()
def fake_http_connection(*args, **kwargs):
_orig_http_connection = c.http_connection
return_read = kwargs.get('return_read')
@ -210,7 +208,7 @@ class TestGetAuth(MockHttpTest):
self.assertEquals(token, None)
def test_auth_v2(self):
os_options={'tenant_name': 'asdf'}
os_options = {'tenant_name': 'asdf'}
c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(os_options)
url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf',
os_options=os_options,
@ -245,9 +243,9 @@ class TestGetAuth(MockHttpTest):
self.assertTrue(token)
def test_auth_v2_with_os_options(self):
os_options={'service_type': 'object-store',
'endpoint_type': 'internalURL',
'tenant_name': 'asdf'}
os_options = {'service_type': 'object-store',
'endpoint_type': 'internalURL',
'tenant_name': 'asdf'}
c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(os_options)
url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf',
os_options=os_options,
@ -259,13 +257,13 @@ class TestGetAuth(MockHttpTest):
tenant_option = {'tenant_name': 'foo'}
c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(tenant_option)
url, token = c.get_auth('http://www.test.com', 'foo:bar', 'asdf',
auth_version="2.0")
auth_version="2.0")
self.assertTrue(url.startswith("http"))
self.assertTrue(token)
def test_auth_v2_with_os_region_name(self):
os_options={'region_name': 'good-region',
'tenant_name': 'asdf'}
os_options = {'region_name': 'good-region',
'tenant_name': 'asdf'}
c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(os_options)
url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf',
os_options=os_options,
@ -274,19 +272,17 @@ class TestGetAuth(MockHttpTest):
self.assertTrue(token)
def test_auth_v2_no_endpoint(self):
os_options={'region_name': 'unknown_region',
'tenant_name': 'asdf'}
os_options = {'region_name': 'unknown_region',
'tenant_name': 'asdf'}
c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(
os_options,
c.ClientException)
os_options, c.ClientException)
self.assertRaises(c.ClientException, c.get_auth,
'http://www.tests.com', 'asdf', 'asdf',
os_options=os_options, auth_version='2.0')
def test_auth_v2_ks_exception(self):
c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(
{},
c.ClientException)
{}, c.ClientException)
self.assertRaises(c.ClientException, c.get_auth,
'http://www.tests.com', 'asdf', 'asdf',
os_options={},
@ -295,10 +291,9 @@ class TestGetAuth(MockHttpTest):
def test_auth_v2_cacert(self):
os_options = {'tenant_name': 'foo'}
c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(
os_options,
None)
os_options, None)
auth_url_secure = 'https://www.tests.com'
auth_url_secure = 'https://www.tests.com'
auth_url_insecure = 'https://www.tests.com/self-signed-certificate'
url, token = c.get_auth(auth_url_secure, 'asdf', 'asdf',
@ -324,10 +319,9 @@ class TestGetAuth(MockHttpTest):
def test_auth_v2_insecure(self):
os_options = {'tenant_name': 'foo'}
c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(
os_options,
None)
os_options, None)
auth_url_secure = 'https://www.tests.com'
auth_url_secure = 'https://www.tests.com'
auth_url_insecure = 'https://www.tests.com/invalid-certificate'
url, token = c.get_auth(auth_url_secure, 'asdf', 'asdf',
@ -394,8 +388,8 @@ class TestHeadContainer(MockHttpTest):
body = 'c' * 60
c.http_connection = self.fake_http_connection(500, body=body)
self.assertRaises(c.ClientException, c.head_container,
'http://www.test.com', 'asdf', 'asdf',
)
'http://www.test.com', 'asdf', 'asdf',
)
try:
value = c.head_container('http://www.test.com', 'asdf', 'asdf')
except c.ClientException as e:
@ -413,8 +407,8 @@ class TestPutContainer(MockHttpTest):
body = 'c' * 60
c.http_connection = self.fake_http_connection(500, body=body)
self.assertRaises(c.ClientException, c.put_container,
'http://www.test.com', 'asdf', 'asdf',
)
'http://www.test.com', 'asdf', 'asdf',
)
try:
value = c.put_container('http://www.test.com', 'asdf', 'asdf')
except c.ClientException as e:
@ -471,7 +465,7 @@ class TestPutObject(MockHttpTest):
self.assertTrue(isinstance(value, basestring))
# Test for RFC-2616 encoded symbols
self.assertTrue("a-b: .x:yz mn:fg:lp" in resp.buffer[0],
"[a-b: .x:yz mn:fg:lp] header is missing")
"[a-b: .x:yz mn:fg:lp] header is missing")
def test_chunk_warning(self):
conn = c.http_connection('http://www.test.com/')
@ -492,7 +486,6 @@ class TestPutObject(MockHttpTest):
self.assertEquals(len(w), 1)
self.assertTrue(issubclass(w[-1].category, UserWarning))
def test_server_error(self):
body = 'c' * 60
c.http_connection = self.fake_http_connection(500, body=body)
@ -526,7 +519,7 @@ class TestPostObject(MockHttpTest):
c.post_object(*args, headers=headers, http_conn=conn)
# Test for RFC-2616 encoded symbols
self.assertTrue("a-b: .x:yz mn:kl:qr" in resp.buffer[0],
"[a-b: .x:yz mn:kl:qr] header is missing")
"[a-b: .x:yz mn:kl:qr] header is missing")
def test_server_error(self):
body = 'c' * 60
@ -630,7 +623,7 @@ class TestConnection(MockHttpTest):
conn = c.Connection('http://www.test.com', 'asdf', 'asdf',
preauthurl='http://www.old.com',
preauthtoken='old',
)
)
self.assertEquals(conn.attempts, 0)
self.assertEquals(conn.url, 'http://www.old.com')
@ -736,7 +729,7 @@ class TestConnection(MockHttpTest):
exc = err
self.assertEquals(contents.seeks, [])
self.assertEquals(str(exc), "put_object('c', 'o', ...) failure "
"and no ability to reset contents for reupload.")
"and no ability to reset contents for reupload.")
finally:
c.http_connection = orig_conn

@ -16,6 +16,7 @@ from httplib import HTTPException
from eventlet import Timeout, sleep
def fake_get_keystoneclient_2_0(os_options, exc=None, **kwargs):
def fake_get_keystoneclient_2_0(auth_url,
user,
@ -78,7 +79,7 @@ def fake_http_connect(*code_iter, **kwargs):
'last-modified': self.timestamp,
'x-object-meta-test': 'testing',
'etag':
self.etag or '"68b329da9893e34099c7d8ad5cb9c940"',
self.etag or '"68b329da9893e34099c7d8ad5cb9c940"',
'x-works': 'yes',
'x-account-container-count': 12345}
if not self.timestamp:

@ -13,7 +13,7 @@ commands = python setup.py testr --testr-args="{posargs}"
[testenv:pep8]
deps = pep8
commands = pep8 --repeat --show-source --exclude=openstack swiftclient setup.py
commands = pep8 --repeat --show-source --exclude=openstack swiftclient setup.py tests
[testenv:venv]
commands = {posargs}