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:
parent
c067abd21e
commit
be1cff4f1f
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
@ -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()
|
||||
|
@ -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,
|
||||
|
@ -58,6 +58,7 @@ class SetConfigParser(object):
|
||||
def start_response(*args):
|
||||
pass
|
||||
|
||||
|
||||
class TestCacheMiddleware(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
@ -53,9 +53,11 @@ 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,
|
||||
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)
|
||||
@ -64,7 +66,8 @@ class TestNameCheckMiddleware(unittest.TestCase):
|
||||
path = '/V1.0/' + 'c' * (MAX_LENGTH - 5)
|
||||
resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'}
|
||||
).get_response(self.test_check)
|
||||
self.assertEquals(resp.body,
|
||||
self.assertEquals(
|
||||
resp.body,
|
||||
("Object/Container name longer than the allowed maximum %s"
|
||||
% self.conf['maximum_length']))
|
||||
self.assertEquals(resp.status_int, 400)
|
||||
@ -72,9 +75,11 @@ class TestNameCheckMiddleware(unittest.TestCase):
|
||||
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,
|
||||
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']))
|
||||
@ -83,8 +88,9 @@ class TestNameCheckMiddleware(unittest.TestCase):
|
||||
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')
|
||||
|
||||
|
||||
|
@ -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):
|
||||
|
@ -56,7 +56,8 @@ class TestUtils(unittest.TestCase):
|
||||
self.test_devs = get_test_devs()
|
||||
|
||||
def test_tiers_for_dev(self):
|
||||
self.assertEqual(tiers_for_dev(self.test_dev),
|
||||
self.assertEqual(
|
||||
tiers_for_dev(self.test_dev),
|
||||
((1,),
|
||||
(1, 1),
|
||||
(1, 1, '192.168.1.1:6000'),
|
||||
@ -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')
|
||||
|
@ -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:
|
||||
|
@ -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,
|
||||
}
|
||||
|
@ -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'
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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)
|
||||
@ -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:
|
||||
@ -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:
|
||||
|
@ -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)
|
||||
|
@ -124,7 +124,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 a non cached call to account than non cached to container
|
||||
# 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):
|
||||
@ -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,7 +219,7 @@ 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},
|
||||
environ={env_key: {'bytes': 3867},
|
||||
'swift.cache': FakeCache({})})
|
||||
resp = get_container_info(req.environ, 'xxx')
|
||||
self.assertEquals(resp['bytes'], 3867)
|
||||
@ -266,7 +268,7 @@ 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},
|
||||
environ={env_key: {'bytes': 3867},
|
||||
'swift.cache': FakeCache({})})
|
||||
resp = get_account_info(req.environ, 'xxx')
|
||||
self.assertEquals(resp['bytes'], 3867)
|
||||
|
@ -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__':
|
||||
|
Loading…
Reference in New Issue
Block a user