Fix PEP8 issues in ./test/unit/common .
Fix some pep8 issues in modified: test_bufferedhttp.py modified: test_constraints.py modified: test_db.py modified: test_db_replicator.py modified: test_init.py make the code looks pretty. Change-Id: I1c374b1ccd4f028c4e4b2e8194a6d1c201d50571
This commit is contained in:
parent
4a2ae2b460
commit
7b664c99e5
@ -24,6 +24,7 @@ class TestBufferedHTTP(unittest.TestCase):
|
|||||||
|
|
||||||
def test_http_connect(self):
|
def test_http_connect(self):
|
||||||
bindsock = listen(('127.0.0.1', 0))
|
bindsock = listen(('127.0.0.1', 0))
|
||||||
|
|
||||||
def accept(expected_par):
|
def accept(expected_par):
|
||||||
try:
|
try:
|
||||||
with Timeout(3):
|
with Timeout(3):
|
||||||
|
@ -166,9 +166,9 @@ class TestConstraints(unittest.TestCase):
|
|||||||
|
|
||||||
def test_check_mount(self):
|
def test_check_mount(self):
|
||||||
self.assertFalse(constraints.check_mount('', ''))
|
self.assertFalse(constraints.check_mount('', ''))
|
||||||
constraints.os = MockTrue() # mock os module
|
constraints.os = MockTrue() # mock os module
|
||||||
self.assertTrue(constraints.check_mount('/srv', '1'))
|
self.assertTrue(constraints.check_mount('/srv', '1'))
|
||||||
reload(constraints) # put it back
|
reload(constraints) # put it back
|
||||||
|
|
||||||
def test_check_float(self):
|
def test_check_float(self):
|
||||||
self.assertFalse(constraints.check_float(''))
|
self.assertFalse(constraints.check_float(''))
|
||||||
|
@ -124,6 +124,7 @@ class TestDatabaseBroker(unittest.TestCase):
|
|||||||
DatabaseBroker(':memory:').initialize,
|
DatabaseBroker(':memory:').initialize,
|
||||||
normalize_timestamp('1'))
|
normalize_timestamp('1'))
|
||||||
stub_dict = {}
|
stub_dict = {}
|
||||||
|
|
||||||
def stub(*args, **kwargs):
|
def stub(*args, **kwargs):
|
||||||
for key in stub_dict.keys():
|
for key in stub_dict.keys():
|
||||||
del stub_dict[key]
|
del stub_dict[key]
|
||||||
@ -156,6 +157,7 @@ class TestDatabaseBroker(unittest.TestCase):
|
|||||||
conn.execute('INSERT INTO test (one) VALUES ("1")')
|
conn.execute('INSERT INTO test (one) VALUES ("1")')
|
||||||
conn.commit()
|
conn.commit()
|
||||||
stub_called = [False]
|
stub_called = [False]
|
||||||
|
|
||||||
def delete_stub(*a, **kw):
|
def delete_stub(*a, **kw):
|
||||||
stub_called[0] = True
|
stub_called[0] = True
|
||||||
broker = DatabaseBroker(':memory:')
|
broker = DatabaseBroker(':memory:')
|
||||||
@ -198,6 +200,7 @@ class TestDatabaseBroker(unittest.TestCase):
|
|||||||
except Exception:
|
except Exception:
|
||||||
got_exc = True
|
got_exc = True
|
||||||
self.assert_(got_exc)
|
self.assert_(got_exc)
|
||||||
|
|
||||||
def stub(*args, **kwargs):
|
def stub(*args, **kwargs):
|
||||||
pass
|
pass
|
||||||
broker._initialize = stub
|
broker._initialize = stub
|
||||||
@ -273,6 +276,7 @@ class TestDatabaseBroker(unittest.TestCase):
|
|||||||
except Exception:
|
except Exception:
|
||||||
got_exc = True
|
got_exc = True
|
||||||
self.assert_(got_exc)
|
self.assert_(got_exc)
|
||||||
|
|
||||||
def stub(*args, **kwargs):
|
def stub(*args, **kwargs):
|
||||||
pass
|
pass
|
||||||
broker._initialize = stub
|
broker._initialize = stub
|
||||||
@ -281,7 +285,8 @@ class TestDatabaseBroker(unittest.TestCase):
|
|||||||
pass
|
pass
|
||||||
with broker.lock():
|
with broker.lock():
|
||||||
pass
|
pass
|
||||||
broker2 = DatabaseBroker(os.path.join(self.testdir, '1.db'), timeout=.1)
|
broker2 = DatabaseBroker(os.path.join(self.testdir, '1.db'),
|
||||||
|
timeout=.1)
|
||||||
broker2._initialize = stub
|
broker2._initialize = stub
|
||||||
with broker.lock():
|
with broker.lock():
|
||||||
got_exc = False
|
got_exc = False
|
||||||
@ -304,6 +309,7 @@ class TestDatabaseBroker(unittest.TestCase):
|
|||||||
broker.db_type = 'test'
|
broker.db_type = 'test'
|
||||||
broker.db_contains_type = 'test'
|
broker.db_contains_type = 'test'
|
||||||
uuid1 = str(uuid4())
|
uuid1 = str(uuid4())
|
||||||
|
|
||||||
def _initialize(conn, timestamp):
|
def _initialize(conn, timestamp):
|
||||||
conn.execute('CREATE TABLE test (one TEXT)')
|
conn.execute('CREATE TABLE test (one TEXT)')
|
||||||
conn.execute('CREATE TABLE test_stat (id TEXT)')
|
conn.execute('CREATE TABLE test_stat (id TEXT)')
|
||||||
@ -350,6 +356,7 @@ class TestDatabaseBroker(unittest.TestCase):
|
|||||||
broker = DatabaseBroker(':memory:')
|
broker = DatabaseBroker(':memory:')
|
||||||
broker.db_type = 'test'
|
broker.db_type = 'test'
|
||||||
broker.db_contains_type = 'test'
|
broker.db_contains_type = 'test'
|
||||||
|
|
||||||
def _initialize(conn, timestamp):
|
def _initialize(conn, timestamp):
|
||||||
conn.execute('CREATE TABLE test (one TEXT)')
|
conn.execute('CREATE TABLE test (one TEXT)')
|
||||||
conn.execute('INSERT INTO test (one) VALUES ("1")')
|
conn.execute('INSERT INTO test (one) VALUES ("1")')
|
||||||
@ -372,6 +379,7 @@ class TestDatabaseBroker(unittest.TestCase):
|
|||||||
broker.db_type = 'test'
|
broker.db_type = 'test'
|
||||||
broker.db_contains_type = 'test'
|
broker.db_contains_type = 'test'
|
||||||
uuid1 = str(uuid4())
|
uuid1 = str(uuid4())
|
||||||
|
|
||||||
def _initialize(conn, timestamp):
|
def _initialize(conn, timestamp):
|
||||||
conn.execute('CREATE TABLE test (one TEXT)')
|
conn.execute('CREATE TABLE test (one TEXT)')
|
||||||
conn.execute('CREATE TABLE test_stat (id TEXT)')
|
conn.execute('CREATE TABLE test_stat (id TEXT)')
|
||||||
@ -408,6 +416,7 @@ class TestDatabaseBroker(unittest.TestCase):
|
|||||||
|
|
||||||
def test_merge_syncs(self):
|
def test_merge_syncs(self):
|
||||||
broker = DatabaseBroker(':memory:')
|
broker = DatabaseBroker(':memory:')
|
||||||
|
|
||||||
def stub(*args, **kwargs):
|
def stub(*args, **kwargs):
|
||||||
pass
|
pass
|
||||||
broker._initialize = stub
|
broker._initialize = stub
|
||||||
@ -445,6 +454,7 @@ class TestDatabaseBroker(unittest.TestCase):
|
|||||||
broker_uuid = str(uuid4())
|
broker_uuid = str(uuid4())
|
||||||
broker_metadata = metadata and simplejson.dumps(
|
broker_metadata = metadata and simplejson.dumps(
|
||||||
{'Test': ('Value', normalize_timestamp(1))}) or ''
|
{'Test': ('Value', normalize_timestamp(1))}) or ''
|
||||||
|
|
||||||
def _initialize(conn, put_timestamp):
|
def _initialize(conn, put_timestamp):
|
||||||
if put_timestamp is None:
|
if put_timestamp is None:
|
||||||
put_timestamp = normalize_timestamp(0)
|
put_timestamp = normalize_timestamp(0)
|
||||||
@ -688,7 +698,6 @@ class TestContainerBroker(unittest.TestCase):
|
|||||||
res = broker.reclaim(normalize_timestamp(time()), time())
|
res = broker.reclaim(normalize_timestamp(time()), time())
|
||||||
broker.delete_db(normalize_timestamp(time()))
|
broker.delete_db(normalize_timestamp(time()))
|
||||||
|
|
||||||
|
|
||||||
def test_delete_object(self):
|
def test_delete_object(self):
|
||||||
""" Test swift.common.db.ContainerBroker.delete_object """
|
""" Test swift.common.db.ContainerBroker.delete_object """
|
||||||
broker = ContainerBroker(':memory:', account='a', container='c')
|
broker = ContainerBroker(':memory:', account='a', container='c')
|
||||||
@ -890,7 +899,7 @@ class TestContainerBroker(unittest.TestCase):
|
|||||||
"SELECT deleted FROM object").fetchone()[0], 0)
|
"SELECT deleted FROM object").fetchone()[0], 0)
|
||||||
|
|
||||||
# Put event from after last put but before last post
|
# Put event from after last put but before last post
|
||||||
timestamp = in_between_timestamp
|
timestamp = in_between_timestamp
|
||||||
broker.put_object('"{<object \'&\' name>}"', timestamp, 456,
|
broker.put_object('"{<object \'&\' name>}"', timestamp, 456,
|
||||||
'application/x-test3',
|
'application/x-test3',
|
||||||
'6af83e3196bf99f440f31f2e1a6c9afe')
|
'6af83e3196bf99f440f31f2e1a6c9afe')
|
||||||
@ -913,7 +922,8 @@ class TestContainerBroker(unittest.TestCase):
|
|||||||
|
|
||||||
def test_get_info(self):
|
def test_get_info(self):
|
||||||
""" Test swift.common.db.ContainerBroker.get_info """
|
""" Test swift.common.db.ContainerBroker.get_info """
|
||||||
broker = ContainerBroker(':memory:', account='test1', container='test2')
|
broker = ContainerBroker(':memory:', account='test1',
|
||||||
|
container='test2')
|
||||||
broker.initialize(normalize_timestamp('1'))
|
broker.initialize(normalize_timestamp('1'))
|
||||||
|
|
||||||
info = broker.get_info()
|
info = broker.get_info()
|
||||||
@ -962,7 +972,8 @@ class TestContainerBroker(unittest.TestCase):
|
|||||||
self.assertEquals(info['x_container_sync_point2'], -1)
|
self.assertEquals(info['x_container_sync_point2'], -1)
|
||||||
|
|
||||||
def test_set_x_syncs(self):
|
def test_set_x_syncs(self):
|
||||||
broker = ContainerBroker(':memory:', account='test1', container='test2')
|
broker = ContainerBroker(':memory:', account='test1',
|
||||||
|
container='test2')
|
||||||
broker.initialize(normalize_timestamp('1'))
|
broker.initialize(normalize_timestamp('1'))
|
||||||
|
|
||||||
info = broker.get_info()
|
info = broker.get_info()
|
||||||
@ -975,7 +986,8 @@ class TestContainerBroker(unittest.TestCase):
|
|||||||
self.assertEquals(info['x_container_sync_point2'], 2)
|
self.assertEquals(info['x_container_sync_point2'], 2)
|
||||||
|
|
||||||
def test_get_report_info(self):
|
def test_get_report_info(self):
|
||||||
broker = ContainerBroker(':memory:', account='test1', container='test2')
|
broker = ContainerBroker(':memory:', account='test1',
|
||||||
|
container='test2')
|
||||||
broker.initialize(normalize_timestamp('1'))
|
broker.initialize(normalize_timestamp('1'))
|
||||||
|
|
||||||
info = broker.get_info()
|
info = broker.get_info()
|
||||||
@ -1098,7 +1110,7 @@ class TestContainerBroker(unittest.TestCase):
|
|||||||
self.assertEquals(len(listing), 2)
|
self.assertEquals(len(listing), 2)
|
||||||
self.assertEquals([row[0] for row in listing], ['2/', '3/'])
|
self.assertEquals([row[0] for row in listing], ['2/', '3/'])
|
||||||
|
|
||||||
listing = broker.list_objects_iter(10, '2/',None, None, '/')
|
listing = broker.list_objects_iter(10, '2/', None, None, '/')
|
||||||
self.assertEquals(len(listing), 1)
|
self.assertEquals(len(listing), 1)
|
||||||
self.assertEquals([row[0] for row in listing], ['3/'])
|
self.assertEquals([row[0] for row in listing], ['3/'])
|
||||||
|
|
||||||
@ -1167,14 +1179,17 @@ class TestContainerBroker(unittest.TestCase):
|
|||||||
broker.put_object('/snakes', normalize_timestamp(0), 0,
|
broker.put_object('/snakes', normalize_timestamp(0), 0,
|
||||||
'text/plain', 'd41d8cd98f00b204e9800998ecf8427e')
|
'text/plain', 'd41d8cd98f00b204e9800998ecf8427e')
|
||||||
|
|
||||||
#def list_objects_iter(self, limit, marker, prefix, delimiter, path=None,
|
#def list_objects_iter(self, limit, marker, prefix, delimiter,
|
||||||
# format=None):
|
# path=None, format=None):
|
||||||
listing = broker.list_objects_iter(100, None, None, '/pets/f', '/')
|
listing = broker.list_objects_iter(100, None, None, '/pets/f', '/')
|
||||||
self.assertEquals([row[0] for row in listing], ['/pets/fish/', '/pets/fish_info.txt'])
|
self.assertEquals([row[0] for row in listing],
|
||||||
|
['/pets/fish/', '/pets/fish_info.txt'])
|
||||||
listing = broker.list_objects_iter(100, None, None, '/pets/fish', '/')
|
listing = broker.list_objects_iter(100, None, None, '/pets/fish', '/')
|
||||||
self.assertEquals([row[0] for row in listing], ['/pets/fish/', '/pets/fish_info.txt'])
|
self.assertEquals([row[0] for row in listing],
|
||||||
|
['/pets/fish/', '/pets/fish_info.txt'])
|
||||||
listing = broker.list_objects_iter(100, None, None, '/pets/fish/', '/')
|
listing = broker.list_objects_iter(100, None, None, '/pets/fish/', '/')
|
||||||
self.assertEquals([row[0] for row in listing], ['/pets/fish/a', '/pets/fish/b'])
|
self.assertEquals([row[0] for row in listing],
|
||||||
|
['/pets/fish/a', '/pets/fish/b'])
|
||||||
|
|
||||||
def test_double_check_trailing_delimiter(self):
|
def test_double_check_trailing_delimiter(self):
|
||||||
""" Test swift.common.db.ContainerBroker.list_objects_iter for a
|
""" Test swift.common.db.ContainerBroker.list_objects_iter for a
|
||||||
@ -1204,15 +1219,15 @@ class TestContainerBroker(unittest.TestCase):
|
|||||||
listing = broker.list_objects_iter(15, None, None, None, None)
|
listing = broker.list_objects_iter(15, None, None, None, None)
|
||||||
self.assertEquals(len(listing), 10)
|
self.assertEquals(len(listing), 10)
|
||||||
self.assertEquals([row[0] for row in listing],
|
self.assertEquals([row[0] for row in listing],
|
||||||
['a', 'a/', 'a/a', 'a/a/a', 'a/a/b', 'a/b', 'b', 'b/a', 'b/b', 'c'])
|
['a', 'a/', 'a/a', 'a/a/a', 'a/a/b', 'a/b', 'b', 'b/a', 'b/b', 'c'])
|
||||||
listing = broker.list_objects_iter(15, None, None, '', '/')
|
listing = broker.list_objects_iter(15, None, None, '', '/')
|
||||||
self.assertEquals(len(listing), 5)
|
self.assertEquals(len(listing), 5)
|
||||||
self.assertEquals([row[0] for row in listing],
|
self.assertEquals([row[0] for row in listing],
|
||||||
['a', 'a/', 'b', 'b/', 'c'])
|
['a', 'a/', 'b', 'b/', 'c'])
|
||||||
listing = broker.list_objects_iter(15, None, None, 'a/', '/')
|
listing = broker.list_objects_iter(15, None, None, 'a/', '/')
|
||||||
self.assertEquals(len(listing), 4)
|
self.assertEquals(len(listing), 4)
|
||||||
self.assertEquals([row[0] for row in listing],
|
self.assertEquals([row[0] for row in listing],
|
||||||
['a/', 'a/a', 'a/a/', 'a/b'])
|
['a/', 'a/a', 'a/a/', 'a/b'])
|
||||||
listing = broker.list_objects_iter(15, None, None, 'b/', '/')
|
listing = broker.list_objects_iter(15, None, None, 'b/', '/')
|
||||||
self.assertEquals(len(listing), 2)
|
self.assertEquals(len(listing), 2)
|
||||||
self.assertEquals([row[0] for row in listing], ['b/a', 'b/b'])
|
self.assertEquals([row[0] for row in listing], ['b/a', 'b/b'])
|
||||||
@ -1226,12 +1241,14 @@ class TestContainerBroker(unittest.TestCase):
|
|||||||
'text/plain', 'd41d8cd98f00b204e9800998ecf8427e')
|
'text/plain', 'd41d8cd98f00b204e9800998ecf8427e')
|
||||||
hasha = hashlib.md5('%s-%s' % ('a', '0000000001.00000')).digest()
|
hasha = hashlib.md5('%s-%s' % ('a', '0000000001.00000')).digest()
|
||||||
hashb = hashlib.md5('%s-%s' % ('b', '0000000002.00000')).digest()
|
hashb = hashlib.md5('%s-%s' % ('b', '0000000002.00000')).digest()
|
||||||
hashc = ''.join(('%2x' % (ord(a)^ord(b)) for a, b in zip(hasha, hashb)))
|
hashc = ''.join(('%2x' % (ord(a) ^ ord(b)) for a, b in zip(hasha,
|
||||||
|
hashb)))
|
||||||
self.assertEquals(broker.get_info()['hash'], hashc)
|
self.assertEquals(broker.get_info()['hash'], hashc)
|
||||||
broker.put_object('b', normalize_timestamp(3), 0,
|
broker.put_object('b', normalize_timestamp(3), 0,
|
||||||
'text/plain', 'd41d8cd98f00b204e9800998ecf8427e')
|
'text/plain', 'd41d8cd98f00b204e9800998ecf8427e')
|
||||||
hashb = hashlib.md5('%s-%s' % ('b', '0000000003.00000')).digest()
|
hashb = hashlib.md5('%s-%s' % ('b', '0000000003.00000')).digest()
|
||||||
hashc = ''.join(('%02x' % (ord(a)^ord(b)) for a, b in zip(hasha, hashb)))
|
hashc = ''.join(('%02x' % (ord(a) ^ ord(b)) for a, b in zip(hasha,
|
||||||
|
hashb)))
|
||||||
self.assertEquals(broker.get_info()['hash'], hashc)
|
self.assertEquals(broker.get_info()['hash'], hashc)
|
||||||
|
|
||||||
def test_newid(self):
|
def test_newid(self):
|
||||||
@ -1623,7 +1640,6 @@ class TestAccountBroker(unittest.TestCase):
|
|||||||
# self.assert_('z' in containers)
|
# self.assert_('z' in containers)
|
||||||
# self.assert_('a' not in containers)
|
# self.assert_('a' not in containers)
|
||||||
|
|
||||||
|
|
||||||
def test_delete_container(self):
|
def test_delete_container(self):
|
||||||
""" Test swift.common.db.AccountBroker.delete_container """
|
""" Test swift.common.db.AccountBroker.delete_container """
|
||||||
broker = AccountBroker(':memory:', account='a')
|
broker = AccountBroker(':memory:', account='a')
|
||||||
@ -1674,7 +1690,8 @@ class TestAccountBroker(unittest.TestCase):
|
|||||||
"SELECT name FROM container").fetchone()[0],
|
"SELECT name FROM container").fetchone()[0],
|
||||||
'"{<container \'&\' name>}"')
|
'"{<container \'&\' name>}"')
|
||||||
self.assertEquals(conn.execute(
|
self.assertEquals(conn.execute(
|
||||||
"SELECT put_timestamp FROM container").fetchone()[0], timestamp)
|
"SELECT put_timestamp FROM container").fetchone()[0],
|
||||||
|
timestamp)
|
||||||
self.assertEquals(conn.execute(
|
self.assertEquals(conn.execute(
|
||||||
"SELECT deleted FROM container").fetchone()[0], 0)
|
"SELECT deleted FROM container").fetchone()[0], 0)
|
||||||
|
|
||||||
@ -1685,7 +1702,8 @@ class TestAccountBroker(unittest.TestCase):
|
|||||||
"SELECT name FROM container").fetchone()[0],
|
"SELECT name FROM container").fetchone()[0],
|
||||||
'"{<container \'&\' name>}"')
|
'"{<container \'&\' name>}"')
|
||||||
self.assertEquals(conn.execute(
|
self.assertEquals(conn.execute(
|
||||||
"SELECT put_timestamp FROM container").fetchone()[0], timestamp)
|
"SELECT put_timestamp FROM container").fetchone()[0],
|
||||||
|
timestamp)
|
||||||
self.assertEquals(conn.execute(
|
self.assertEquals(conn.execute(
|
||||||
"SELECT deleted FROM container").fetchone()[0], 0)
|
"SELECT deleted FROM container").fetchone()[0], 0)
|
||||||
|
|
||||||
@ -1698,7 +1716,8 @@ class TestAccountBroker(unittest.TestCase):
|
|||||||
"SELECT name FROM container").fetchone()[0],
|
"SELECT name FROM container").fetchone()[0],
|
||||||
'"{<container \'&\' name>}"')
|
'"{<container \'&\' name>}"')
|
||||||
self.assertEquals(conn.execute(
|
self.assertEquals(conn.execute(
|
||||||
"SELECT put_timestamp FROM container").fetchone()[0], timestamp)
|
"SELECT put_timestamp FROM container").fetchone()[0],
|
||||||
|
timestamp)
|
||||||
self.assertEquals(conn.execute(
|
self.assertEquals(conn.execute(
|
||||||
"SELECT deleted FROM container").fetchone()[0], 0)
|
"SELECT deleted FROM container").fetchone()[0], 0)
|
||||||
|
|
||||||
@ -1710,7 +1729,8 @@ class TestAccountBroker(unittest.TestCase):
|
|||||||
"SELECT name FROM container").fetchone()[0],
|
"SELECT name FROM container").fetchone()[0],
|
||||||
'"{<container \'&\' name>}"')
|
'"{<container \'&\' name>}"')
|
||||||
self.assertEquals(conn.execute(
|
self.assertEquals(conn.execute(
|
||||||
"SELECT put_timestamp FROM container").fetchone()[0], timestamp)
|
"SELECT put_timestamp FROM container").fetchone()[0],
|
||||||
|
timestamp)
|
||||||
self.assertEquals(conn.execute(
|
self.assertEquals(conn.execute(
|
||||||
"SELECT deleted FROM container").fetchone()[0], 0)
|
"SELECT deleted FROM container").fetchone()[0], 0)
|
||||||
|
|
||||||
@ -1722,7 +1742,8 @@ class TestAccountBroker(unittest.TestCase):
|
|||||||
"SELECT name FROM container").fetchone()[0],
|
"SELECT name FROM container").fetchone()[0],
|
||||||
'"{<container \'&\' name>}"')
|
'"{<container \'&\' name>}"')
|
||||||
self.assertEquals(conn.execute(
|
self.assertEquals(conn.execute(
|
||||||
"SELECT put_timestamp FROM container").fetchone()[0], timestamp)
|
"SELECT put_timestamp FROM container").fetchone()[0],
|
||||||
|
timestamp)
|
||||||
self.assertEquals(conn.execute(
|
self.assertEquals(conn.execute(
|
||||||
"SELECT delete_timestamp FROM container").fetchone()[0],
|
"SELECT delete_timestamp FROM container").fetchone()[0],
|
||||||
dtimestamp)
|
dtimestamp)
|
||||||
@ -1752,7 +1773,8 @@ class TestAccountBroker(unittest.TestCase):
|
|||||||
"SELECT name FROM container").fetchone()[0],
|
"SELECT name FROM container").fetchone()[0],
|
||||||
'"{<container \'&\' name>}"')
|
'"{<container \'&\' name>}"')
|
||||||
self.assertEquals(conn.execute(
|
self.assertEquals(conn.execute(
|
||||||
"SELECT put_timestamp FROM container").fetchone()[0], timestamp)
|
"SELECT put_timestamp FROM container").fetchone()[0],
|
||||||
|
timestamp)
|
||||||
self.assertEquals(conn.execute(
|
self.assertEquals(conn.execute(
|
||||||
"SELECT deleted FROM container").fetchone()[0], 0)
|
"SELECT deleted FROM container").fetchone()[0], 0)
|
||||||
|
|
||||||
@ -1936,7 +1958,7 @@ class TestAccountBroker(unittest.TestCase):
|
|||||||
('b', '0000000002.00000-0000000000.00000-0-0')
|
('b', '0000000002.00000-0000000000.00000-0-0')
|
||||||
).digest()
|
).digest()
|
||||||
hashc = \
|
hashc = \
|
||||||
''.join(('%02x' % (ord(a)^ord(b)) for a, b in zip(hasha, hashb)))
|
''.join(('%02x' % (ord(a) ^ ord(b)) for a, b in zip(hasha, hashb)))
|
||||||
self.assertEquals(broker.get_info()['hash'], hashc)
|
self.assertEquals(broker.get_info()['hash'], hashc)
|
||||||
broker.put_container('b', normalize_timestamp(3),
|
broker.put_container('b', normalize_timestamp(3),
|
||||||
normalize_timestamp(0), 0, 0)
|
normalize_timestamp(0), 0, 0)
|
||||||
@ -1944,7 +1966,7 @@ class TestAccountBroker(unittest.TestCase):
|
|||||||
('b', '0000000003.00000-0000000000.00000-0-0')
|
('b', '0000000003.00000-0000000000.00000-0-0')
|
||||||
).digest()
|
).digest()
|
||||||
hashc = \
|
hashc = \
|
||||||
''.join(('%02x' % (ord(a)^ord(b)) for a, b in zip(hasha, hashb)))
|
''.join(('%02x' % (ord(a) ^ ord(b)) for a, b in zip(hasha, hashb)))
|
||||||
self.assertEquals(broker.get_info()['hash'], hashc)
|
self.assertEquals(broker.get_info()['hash'], hashc)
|
||||||
|
|
||||||
def test_merge_items(self):
|
def test_merge_items(self):
|
||||||
|
@ -41,10 +41,13 @@ def lock_parent_directory(filename):
|
|||||||
class FakeRing:
|
class FakeRing:
|
||||||
class Ring:
|
class Ring:
|
||||||
devs = []
|
devs = []
|
||||||
|
|
||||||
def __init__(self, path, reload_time=15, ring_name=None):
|
def __init__(self, path, reload_time=15, ring_name=None):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_part_nodes(self, part):
|
def get_part_nodes(self, part):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def get_more_nodes(self, *args):
|
def get_more_nodes(self, *args):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@ -66,8 +69,10 @@ class FakeRingWithNodes:
|
|||||||
|
|
||||||
def __init__(self, path, reload_time=15, ring_name=None):
|
def __init__(self, path, reload_time=15, ring_name=None):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_part_nodes(self, part):
|
def get_part_nodes(self, part):
|
||||||
return self.devs[:3]
|
return self.devs[:3]
|
||||||
|
|
||||||
def get_more_nodes(self, *args):
|
def get_more_nodes(self, *args):
|
||||||
return (d for d in self.devs[3:])
|
return (d for d in self.devs[3:])
|
||||||
|
|
||||||
@ -75,6 +80,7 @@ class FakeRingWithNodes:
|
|||||||
class FakeProcess:
|
class FakeProcess:
|
||||||
def __init__(self, *codes):
|
def __init__(self, *codes):
|
||||||
self.codes = iter(codes)
|
self.codes = iter(codes)
|
||||||
|
|
||||||
def __call__(self, *args, **kwargs):
|
def __call__(self, *args, **kwargs):
|
||||||
class Failure:
|
class Failure:
|
||||||
def communicate(innerself):
|
def communicate(innerself):
|
||||||
@ -99,11 +105,14 @@ class ReplHttp:
|
|||||||
self.response = response
|
self.response = response
|
||||||
replicated = False
|
replicated = False
|
||||||
host = 'localhost'
|
host = 'localhost'
|
||||||
|
|
||||||
def replicate(self, *args):
|
def replicate(self, *args):
|
||||||
self.replicated = True
|
self.replicated = True
|
||||||
|
|
||||||
class Response:
|
class Response:
|
||||||
status = 200
|
status = 200
|
||||||
data = self.response
|
data = self.response
|
||||||
|
|
||||||
def read(innerself):
|
def read(innerself):
|
||||||
return self.response
|
return self.response
|
||||||
return Response()
|
return Response()
|
||||||
@ -114,6 +123,7 @@ class ChangingMtimesOs:
|
|||||||
self.mtime = 0
|
self.mtime = 0
|
||||||
self.path = self
|
self.path = self
|
||||||
self.basename = os.path.basename
|
self.basename = os.path.basename
|
||||||
|
|
||||||
def getmtime(self, file):
|
def getmtime(self, file):
|
||||||
self.mtime += 1
|
self.mtime += 1
|
||||||
return self.mtime
|
return self.mtime
|
||||||
@ -124,31 +134,41 @@ class FakeBroker:
|
|||||||
get_repl_missing_table = False
|
get_repl_missing_table = False
|
||||||
stub_replication_info = None
|
stub_replication_info = None
|
||||||
db_type = 'container'
|
db_type = 'container'
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def lock(self):
|
def lock(self):
|
||||||
yield True
|
yield True
|
||||||
|
|
||||||
def get_sync(self, *args, **kwargs):
|
def get_sync(self, *args, **kwargs):
|
||||||
return 5
|
return 5
|
||||||
|
|
||||||
def get_syncs(self):
|
def get_syncs(self):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def get_items_since(self, point, *args):
|
def get_items_since(self, point, *args):
|
||||||
if point == 0:
|
if point == 0:
|
||||||
return [{'ROWID': 1}]
|
return [{'ROWID': 1}]
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def merge_syncs(self, *args, **kwargs):
|
def merge_syncs(self, *args, **kwargs):
|
||||||
self.args = args
|
self.args = args
|
||||||
|
|
||||||
def merge_items(self, *args):
|
def merge_items(self, *args):
|
||||||
self.args = args
|
self.args = args
|
||||||
|
|
||||||
def get_replication_info(self):
|
def get_replication_info(self):
|
||||||
if self.get_repl_missing_table:
|
if self.get_repl_missing_table:
|
||||||
raise Exception('no such table')
|
raise Exception('no such table')
|
||||||
if self.stub_replication_info:
|
if self.stub_replication_info:
|
||||||
return self.stub_replication_info
|
return self.stub_replication_info
|
||||||
return {'delete_timestamp': 0, 'put_timestamp': 1, 'count': 0}
|
return {'delete_timestamp': 0, 'put_timestamp': 1, 'count': 0}
|
||||||
|
|
||||||
def reclaim(self, item_timestamp, sync_timestamp):
|
def reclaim(self, item_timestamp, sync_timestamp):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_info(self):
|
def get_info(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -169,20 +189,23 @@ class TestDBReplicator(unittest.TestCase):
|
|||||||
def stub_delete_db(self, object_file):
|
def stub_delete_db(self, object_file):
|
||||||
self.delete_db_calls.append(object_file)
|
self.delete_db_calls.append(object_file)
|
||||||
|
|
||||||
|
|
||||||
def test_repl_connection(self):
|
def test_repl_connection(self):
|
||||||
node = {'ip': '127.0.0.1', 'port': 80, 'device': 'sdb1'}
|
node = {'ip': '127.0.0.1', 'port': 80, 'device': 'sdb1'}
|
||||||
conn = db_replicator.ReplConnection(node, '1234567890', 'abcdefg',
|
conn = db_replicator.ReplConnection(node, '1234567890', 'abcdefg',
|
||||||
logging.getLogger())
|
logging.getLogger())
|
||||||
|
|
||||||
def req(method, path, body, headers):
|
def req(method, path, body, headers):
|
||||||
self.assertEquals(method, 'REPLICATE')
|
self.assertEquals(method, 'REPLICATE')
|
||||||
self.assertEquals(headers['Content-Type'], 'application/json')
|
self.assertEquals(headers['Content-Type'], 'application/json')
|
||||||
|
|
||||||
class Resp:
|
class Resp:
|
||||||
def read(self): return 'data'
|
def read(self):
|
||||||
|
return 'data'
|
||||||
resp = Resp()
|
resp = Resp()
|
||||||
conn.request = req
|
conn.request = req
|
||||||
conn.getresponse = lambda *args: resp
|
conn.getresponse = lambda *args: resp
|
||||||
self.assertEquals(conn.replicate(1, 2, 3), resp)
|
self.assertEquals(conn.replicate(1, 2, 3), resp)
|
||||||
|
|
||||||
def other_req(method, path, body, headers):
|
def other_req(method, path, body, headers):
|
||||||
raise Exception('blah')
|
raise Exception('blah')
|
||||||
conn.request = other_req
|
conn.request = other_req
|
||||||
@ -236,7 +259,8 @@ class TestDBReplicator(unittest.TestCase):
|
|||||||
'created_at': 100, 'put_timestamp': 0,
|
'created_at': 100, 'put_timestamp': 0,
|
||||||
'delete_timestamp': 0,
|
'delete_timestamp': 0,
|
||||||
'metadata': {'Test': ('Value', normalize_timestamp(1))}}
|
'metadata': {'Test': ('Value', normalize_timestamp(1))}}
|
||||||
replicator._http_connect = lambda *args: ReplHttp('{"id": 3, "point": -1}')
|
replicator._http_connect = lambda *args: ReplHttp(
|
||||||
|
'{"id": 3, "point": -1}')
|
||||||
self.assertEquals(replicator._repl_to_node(
|
self.assertEquals(replicator._repl_to_node(
|
||||||
fake_node, FakeBroker(), '0', fake_info), True)
|
fake_node, FakeBroker(), '0', fake_info), True)
|
||||||
|
|
||||||
@ -337,8 +361,10 @@ class TestDBReplicator(unittest.TestCase):
|
|||||||
# self.assertEquals(rpc.dispatch(('drv', 'part', 'hash'), ['op',]
|
# self.assertEquals(rpc.dispatch(('drv', 'part', 'hash'), ['op',]
|
||||||
# ).status_int, 507)
|
# ).status_int, 507)
|
||||||
# rpc.mount_check = False
|
# rpc.mount_check = False
|
||||||
# rpc.rsync_then_merge = lambda drive, db_file, args: self.assertEquals(args, ['test1'])
|
# rpc.rsync_then_merge = lambda drive, db_file,
|
||||||
# rpc.complete_rsync = lambda drive, db_file, args: self.assertEquals(args, ['test2'])
|
# args: self.assertEquals(args, ['test1'])
|
||||||
|
# rpc.complete_rsync = lambda drive, db_file,
|
||||||
|
# args: self.assertEquals(args, ['test2'])
|
||||||
# rpc.dispatch(('drv', 'part', 'hash'), ['rsync_then_merge','test1'])
|
# rpc.dispatch(('drv', 'part', 'hash'), ['rsync_then_merge','test1'])
|
||||||
# rpc.dispatch(('drv', 'part', 'hash'), ['complete_rsync','test2'])
|
# rpc.dispatch(('drv', 'part', 'hash'), ['complete_rsync','test2'])
|
||||||
# rpc.dispatch(('drv', 'part', 'hash'), ['other_op',])
|
# rpc.dispatch(('drv', 'part', 'hash'), ['other_op',])
|
||||||
@ -364,4 +390,3 @@ class TestDBReplicator(unittest.TestCase):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ import re
|
|||||||
import unittest
|
import unittest
|
||||||
import swift
|
import swift
|
||||||
|
|
||||||
|
|
||||||
class TestVersioning(unittest.TestCase):
|
class TestVersioning(unittest.TestCase):
|
||||||
def test_canonical_version_is_clean(self):
|
def test_canonical_version_is_clean(self):
|
||||||
"""Ensure that a non-clean canonical_version never happens"""
|
"""Ensure that a non-clean canonical_version never happens"""
|
||||||
|
Loading…
Reference in New Issue
Block a user