From eadab846b32e78644925fec707c6a048d959c3a8 Mon Sep 17 00:00:00 2001 From: Kota Tsuyuzaki Date: Thu, 4 Aug 2016 23:34:40 -0700 Subject: [PATCH] Remove unnecessary open call and related vars in unit tests Since the methods touching exisiting file is mocked, we don't have to open the file. (if it is needed, we should close at first anyway) And cleanup unecessary vars/imports that is used for making the file path. This patch is a followup on: https://review.openstack.org/#/c/350471/ Change-Id: I8fbc0b5b9a01782b6da5a7dd674f52d4b566ca5c --- test/unit/account/test_server.py | 15 +-------------- test/unit/container/test_server.py | 14 +------------- 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/test/unit/account/test_server.py b/test/unit/account/test_server.py index a26a2832a2..b4d99f77f7 100644 --- a/test/unit/account/test_server.py +++ b/test/unit/account/test_server.py @@ -33,8 +33,7 @@ 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, - mkdirs, storage_directory) +from swift.common.utils import (normalize_timestamp, replication, public) 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 @@ -172,12 +171,6 @@ class TestAccountController(unittest.TestCase): self.assertEqual(resp.status_int, 507) 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'), - 'a' + '.db') - open(db_file, 'w') - def fake_rsync_then_merge(self, drive, db_file, args): return HTTPNoContent() @@ -193,12 +186,6 @@ class TestAccountController(unittest.TestCase): 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 diff --git a/test/unit/container/test_server.py b/test/unit/container/test_server.py index 57bed853a8..092fee7932 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, - storage_directory, lock_parent_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 @@ -1269,12 +1269,6 @@ class TestContainerController(unittest.TestCase): self.assertEqual(resp.status_int, 507) 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'), - 'a' + '.db') - open(db_file, 'w') - def fake_rsync_then_merge(self, drive, db_file, args): return HTTPNoContent() @@ -1290,12 +1284,6 @@ class TestContainerController(unittest.TestCase): 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."