From b1b410902d3af011c65569a0ba94a39148f8265e Mon Sep 17 00:00:00 2001
From: zheng yin <yin.zheng@easystack.cn>
Date: Wed, 3 Aug 2016 17:11:25 +0800
Subject: [PATCH] Add unit case

"op" has three judgments in ReplicatorRpc.dispatch, rsync_then_merge,complete_rsync
and other. But it only has two times judgments,including rsync_then_merge and other
in test_REPLICATE_works, so I add complete_rsync in test_account and test_container

Change-Id: I8277b556062dd6b30bf85dedd636d56517f10d8d
---
 test/unit/account/test_server.py   | 28 +++++++++++++++++++++++++++-
 test/unit/container/test_server.py | 26 +++++++++++++++++++++++++-
 2 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/test/unit/account/test_server.py b/test/unit/account/test_server.py
index d2e7c087ef..a26a2832a2 100644
--- a/test/unit/account/test_server.py
+++ b/test/unit/account/test_server.py
@@ -171,7 +171,7 @@ class TestAccountController(unittest.TestCase):
             resp = req.get_response(self.account_controller)
         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'))
         db_file = os.path.join(self.testdir, 'sda1',
                                storage_directory('account', 'p', 'a'),
@@ -192,6 +192,32 @@ class TestAccountController(unittest.TestCase):
             resp = req.get_response(self.controller)
         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
         wsgi_input_valuerror = '["sync" : sync, "-1"]'
         inbuf1 = WsgiBytesIO(wsgi_input_valuerror)
diff --git a/test/unit/container/test_server.py b/test/unit/container/test_server.py
index 706f3c3366..57bed853a8 100644
--- a/test/unit/container/test_server.py
+++ b/test/unit/container/test_server.py
@@ -1268,7 +1268,7 @@ class TestContainerController(unittest.TestCase):
             resp = req.get_response(self.container_controller)
         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'))
         db_file = os.path.join(self.testdir, 'sda1',
                                storage_directory('containers', 'p', 'a'),
@@ -1289,6 +1289,30 @@ class TestContainerController(unittest.TestCase):
             resp = req.get_response(self.controller)
         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
         wsgi_input_valuerror = '["sync" : sync, "-1"]'
         inbuf1 = WsgiBytesIO(wsgi_input_valuerror)