Pep8 unit test modules w/ <= 10 violations (5 of 12)

Change-Id: I8e82c14ada52d44df5a31e08982ac79cd7e5c969
Signed-off-by: Peter Portante <peter.portante@redhat.com>
This commit is contained in:
Peter Portante 2013-08-31 23:13:15 -04:00
parent c067abd21e
commit be1cff4f1f
18 changed files with 152 additions and 106 deletions

View File

@ -185,9 +185,9 @@ class TestAccountQuota(unittest.TestCase):
app = account_quotas.AccountQuotaMiddleware(FakeApp(headers))
cache = FakeCache(None)
req = Request.blank('/v1/a/c', environ={
'REQUEST_METHOD': 'POST',
'swift.cache': cache,
'HTTP_X_REMOVE_ACCOUNT_META_QUOTA_BYTES': 'True'})
'REQUEST_METHOD': 'POST',
'swift.cache': cache,
'HTTP_X_REMOVE_ACCOUNT_META_QUOTA_BYTES': 'True'})
res = req.get_response(app)
self.assertEquals(res.status_int, 403)
@ -206,10 +206,10 @@ class TestAccountQuota(unittest.TestCase):
app = account_quotas.AccountQuotaMiddleware(FakeApp(headers))
cache = FakeCache(None)
req = Request.blank('/v1/a/c', environ={
'REQUEST_METHOD': 'POST',
'swift.cache': cache,
'HTTP_X_REMOVE_ACCOUNT_META_QUOTA_BYTES': 'True',
'reseller_request': True})
'REQUEST_METHOD': 'POST',
'swift.cache': cache,
'HTTP_X_REMOVE_ACCOUNT_META_QUOTA_BYTES': 'True',
'reseller_request': True})
res = req.get_response(app)
self.assertEquals(res.status_int, 200)

View File

@ -49,7 +49,7 @@ class TestACL(unittest.TestCase):
self.assertEquals(value, '.r:*')
value = acl.clean_acl('header', '.referrer:*')
self.assertEquals(value, '.r:*')
value = acl.clean_acl('header',
value = acl.clean_acl('header',
' .r : one , ,, .r:two , .r : - three ')
self.assertEquals(value, '.r:one,.r:two,.r:-three')
self.assertRaises(ValueError, acl.clean_acl, 'header', '.unknown:test')
@ -105,13 +105,17 @@ class TestACL(unittest.TestCase):
'http://user:pass@www.example.com:8080', ['.example.com']))
self.assert_(acl.referrer_allowed('http://www.example.com',
['.example.com']))
self.assert_(not acl.referrer_allowed('http://thief.example.com',
self.assert_(not acl.referrer_allowed(
'http://thief.example.com',
['.example.com', '-thief.example.com']))
self.assert_(not acl.referrer_allowed('http://thief.example.com',
self.assert_(not acl.referrer_allowed(
'http://thief.example.com',
['*', '-thief.example.com']))
self.assert_(acl.referrer_allowed('http://www.example.com',
self.assert_(acl.referrer_allowed(
'http://www.example.com',
['.other.com', 'www.example.com']))
self.assert_(acl.referrer_allowed('http://www.example.com',
self.assert_(acl.referrer_allowed(
'http://www.example.com',
['-.example.com', 'www.example.com']))
# This is considered a relative uri to the request uri, a mode not
# currently supported.

View File

@ -18,7 +18,7 @@ from nose import SkipTest
try:
# this test requires the dnspython package to be installed
import dns.resolver
import dns.resolver # noqa
except ImportError:
skip = True
else: # executed if the try has no errors
@ -128,7 +128,7 @@ class TestCNAMELookup(unittest.TestCase):
resp = self.app(req.environ, start_response)
self.assertEquals(resp,
['CNAME lookup failed to resolve to a valid domain'])
['CNAME lookup failed to resolve to a valid domain'])
def test_something_weird(self):
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'},
@ -140,7 +140,7 @@ class TestCNAMELookup(unittest.TestCase):
resp = self.app(req.environ, start_response)
self.assertEquals(resp,
['CNAME lookup failed to resolve to a valid domain'])
['CNAME lookup failed to resolve to a valid domain'])
def test_with_memcache(self):
def my_lookup(d):
@ -178,12 +178,12 @@ class TestCNAMELookup(unittest.TestCase):
resp = self.app(req.environ, start_response)
self.assertEquals(resp,
['CNAME lookup failed to resolve to a valid domain'])
['CNAME lookup failed to resolve to a valid domain'])
def test_cname_configured_with_empty_storage_domain(self):
app = cname_lookup.CNAMELookupMiddleware(FakeApp(),
{'storage_domain': '',
'lookup_depth': 2})
{'storage_domain': '',
'lookup_depth': 2})
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'},
headers={'Host': 'c.a.example.com'})

View File

@ -19,7 +19,9 @@ from swift.common.swob import Request
from swift.common.middleware import catch_errors
from swift.common.utils import get_logger
class FakeApp(object):
def __init__(self, error=False, body_iter=None):
self.error = error
self.body_iter = body_iter
@ -34,9 +36,11 @@ class FakeApp(object):
else:
return self.body_iter
def start_response(*args):
pass
class TestCatchErrors(unittest.TestCase):
def setUp(self):
@ -63,7 +67,7 @@ class TestCatchErrors(unittest.TestCase):
app = catch_errors.CatchErrorMiddleware(FakeApp(), {})
req = Request.blank('/v1/a/c/o')
app(req.environ, start_response)
self.assertEquals(len(self.logger.txn_id), 34) # 32 hex + 'tx'
self.assertEquals(len(self.logger.txn_id), 34) # 32 hex + 'tx'
def test_trans_id_header_fail(self):
self.assertEquals(self.logger.txn_id, None)
@ -93,5 +97,6 @@ class TestCatchErrors(unittest.TestCase):
app(req.environ, start_response)
self.assertTrue(self.logger.txn_id.endswith('-stuff'))
if __name__ == '__main__':
unittest.main()

View File

@ -466,7 +466,8 @@ class TestFormPost(unittest.TestCase):
'SERVER_NAME': '172.16.83.128',
'SERVER_PORT': '8080',
'SERVER_PROTOCOL': 'HTTP/1.0',
'swift.account/AUTH_test': self._fake_cache_env('AUTH_test', [key]),
'swift.account/AUTH_test': self._fake_cache_env(
'AUTH_test', [key]),
'wsgi.errors': wsgi_errors,
'wsgi.input': wsgi_input,
'wsgi.multiprocess': False,
@ -577,7 +578,8 @@ class TestFormPost(unittest.TestCase):
'SERVER_NAME': '172.16.83.128',
'SERVER_PORT': '8080',
'SERVER_PROTOCOL': 'HTTP/1.0',
'swift.account/AUTH_test': self._fake_cache_env('AUTH_test', [key]),
'swift.account/AUTH_test': self._fake_cache_env(
'AUTH_test', [key]),
'wsgi.errors': wsgi_errors,
'wsgi.input': wsgi_input,
'wsgi.multiprocess': False,
@ -691,7 +693,8 @@ class TestFormPost(unittest.TestCase):
'SERVER_NAME': '172.16.83.128',
'SERVER_PORT': '8080',
'SERVER_PROTOCOL': 'HTTP/1.0',
'swift.account/AUTH_test': self._fake_cache_env('AUTH_test', [key]),
'swift.account/AUTH_test': self._fake_cache_env(
'AUTH_test', [key]),
'wsgi.errors': wsgi_errors,
'wsgi.input': wsgi_input,
'wsgi.multiprocess': False,
@ -801,7 +804,8 @@ class TestFormPost(unittest.TestCase):
'SERVER_NAME': '172.16.83.128',
'SERVER_PORT': '8080',
'SERVER_PROTOCOL': 'HTTP/1.0',
'swift.account/AUTH_test': self._fake_cache_env('AUTH_test', [key]),
'swift.account/AUTH_test': self._fake_cache_env(
'AUTH_test', [key]),
'wsgi.errors': wsgi_errors,
'wsgi.input': wsgi_input,
'wsgi.multiprocess': False,

View File

@ -58,6 +58,7 @@ class SetConfigParser(object):
def start_response(*args):
pass
class TestCacheMiddleware(unittest.TestCase):
def setUp(self):
@ -80,7 +81,7 @@ class TestCacheMiddleware(unittest.TestCase):
finally:
memcache.ConfigParser = orig_parser
self.assertEquals(str(exc),
"read called with '/etc/swift/memcache.conf'")
"read called with '/etc/swift/memcache.conf'")
def test_conf_set_no_read(self):
orig_parser = memcache.ConfigParser
@ -88,8 +89,8 @@ class TestCacheMiddleware(unittest.TestCase):
exc = None
try:
memcache.MemcacheMiddleware(
FakeApp(), {'memcache_servers': '1.2.3.4:5',
'memcache_serialization_support': '2'})
FakeApp(), {'memcache_servers': '1.2.3.4:5',
'memcache_serialization_support': '2'})
except Exception, err:
exc = err
finally:
@ -123,9 +124,9 @@ class TestCacheMiddleware(unittest.TestCase):
memcache.ConfigParser = SetConfigParser
try:
app = memcache.MemcacheMiddleware(
FakeApp(),
{'memcache_servers': '6.7.8.9:10',
'serialization_format': '0'})
FakeApp(),
{'memcache_servers': '6.7.8.9:10',
'serialization_format': '0'})
finally:
memcache.ConfigParser = orig_parser
self.assertEquals(app.memcache_servers, '6.7.8.9:10')

View File

@ -53,38 +53,44 @@ class TestNameCheckMiddleware(unittest.TestCase):
def test_invalid_character(self):
for c in self.conf['forbidden_chars']:
path = '/V1.0/1234' + c + '5'
resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'}
).get_response(self.test_check)
self.assertEquals(resp.body,
("Object/Container name contains forbidden chars from %s"
% self.conf['forbidden_chars']))
resp = Request.blank(
path, environ={'REQUEST_METHOD': 'PUT'}).get_response(
self.test_check)
self.assertEquals(
resp.body,
("Object/Container name contains forbidden chars from %s"
% self.conf['forbidden_chars']))
self.assertEquals(resp.status_int, 400)
def test_invalid_length(self):
path = '/V1.0/' + 'c' * (MAX_LENGTH - 5)
resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'}
).get_response(self.test_check)
self.assertEquals(resp.body,
("Object/Container name longer than the allowed maximum %s"
% self.conf['maximum_length']))
self.assertEquals(
resp.body,
("Object/Container name longer than the allowed maximum %s"
% self.conf['maximum_length']))
self.assertEquals(resp.status_int, 400)
def test_invalid_regexp(self):
for s in ['/.', '/..', '/./foo', '/../foo']:
path = '/V1.0/' + s
resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'}
).get_response(self.test_check)
self.assertEquals(resp.body,
("Object/Container name contains a forbidden substring "
"from regular expression %s"
% self.conf['forbidden_regexp']))
resp = Request.blank(
path, environ={'REQUEST_METHOD': 'PUT'}).get_response(
self.test_check)
self.assertEquals(
resp.body,
("Object/Container name contains a forbidden substring "
"from regular expression %s"
% self.conf['forbidden_regexp']))
self.assertEquals(resp.status_int, 400)
def test_valid_regexp(self):
for s in ['/...', '/.\.', '/foo']:
path = '/V1.0/' + s
resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'}
).get_response(self.test_check)
resp = Request.blank(
path, environ={'REQUEST_METHOD': 'PUT'}).get_response(
self.test_check)
self.assertEquals(resp.body, 'OK')

View File

@ -98,7 +98,6 @@ class TestRingBuilder(unittest.TestCase):
r0 = rb0.get_ring()
self.assertTrue(rb0.get_ring() is r0)
rb0.rebalance() # NO SEED
rb1.rebalance(seed=10)
rb2.rebalance(seed=10)
@ -749,7 +748,8 @@ class TestRingBuilder(unittest.TestCase):
rb.rebalance()
rb.save('some.builder')
mock_open.assert_called_once_with('some.builder', 'wb')
mock_pickle_dump.assert_called_once_with(rb.to_dict(), mock_fh.__enter__(),
mock_pickle_dump.assert_called_once_with(rb.to_dict(),
mock_fh.__enter__(),
protocol=2)
def test_search_devs(self):

View File

@ -56,11 +56,12 @@ class TestUtils(unittest.TestCase):
self.test_devs = get_test_devs()
def test_tiers_for_dev(self):
self.assertEqual(tiers_for_dev(self.test_dev),
((1,),
(1, 1),
(1, 1, '192.168.1.1:6000'),
(1, 1, '192.168.1.1:6000', 0)))
self.assertEqual(
tiers_for_dev(self.test_dev),
((1,),
(1, 1),
(1, 1, '192.168.1.1:6000'),
(1, 1, '192.168.1.1:6000', 0)))
def test_build_tier_tree(self):
ret = build_tier_tree(self.test_devs)
@ -110,7 +111,8 @@ class TestUtils(unittest.TestCase):
res = parse_search_value('R127.0.0.10')
self.assertEqual(res, {'replication_ip': '127.0.0.10'})
res = parse_search_value('R[127.0.0.10]:20000')
self.assertEqual(res, {'replication_ip': '127.0.0.10', 'replication_port': 20000})
self.assertEqual(res, {'replication_ip': '127.0.0.10',
'replication_port': 20000})
res = parse_search_value('R:20000')
self.assertEqual(res, {'replication_port': 20000})
res = parse_search_value('/sdb1')

View File

@ -33,7 +33,8 @@ class TestBufferedHTTP(unittest.TestCase):
fp.write('HTTP/1.1 200 OK\r\nContent-Length: 8\r\n\r\n'
'RESPONSE')
fp.flush()
self.assertEquals(fp.readline(),
self.assertEquals(
fp.readline(),
'PUT /dev/%s/path/..%%25/?omg&no=%%7f HTTP/1.1\r\n' %
expected_par)
headers = {}
@ -52,10 +53,12 @@ class TestBufferedHTTP(unittest.TestCase):
event = spawn(accept, par)
try:
with Timeout(3):
conn = bufferedhttp.http_connect('127.0.0.1',
bindsock.getsockname()[1], 'dev', par, 'PUT',
'/path/..%/', {'content-length': 7, 'x-header':
'value'}, query_string='omg&no=%7f')
conn = bufferedhttp.http_connect(
'127.0.0.1', bindsock.getsockname()[1], 'dev', par,
'PUT', '/path/..%/', {
'content-length': 7,
'x-header': 'value'},
query_string='omg&no=%7f')
conn.send('REQUEST\r\n')
resp = conn.getresponse()
body = resp.read()
@ -88,10 +91,12 @@ class TestBufferedHTTP(unittest.TestCase):
origHTTPSConnection = bufferedhttp.HTTPSConnection
bufferedhttp.HTTPSConnection = MockHTTPSConnection
try:
bufferedhttp.http_connect('127.0.0.1', 8080, 'sda', 1, 'GET', '/',
bufferedhttp.http_connect(
'127.0.0.1', 8080, 'sda', 1, 'GET', '/',
headers={'x-one': '1', 'x-two': 2, 'x-three': 3.0,
'x-four': {'crazy': 'value'}}, ssl=True)
bufferedhttp.http_connect_raw('127.0.0.1', 8080, 'GET', '/',
bufferedhttp.http_connect_raw(
'127.0.0.1', 8080, 'GET', '/',
headers={'x-one': '1', 'x-two': 2, 'x-three': 3.0,
'x-four': {'crazy': 'value'}}, ssl=True)
finally:

View File

@ -1188,8 +1188,8 @@ class TestServer(unittest.TestCase):
4: conf4,
}
self.assertEquals(server.launch(once=True), expected)
self.assertEquals(mock_spawn.conf_files, [conf1, conf2,
conf3, conf4])
self.assertEquals(mock_spawn.conf_files, [
conf1, conf2, conf3, conf4])
expected = {
'once': True,
}
@ -1310,7 +1310,7 @@ class TestManager(unittest.TestCase):
self.assert_(server.server in manager.ALL_SERVERS)
# test dedupe
m = manager.Manager(['main', 'rest', 'proxy', 'object',
'container', 'account'])
'container', 'account'])
self.assertEquals(len(m.servers), len(manager.ALL_SERVERS))
for server in m.servers:
self.assert_(server.server in manager.ALL_SERVERS)

View File

@ -371,15 +371,16 @@ class TestRequest(unittest.TestCase):
def test_invalid_req_environ_property_args(self):
# getter only property
try:
req = swift.common.swob.Request.blank('/', params={'a': 'b'})
swift.common.swob.Request.blank('/', params={'a': 'b'})
except TypeError as e:
self.assertEquals("got unexpected keyword argument 'params'", str(e))
self.assertEquals("got unexpected keyword argument 'params'",
str(e))
else:
self.assert_(False, "invalid req_environ_property "
"didn't raise error!")
# regular attribute
try:
req = swift.common.swob.Request.blank('/', _params_cache={'a': 'b'})
swift.common.swob.Request.blank('/', _params_cache={'a': 'b'})
except TypeError as e:
self.assertEquals("got unexpected keyword "
"argument '_params_cache'", str(e))
@ -388,7 +389,7 @@ class TestRequest(unittest.TestCase):
"didn't raise error!")
# non-existant attribute
try:
req = swift.common.swob.Request.blank('/', params_cache={'a': 'b'})
swift.common.swob.Request.blank('/', params_cache={'a': 'b'})
except TypeError as e:
self.assertEquals("got unexpected keyword "
"argument 'params_cache'", str(e))
@ -397,7 +398,7 @@ class TestRequest(unittest.TestCase):
"didn't raise error!")
# method
try:
req = swift.common.swob.Request.blank(
swift.common.swob.Request.blank(
'/', as_referer='GET http://example.com')
except TypeError as e:
self.assertEquals("got unexpected keyword "
@ -406,7 +407,6 @@ class TestRequest(unittest.TestCase):
self.assert_(False, "invalid req_environ_property "
"didn't raise error!")
def test_blank_path_info_precedence(self):
blank = swift.common.swob.Request.blank
req = blank('/a')
@ -725,7 +725,7 @@ class TestRequest(unittest.TestCase):
req = swift.common.swob.Request.blank(
u'/',
environ={'REQUEST_METHOD': 'PUT', 'PATH_INFO': '/'},
body='x'*42)
body='x' * 42)
self.assertEquals(req.message_length(), 42)
req.headers['Content-Length'] = 'abc'
@ -741,7 +741,7 @@ class TestRequest(unittest.TestCase):
u'/',
environ={'REQUEST_METHOD': 'PUT', 'PATH_INFO': '/'},
headers={'transfer-encoding': 'chunked'},
body='x'*42)
body='x' * 42)
self.assertEquals(req.message_length(), None)
req.headers['Transfer-Encoding'] = 'gzip,chunked'

View File

@ -441,8 +441,8 @@ class TestUtils(unittest.TestCase):
os.path.isdir('/dev/log'):
# Since socket on OSX is in /var/run/syslog, there will be
# a fallback to UDP.
expected_args.append(((),
{'facility': orig_sysloghandler.LOG_LOCAL3}))
expected_args.append(
((), {'facility': orig_sysloghandler.LOG_LOCAL3}))
self.assertEquals(expected_args, syslog_handler_args)
syslog_handler_args = []
@ -1395,9 +1395,11 @@ log_name = %(yarr)s'''
with patch.object(utils.tpool, 'execute', lambda f: f()):
self.assertTrue(
utils.tpool_reraise(MagicMock(return_value='test1')), 'test1')
self.assertRaises(Exception,
self.assertRaises(
Exception,
utils.tpool_reraise, MagicMock(side_effect=Exception('test2')))
self.assertRaises(BaseException,
self.assertRaises(
BaseException,
utils.tpool_reraise,
MagicMock(side_effect=BaseException('test3')))
@ -1429,8 +1431,10 @@ log_name = %(yarr)s'''
with utils.lock_file(nt.name, timeout=3, unlink=False) as f:
try:
with utils.lock_file(nt.name, timeout=1, unlink=False) as f:
self.assertTrue(False, "Expected LockTimeout exception")
with utils.lock_file(
nt.name, timeout=1, unlink=False) as f:
self.assertTrue(
False, "Expected LockTimeout exception")
except LockTimeout:
pass
@ -1438,7 +1442,8 @@ log_name = %(yarr)s'''
self.assertEqual(f.read(), "test string\nanother string")
# we have a lock, now let's try to get a newer one
fd = os.open(nt.name, flags)
self.assertRaises(IOError, fcntl.flock, fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
self.assertRaises(
IOError, fcntl.flock, fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
self.assertRaises(OSError, os.remove, nt.name)
@ -1796,7 +1801,7 @@ class TestStatsdLogging(unittest.TestCase):
payload = mock_socket.sent[0][0]
self.assertTrue(payload.endswith("|@%s" % effective_sample_rate),
payload)
payload)
effective_sample_rate = 0.587 * 0.91
statsd_client.random = lambda: effective_sample_rate - 0.001
@ -1805,7 +1810,7 @@ class TestStatsdLogging(unittest.TestCase):
payload = mock_socket.sent[1][0]
self.assertTrue(payload.endswith("|@%s" % effective_sample_rate),
payload)
payload)
def test_timing_stats(self):
class MockController(object):

View File

@ -42,21 +42,24 @@ from mock import patch
def _fake_rings(tmpdir):
with closing(GzipFile(os.path.join(tmpdir, 'account.ring.gz'), 'wb')) as f:
account_ring_path = os.path.join(tmpdir, 'account.ring.gz')
with closing(GzipFile(account_ring_path, 'wb')) as f:
pickle.dump(ring.RingData([[0, 1, 0, 1], [1, 0, 1, 0]],
[{'id': 0, 'zone': 0, 'device': 'sda1', 'ip': '127.0.0.1',
'port': 6012},
{'id': 1, 'zone': 1, 'device': 'sdb1', 'ip': '127.0.0.1',
'port': 6022}], 30),
f)
with closing(GzipFile(os.path.join(tmpdir, 'container.ring.gz'), 'wb')) as f:
container_ring_path = os.path.join(tmpdir, 'container.ring.gz')
with closing(GzipFile(container_ring_path, 'wb')) as f:
pickle.dump(ring.RingData([[0, 1, 0, 1], [1, 0, 1, 0]],
[{'id': 0, 'zone': 0, 'device': 'sda1', 'ip': '127.0.0.1',
'port': 6011},
{'id': 1, 'zone': 1, 'device': 'sdb1', 'ip': '127.0.0.1',
'port': 6021}], 30),
f)
with closing(GzipFile(os.path.join(tmpdir, 'object.ring.gz'), 'wb')) as f:
object_ring_path = os.path.join(tmpdir, 'object.ring.gz')
with closing(GzipFile(object_ring_path, 'wb')) as f:
pickle.dump(ring.RingData([[0, 1, 0, 1], [1, 0, 1, 0]],
[{'id': 0, 'zone': 0, 'device': 'sda1', 'ip': '127.0.0.1',
'port': 6010},
@ -535,6 +538,7 @@ class TestWSGI(unittest.TestCase):
self.assertEquals(r.environ['SCRIPT_NAME'], '')
self.assertEquals(r.environ['PATH_INFO'], '/override')
class TestWSGIContext(unittest.TestCase):
def test_app_call(self):

View File

@ -41,11 +41,12 @@ class TestContainerUpdater(unittest.TestCase):
os.mkdir(self.testdir)
ring_file = os.path.join(self.testdir, 'account.ring.gz')
with closing(GzipFile(ring_file, 'wb')) as f:
pickle.dump(RingData([[0, 1, 0, 1], [1, 0, 1, 0]],
[{'id': 0, 'ip': '127.0.0.1', 'port': 12345, 'device': 'sda1',
'zone': 0},
{'id': 1, 'ip': '127.0.0.1', 'port': 12345, 'device': 'sda1',
'zone': 2}], 30),
pickle.dump(
RingData([[0, 1, 0, 1], [1, 0, 1, 0]],
[{'id': 0, 'ip': '127.0.0.1', 'port': 12345,
'device': 'sda1', 'zone': 0},
{'id': 1, 'ip': '127.0.0.1', 'port': 12345,
'device': 'sda1', 'zone': 2}], 30),
f)
self.devices_dir = os.path.join(self.testdir, 'devices')
os.mkdir(self.devices_dir)
@ -63,7 +64,7 @@ class TestContainerUpdater(unittest.TestCase):
'interval': '1',
'concurrency': '2',
'node_timeout': '5',
})
})
self.assert_(hasattr(cu, 'logger'))
self.assert_(cu.logger is not None)
self.assertEquals(cu.devices, self.devices_dir)
@ -81,7 +82,7 @@ class TestContainerUpdater(unittest.TestCase):
'concurrency': '1',
'node_timeout': '15',
'account_suppression_time': 0
})
})
cu.run_once()
containers_dir = os.path.join(self.sda1, container_server.DATADIR)
os.mkdir(containers_dir)
@ -134,12 +135,14 @@ class TestContainerUpdater(unittest.TestCase):
return err
return None
bindsock = listen(('127.0.0.1', 0))
def spawn_accepts():
events = []
for _junk in xrange(2):
sock, addr = bindsock.accept()
events.append(spawn(accept, sock, addr, 201))
return events
spawned = spawn(spawn_accepts)
for dev in cu.get_account_ring().devs:
if dev is not None:
@ -163,7 +166,7 @@ class TestContainerUpdater(unittest.TestCase):
'interval': '1',
'concurrency': '1',
'node_timeout': '15',
})
})
containers_dir = os.path.join(self.sda1, container_server.DATADIR)
os.mkdir(containers_dir)
subdir = os.path.join(containers_dir, 'subdir')
@ -173,6 +176,7 @@ class TestContainerUpdater(unittest.TestCase):
cb.initialize(normalize_timestamp(1))
cb.put_object('\xce\xa9', normalize_timestamp(2), 3, 'text/plain',
'68b329da9893e34099c7d8ad5cb9c940')
def accept(sock, addr):
try:
with Timeout(3):
@ -186,7 +190,9 @@ class TestContainerUpdater(unittest.TestCase):
traceback.print_exc()
return err
return None
bindsock = listen(('127.0.0.1', 0))
def spawn_accepts():
events = []
for _junk in xrange(2):
@ -194,6 +200,7 @@ class TestContainerUpdater(unittest.TestCase):
sock, addr = bindsock.accept()
events.append(spawn(accept, sock, addr))
return events
spawned = spawn(spawn_accepts)
for dev in cu.get_account_ring().devs:
if dev is not None:

View File

@ -46,10 +46,10 @@ class TestObjectUpdater(unittest.TestCase):
with closing(GzipFile(ring_file, 'wb')) as f:
pickle.dump(
RingData([[0, 1, 0, 1], [1, 0, 1, 0]],
[{'id': 0, 'ip': '127.0.0.1', 'port': 1, 'device': 'sda1',
'zone': 0},
{'id': 1, 'ip': '127.0.0.1', 'port': 1, 'device': 'sda1',
'zone': 2}], 30),
[{'id': 0, 'ip': '127.0.0.1', 'port': 1,
'device': 'sda1', 'zone': 0},
{'id': 1, 'ip': '127.0.0.1', 'port': 1,
'device': 'sda1', 'zone': 2}], 30),
f)
self.devices_dir = os.path.join(self.testdir, 'devices')
os.mkdir(self.devices_dir)

View File

@ -124,8 +124,9 @@ class TestFuncs(unittest.TestCase):
self.assertEquals(env['swift.account/a'], info_a)
self.assertEquals(env['swift.container/a/c'], info_c)
# This time do a non cached call to account than non cached to container
env = {} # abandon previous call to env
# This time do a non cached call to account than non cached to
# container
env = {} # abandon previous call to env
with patch('swift.proxy.controllers.base.'
'_prepare_pre_auth_info_request', FakeRequest):
info_c = get_info(None, env, 'a', 'c')
@ -137,7 +138,8 @@ class TestFuncs(unittest.TestCase):
self.assertEquals(env['swift.account/a'], info_a)
self.assertEquals(env['swift.container/a/c'], info_c)
# This time do an env cached call to container while account is not cached
# This time do an env cached call to container while account is not
# cached
del(env['swift.account/a'])
info_c = get_info(None, env, 'a', 'c')
# Check that you got proper info
@ -217,8 +219,8 @@ class TestFuncs(unittest.TestCase):
cache_key = get_container_memcache_key("account", "cont")
env_key = 'swift.%s' % cache_key
req = Request.blank("/v1/account/cont",
environ={ env_key: {'bytes': 3867},
'swift.cache': FakeCache({})})
environ={env_key: {'bytes': 3867},
'swift.cache': FakeCache({})})
resp = get_container_info(req.environ, 'xxx')
self.assertEquals(resp['bytes'], 3867)
@ -266,8 +268,8 @@ class TestFuncs(unittest.TestCase):
cache_key = get_account_memcache_key("account")
env_key = 'swift.%s' % cache_key
req = Request.blank("/v1/account",
environ={ env_key: {'bytes': 3867},
'swift.cache': FakeCache({})})
environ={env_key: {'bytes': 3867},
'swift.cache': FakeCache({})})
resp = get_account_info(req.environ, 'xxx')
self.assertEquals(resp['bytes'], 3867)

View File

@ -21,6 +21,7 @@ import swift
from swift.proxy import server as proxy_server
from test.unit import FakeRing, FakeMemcache, fake_http_connect
@contextmanager
def set_http_connect(*args, **kwargs):
old_connect = swift.proxy.controllers.base.http_connect
@ -36,7 +37,6 @@ def set_http_connect(*args, **kwargs):
swift.proxy.controllers.container.http_connect = old_connect
class TestObjControllerWriteAffinity(unittest.TestCase):
def setUp(self):
self.app = proxy_server.Application(
@ -61,7 +61,8 @@ class TestObjControllerWriteAffinity(unittest.TestCase):
def test_iter_nodes_local_first_moves_locals_first(self):
controller = proxy_server.ObjectController(self.app, 'a', 'c', 'o')
self.app.write_affinity_is_local_fn = (lambda node: node['region'] == 1)
self.app.write_affinity_is_local_fn = (
lambda node: node['region'] == 1)
self.app.write_affinity_node_count = lambda ring: 4
all_nodes = self.app.object_ring.get_part_nodes(1)
@ -80,8 +81,8 @@ class TestObjControllerWriteAffinity(unittest.TestCase):
controller = proxy_server.ObjectController(self.app, 'a', 'c', 'o')
self.app.conn_timeout = 0.1
with set_http_connect(200, slow_connect=True):
nodes = [dict(ip='', port='', device=''),]
res = controller._connect_put_node(nodes, '', '', {}, ('',''))
nodes = [dict(ip='', port='', device='')]
res = controller._connect_put_node(nodes, '', '', {}, ('', ''))
self.assertTrue(res is None)
if __name__ == '__main__':