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
This commit is contained in:
Kota Tsuyuzaki 2016-08-04 23:34:40 -07:00
parent b1b410902d
commit eadab846b3
2 changed files with 2 additions and 27 deletions

View File

@ -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

View File

@ -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."