From 2a58b1efa4b70505bfa01b3fe410a25ea2fa799b Mon Sep 17 00:00:00 2001 From: Christian Schwede Date: Wed, 31 Aug 2016 12:49:07 +0000 Subject: [PATCH] More Test[Account|Container]Controller test updates Added another test that tries to replicate using an unknown sync method, with and without an existing DB file. Change-Id: I09a86615f012e4341268ea30cbc06099528f896b --- test/unit/account/test_server.py | 28 +++++++++++++++++++++++++++- test/unit/container/test_server.py | 27 ++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/test/unit/account/test_server.py b/test/unit/account/test_server.py index b4d99f77f7..38ded6a97b 100644 --- a/test/unit/account/test_server.py +++ b/test/unit/account/test_server.py @@ -33,7 +33,8 @@ from swift import __version__ as swift_version from swift.common.swob import (Request, WsgiBytesIO, HTTPNoContent) from swift.common import constraints from swift.account.server import AccountController -from swift.common.utils import (normalize_timestamp, replication, public) +from swift.common.utils import (normalize_timestamp, replication, public, + mkdirs, storage_directory) from swift.common.request_helpers import get_sys_meta_prefix from test.unit import patch_policies, debug_logger from swift.common.storage_policy import StoragePolicy, POLICIES @@ -212,6 +213,31 @@ class TestAccountController(unittest.TestCase): resp = req.get_response(self.controller) self.assertEqual(resp.status_int, 400) + def test_REPLICATE_unknown_sync(self): + # First without existing DB file + req = Request.blank('/sda1/p/a/', + environ={'REQUEST_METHOD': 'REPLICATE'}, + headers={}) + json_string = '["unknown_sync", "a.db"]' + inbuf = WsgiBytesIO(json_string) + req.environ['wsgi.input'] = inbuf + resp = req.get_response(self.controller) + self.assertEqual(resp.status_int, 404) + + mkdirs(os.path.join(self.testdir, 'sda1', 'accounts', 'p', 'a', 'a')) + db_file = os.path.join(self.testdir, 'sda1', + storage_directory('accounts', 'p', 'a'), + 'a' + '.db') + open(db_file, 'w') + req = Request.blank('/sda1/p/a/', + environ={'REQUEST_METHOD': 'REPLICATE'}, + headers={}) + json_string = '["unknown_sync", "a.db"]' + inbuf = WsgiBytesIO(json_string) + req.environ['wsgi.input'] = inbuf + resp = req.get_response(self.controller) + self.assertEqual(resp.status_int, 500) + def test_HEAD_not_found(self): # Test the case in which account does not exist (can be recreated) req = Request.blank('/sda1/p/a', environ={'REQUEST_METHOD': 'HEAD'}) diff --git a/test/unit/container/test_server.py b/test/unit/container/test_server.py index 092fee7932..b322ae3c41 100644 --- a/test/unit/container/test_server.py +++ b/test/unit/container/test_server.py @@ -40,7 +40,7 @@ import swift.container from swift.container import server as container_server from swift.common import constraints from swift.common.utils import (Timestamp, mkdirs, public, replication, - lock_parent_directory) + storage_directory, lock_parent_directory) from test.unit import fake_http_connect, debug_logger from swift.common.storage_policy import (POLICIES, StoragePolicy) from swift.common.request_helpers import get_sys_meta_prefix @@ -1308,6 +1308,31 @@ class TestContainerController(unittest.TestCase): resp = req.get_response(self.controller) self.assertEqual(resp.status_int, 400) + def test_REPLICATE_unknown_sync(self): + # First without existing DB file + req = Request.blank('/sda1/p/a/', + environ={'REQUEST_METHOD': 'REPLICATE'}, + headers={}) + json_string = '["unknown_sync", "a.db"]' + inbuf = WsgiBytesIO(json_string) + req.environ['wsgi.input'] = inbuf + resp = req.get_response(self.controller) + self.assertEqual(resp.status_int, 404) + + 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') + req = Request.blank('/sda1/p/a/', + environ={'REQUEST_METHOD': 'REPLICATE'}, + headers={}) + json_string = '["unknown_sync", "a.db"]' + inbuf = WsgiBytesIO(json_string) + req.environ['wsgi.input'] = inbuf + resp = req.get_response(self.controller) + self.assertEqual(resp.status_int, 500) + def test_DELETE(self): req = Request.blank( '/sda1/p/a/c',