Merge "Add unit case"

This commit is contained in:
Jenkins 2016-08-31 13:57:12 +00:00 committed by Gerrit Code Review
commit db5fd6470a
2 changed files with 52 additions and 2 deletions

View File

@ -171,7 +171,7 @@ class TestAccountController(unittest.TestCase):
resp = req.get_response(self.account_controller) resp = req.get_response(self.account_controller)
self.assertEqual(resp.status_int, 507) self.assertEqual(resp.status_int, 507)
def test_REPLICATE_works(self): def test_REPLICATE_rsync_then_merge_works(self):
mkdirs(os.path.join(self.testdir, 'sda1', 'account', 'p', 'a', 'a')) mkdirs(os.path.join(self.testdir, 'sda1', 'account', 'p', 'a', 'a'))
db_file = os.path.join(self.testdir, 'sda1', db_file = os.path.join(self.testdir, 'sda1',
storage_directory('account', 'p', 'a'), storage_directory('account', 'p', 'a'),
@ -192,6 +192,32 @@ class TestAccountController(unittest.TestCase):
resp = req.get_response(self.controller) resp = req.get_response(self.controller)
self.assertEqual(resp.status_int, 204) self.assertEqual(resp.status_int, 204)
def test_REPLICATE_complete_rsync_works(self):
mkdirs(os.path.join(self.testdir, 'sda1', 'account', 'p', 'a', 'a'))
db_file = os.path.join(self.testdir, 'sda1',
storage_directory('account', 'p', 'a'),
'a' + '.db')
open(db_file, 'w')
def fake_complete_rsync(self, drive, db_file, args):
return HTTPNoContent()
# check complete_rsync
with mock.patch("swift.common.db_replicator.ReplicatorRpc."
"complete_rsync", fake_complete_rsync):
req = Request.blank('/sda1/p/a/',
environ={'REQUEST_METHOD': 'REPLICATE'},
headers={})
json_string = '["complete_rsync", "a.db"]'
inbuf = WsgiBytesIO(json_string)
req.environ['wsgi.input'] = inbuf
resp = req.get_response(self.controller)
self.assertEqual(resp.status_int, 204)
def test_REPLICATE_value_error_works(self):
req = Request.blank('/sda1/p/a/',
environ={'REQUEST_METHOD': 'REPLICATE'},
headers={})
# check valuerror # check valuerror
wsgi_input_valuerror = '["sync" : sync, "-1"]' wsgi_input_valuerror = '["sync" : sync, "-1"]'
inbuf1 = WsgiBytesIO(wsgi_input_valuerror) inbuf1 = WsgiBytesIO(wsgi_input_valuerror)

View File

@ -1285,7 +1285,7 @@ class TestContainerController(unittest.TestCase):
resp = req.get_response(self.container_controller) resp = req.get_response(self.container_controller)
self.assertEqual(resp.status_int, 507) self.assertEqual(resp.status_int, 507)
def test_REPLICATE_works(self): def test_REPLICATE_rsync_then_merge_works(self):
mkdirs(os.path.join(self.testdir, 'sda1', 'containers', 'p', 'a', 'a')) mkdirs(os.path.join(self.testdir, 'sda1', 'containers', 'p', 'a', 'a'))
db_file = os.path.join(self.testdir, 'sda1', db_file = os.path.join(self.testdir, 'sda1',
storage_directory('containers', 'p', 'a'), storage_directory('containers', 'p', 'a'),
@ -1306,6 +1306,30 @@ class TestContainerController(unittest.TestCase):
resp = req.get_response(self.controller) resp = req.get_response(self.controller)
self.assertEqual(resp.status_int, 204) self.assertEqual(resp.status_int, 204)
def test_REPLICATE_complete_rsync_works(self):
mkdirs(os.path.join(self.testdir, 'sda1', 'containers', 'p', 'a', 'a'))
db_file = os.path.join(self.testdir, 'sda1',
storage_directory('containers', 'p', 'a'),
'a' + '.db')
open(db_file, 'w')
def fake_complete_rsync(self, drive, db_file, args):
return HTTPNoContent()
with mock.patch("swift.container.replicator.ContainerReplicatorRpc."
"complete_rsync", fake_complete_rsync):
req = Request.blank('/sda1/p/a/',
environ={'REQUEST_METHOD': 'REPLICATE'},
headers={})
json_string = '["complete_rsync", "a.db"]'
inbuf = WsgiBytesIO(json_string)
req.environ['wsgi.input'] = inbuf
resp = req.get_response(self.controller)
self.assertEqual(resp.status_int, 204)
def test_REPLICATE_value_error_works(self):
req = Request.blank('/sda1/p/a/',
environ={'REQUEST_METHOD': 'REPLICATE'},
headers={})
# check valuerror # check valuerror
wsgi_input_valuerror = '["sync" : sync, "-1"]' wsgi_input_valuerror = '["sync" : sync, "-1"]'
inbuf1 = WsgiBytesIO(wsgi_input_valuerror) inbuf1 = WsgiBytesIO(wsgi_input_valuerror)