Pep8 unit test modules for hacking and one liners (4 of 12)

Address all the "hacking" lines that are flagged, and all the modules
that just have one item flagged.

Change-Id: I372a4bdf9c7748f73e38c4fd55e5954f1afade5b
Signed-off-by: Peter Portante <peter.portante@redhat.com>
This commit is contained in:
Peter Portante 2013-08-31 22:36:58 -04:00
parent c57f526f58
commit c067abd21e
18 changed files with 77 additions and 97 deletions

View File

@ -17,6 +17,7 @@ from eventlet import sleep, Timeout
import logging.handlers import logging.handlers
from httplib import HTTPException from httplib import HTTPException
class FakeRing(object): class FakeRing(object):
def __init__(self, replicas=3, max_more_nodes=0): def __init__(self, replicas=3, max_more_nodes=0):

View File

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# TODO: Tests # TODO(creiht): Tests
import unittest import unittest

View File

@ -29,15 +29,15 @@ from swift.common.utils import normalize_timestamp, replication, public
class TestAccountController(unittest.TestCase): class TestAccountController(unittest.TestCase):
""" Test swift.account_server.AccountController """ """Test swift.account.server.AccountController"""
def setUp(self): def setUp(self):
""" Set up for testing swift.account_server.AccountController """ """Set up for testing swift.account.server.AccountController"""
self.testdir = os.path.join(os.path.dirname(__file__), 'account_server') self.testdir = os.path.join(os.path.dirname(__file__), 'account_server')
self.controller = AccountController( self.controller = AccountController(
{'devices': self.testdir, 'mount_check': 'false'}) {'devices': self.testdir, 'mount_check': 'false'})
def tearDown(self): def tearDown(self):
""" Tear down for testing swift.account_server.AccountController """ """Tear down for testing swift.account.server.AccountController"""
try: try:
rmtree(self.testdir) rmtree(self.testdir)
except OSError, err: except OSError, err:
@ -1341,10 +1341,7 @@ class TestAccountController(unittest.TestCase):
self.assertEquals(resp.charset, 'utf-8') self.assertEquals(resp.charset, 'utf-8')
def test_serv_reserv(self): def test_serv_reserv(self):
""" # Test replication_server flag was set from configuration file.
Test replication_server flag
was set from configuration file.
"""
conf = {'devices': self.testdir, 'mount_check': 'false'} conf = {'devices': self.testdir, 'mount_check': 'false'}
self.assertEquals(AccountController(conf).replication_server, None) self.assertEquals(AccountController(conf).replication_server, None)
for val in [True, '1', 'True', 'true']: for val in [True, '1', 'True', 'true']:
@ -1355,7 +1352,7 @@ class TestAccountController(unittest.TestCase):
self.assertFalse(AccountController(conf).replication_server) self.assertFalse(AccountController(conf).replication_server)
def test_list_allowed_methods(self): def test_list_allowed_methods(self):
""" Test list of allowed_methods """ # Test list of allowed_methods
obj_methods = ['DELETE', 'PUT', 'HEAD', 'GET', 'POST'] obj_methods = ['DELETE', 'PUT', 'HEAD', 'GET', 'POST']
repl_methods = ['REPLICATE'] repl_methods = ['REPLICATE']
for method_name in obj_methods: for method_name in obj_methods:
@ -1366,10 +1363,8 @@ class TestAccountController(unittest.TestCase):
self.assertEquals(method.replication, True) self.assertEquals(method.replication, True)
def test_correct_allowed_method(self): def test_correct_allowed_method(self):
""" # Test correct work for allowed method using
Test correct work for allowed method using # swift.account.server.AccountController.__call__
swift.account_server.AccountController.__call__
"""
inbuf = StringIO() inbuf = StringIO()
errbuf = StringIO() errbuf = StringIO()
outbuf = StringIO() outbuf = StringIO()
@ -1378,7 +1373,7 @@ class TestAccountController(unittest.TestCase):
'replication_server': 'false'}) 'replication_server': 'false'})
def start_response(*args): def start_response(*args):
""" Sends args to outbuf """ """Sends args to outbuf"""
outbuf.writelines(args) outbuf.writelines(args)
method = 'PUT' method = 'PUT'
@ -1406,10 +1401,8 @@ class TestAccountController(unittest.TestCase):
self.assertEqual(response, method_res) self.assertEqual(response, method_res)
def test_not_allowed_method(self): def test_not_allowed_method(self):
""" # Test correct work for NOT allowed method using
Test correct work for NOT allowed method using # swift.account.server.AccountController.__call__
swift.account_server.AccountController.__call__
"""
inbuf = StringIO() inbuf = StringIO()
errbuf = StringIO() errbuf = StringIO()
outbuf = StringIO() outbuf = StringIO()
@ -1418,7 +1411,7 @@ class TestAccountController(unittest.TestCase):
'replication_server': 'false'}) 'replication_server': 'false'})
def start_response(*args): def start_response(*args):
""" Sends args to outbuf """ """Sends args to outbuf"""
outbuf.writelines(args) outbuf.writelines(args)
method = 'PUT' method = 'PUT'

View File

@ -338,7 +338,7 @@ class TestAuth(unittest.TestCase):
req = self._make_request('/v1/AUTH_admin', req = self._make_request('/v1/AUTH_admin',
headers={'X-Auth-Token': 'AUTH_t'}) headers={'X-Auth-Token': 'AUTH_t'})
cache_key = 'AUTH_/token/AUTH_t' cache_key = 'AUTH_/token/AUTH_t'
cache_entry = (time()+3600, '.reseller_admin') cache_entry = (time() + 3600, '.reseller_admin')
req.environ['swift.cache'].set(cache_key, cache_entry) req.environ['swift.cache'].set(cache_key, cache_entry)
req.get_response(self.test_auth) req.get_response(self.test_auth)
self.assertTrue(req.environ.get('reseller_request', False)) self.assertTrue(req.environ.get('reseller_request', False))

View File

@ -565,7 +565,7 @@ class TestRingBuilder(unittest.TestCase):
self.assertEquals(counts[3], 256) self.assertEquals(counts[3], 256)
def test_add_rebalance_add_rebalance_delete_rebalance(self): def test_add_rebalance_add_rebalance_delete_rebalance(self):
""" Test for https://bugs.launchpad.net/swift/+bug/845952 """ # Test for https://bugs.launchpad.net/swift/+bug/845952
# min_part of 0 to allow for rapid rebalancing # min_part of 0 to allow for rapid rebalancing
rb = ring.RingBuilder(8, 3, 0) rb = ring.RingBuilder(8, 3, 0)
rb.add_dev({'id': 0, 'region': 0, 'zone': 0, 'weight': 1, rb.add_dev({'id': 0, 'region': 0, 'zone': 0, 'weight': 1,

View File

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# TODO: Tests # TODO(gholt): Tests
import unittest import unittest

View File

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# TODO: Test kill_children signal handlers # TODO(clayg): Test kill_children signal handlers
import os import os
import unittest import unittest
@ -83,9 +83,7 @@ class TestRunDaemon(unittest.TestCase):
self.assertEquals(d.once_called, True) self.assertEquals(d.once_called, True)
def test_run_daemon(self): def test_run_daemon(self):
sample_conf = """[my-daemon] sample_conf = "[my-daemon]\nuser = %s\n" % getuser()
user = %s
""" % getuser()
with tmpfile(sample_conf) as conf_file: with tmpfile(sample_conf) as conf_file:
with patch.dict('os.environ', {'TZ': ''}): with patch.dict('os.environ', {'TZ': ''}):
daemon.run_daemon(MyDaemon, conf_file) daemon.run_daemon(MyDaemon, conf_file)

View File

@ -623,7 +623,7 @@ class TestDatabaseBroker(unittest.TestCase):
class TestContainerBroker(unittest.TestCase): class TestContainerBroker(unittest.TestCase):
""" Tests for swift.common.db.ContainerBroker """ """Tests for swift.common.db.ContainerBroker"""
def test_creation(self): def test_creation(self):
# Test swift.common.db.ContainerBroker.__init__ # Test swift.common.db.ContainerBroker.__init__
@ -1781,7 +1781,7 @@ class TestContainerBrokerBeforeXSync(TestContainerBroker):
class TestAccountBroker(unittest.TestCase): class TestAccountBroker(unittest.TestCase):
""" Tests for swift.common.db.AccountBroker """ """Tests for swift.common.db.AccountBroker"""
def test_creation(self): def test_creation(self):
# Test swift.common.db.AccountBroker.__init__ # Test swift.common.db.AccountBroker.__init__

View File

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# TODO: Tests # TODO(creiht): Tests
import unittest import unittest

View File

@ -1602,7 +1602,7 @@ class TestManager(unittest.TestCase):
manager.Server = _orig_server manager.Server = _orig_server
manager.watch_server_pids = _orig_watch_server_pids manager.watch_server_pids = _orig_watch_server_pids
# TODO: more tests # TODO(clayg): more tests
def test_shutdown(self): def test_shutdown(self):
m = manager.Manager(['test']) m = manager.Manager(['test'])
m.stop_was_called = False m.stop_was_called = False

View File

@ -1,4 +1,4 @@
# -*- coding: utf8 -*- # -*- coding:utf-8 -*-
# Copyright (c) 2010-2012 OpenStack, LLC. # Copyright (c) 2010-2012 OpenStack, LLC.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
""" Tests for swift.common.utils """ """Tests for swift.common.utils"""
from __future__ import with_statement from __future__ import with_statement
import logging import logging
@ -45,6 +45,7 @@ class ExplodingMockMemcached(object):
def close(self): def close(self):
pass pass
class MockMemcached(object): class MockMemcached(object):
def __init__(self): def __init__(self):
@ -139,7 +140,7 @@ class MockMemcached(object):
class TestMemcached(unittest.TestCase): class TestMemcached(unittest.TestCase):
""" Tests for swift.common.memcached""" """Tests for swift.common.memcached"""
def test_get_conns(self): def test_get_conns(self):
sock1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

View File

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
""" Tests for swift.common.utils """ """Tests for swift.common.utils"""
from __future__ import with_statement from __future__ import with_statement
from test.unit import temptree from test.unit import temptree
@ -130,14 +130,14 @@ def reset_loggers():
class TestUtils(unittest.TestCase): class TestUtils(unittest.TestCase):
""" Tests for swift.common.utils """ """Tests for swift.common.utils """
def setUp(self): def setUp(self):
utils.HASH_PATH_SUFFIX = 'endcap' utils.HASH_PATH_SUFFIX = 'endcap'
utils.HASH_PATH_PREFIX = 'startcap' utils.HASH_PATH_PREFIX = 'startcap'
def test_normalize_timestamp(self): def test_normalize_timestamp(self):
""" Test swift.common.utils.normalize_timestamp """ # Test swift.common.utils.normalize_timestamp
self.assertEquals(utils.normalize_timestamp('1253327593.48174'), self.assertEquals(utils.normalize_timestamp('1253327593.48174'),
"1253327593.48174") "1253327593.48174")
self.assertEquals(utils.normalize_timestamp(1253327593.48174), self.assertEquals(utils.normalize_timestamp(1253327593.48174),
@ -158,7 +158,7 @@ class TestUtils(unittest.TestCase):
self.assertRaises(ValueError, utils.normalize_timestamp, 'abc') self.assertRaises(ValueError, utils.normalize_timestamp, 'abc')
def test_backwards(self): def test_backwards(self):
""" Test swift.common.utils.backward """ # Test swift.common.utils.backward
# The lines are designed so that the function would encounter # The lines are designed so that the function would encounter
# all of the boundary conditions and typical conditions. # all of the boundary conditions and typical conditions.
@ -215,7 +215,7 @@ class TestUtils(unittest.TestCase):
os.unlink(testroot) os.unlink(testroot)
def test_split_path(self): def test_split_path(self):
""" Test swift.common.utils.split_account_path """ # Test swift.common.utils.split_account_path
self.assertRaises(ValueError, utils.split_path, '') self.assertRaises(ValueError, utils.split_path, '')
self.assertRaises(ValueError, utils.split_path, '/') self.assertRaises(ValueError, utils.split_path, '/')
self.assertRaises(ValueError, utils.split_path, '//') self.assertRaises(ValueError, utils.split_path, '//')
@ -249,7 +249,7 @@ class TestUtils(unittest.TestCase):
self.assertEquals(str(err), 'Invalid path: o%0An%20e') self.assertEquals(str(err), 'Invalid path: o%0An%20e')
def test_validate_device_partition(self): def test_validate_device_partition(self):
""" Test swift.common.utils.validate_device_partition """ # Test swift.common.utils.validate_device_partition
utils.validate_device_partition('foo', 'bar') utils.validate_device_partition('foo', 'bar')
self.assertRaises(ValueError, self.assertRaises(ValueError,
utils.validate_device_partition, '', '') utils.validate_device_partition, '', '')
@ -279,7 +279,7 @@ class TestUtils(unittest.TestCase):
self.assertEquals(str(err), 'Invalid partition: o%0An%20e') self.assertEquals(str(err), 'Invalid partition: o%0An%20e')
def test_NullLogger(self): def test_NullLogger(self):
""" Test swift.common.utils.NullLogger """ # Test swift.common.utils.NullLogger
sio = StringIO() sio = StringIO()
nl = utils.NullLogger() nl = utils.NullLogger()
nl.write('test') nl.write('test')

View File

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
""" Tests for swift.common.wsgi """ """Tests for swift.common.wsgi"""
from __future__ import with_statement from __future__ import with_statement
import errno import errno
@ -66,7 +66,7 @@ def _fake_rings(tmpdir):
class TestWSGI(unittest.TestCase): class TestWSGI(unittest.TestCase):
""" Tests for swift.common.wsgi """ """Tests for swift.common.wsgi"""
def setUp(self): def setUp(self):
utils.HASH_PATH_PREFIX = 'startcap' utils.HASH_PATH_PREFIX = 'startcap'

View File

@ -44,9 +44,9 @@ def save_globals():
class TestContainerController(unittest.TestCase): class TestContainerController(unittest.TestCase):
""" Test swift.container_server.ContainerController """ """Test swift.container.server.ContainerController"""
def setUp(self): def setUp(self):
""" Set up for testing swift.object_server.ObjectController """ """Set up for testing swift.object_server.ObjectController"""
self.testdir = os.path.join(mkdtemp(), self.testdir = os.path.join(mkdtemp(),
'tmp_test_object_server_ObjectController') 'tmp_test_object_server_ObjectController')
mkdirs(self.testdir) mkdirs(self.testdir)
@ -57,7 +57,7 @@ class TestContainerController(unittest.TestCase):
{'devices': self.testdir, 'mount_check': 'false'}) {'devices': self.testdir, 'mount_check': 'false'})
def tearDown(self): def tearDown(self):
""" Tear down for testing swift.object_server.ObjectController """ """Tear down for testing swift.object_server.ObjectController"""
rmtree(os.path.dirname(self.testdir), ignore_errors=1) rmtree(os.path.dirname(self.testdir), ignore_errors=1)
def test_acl_container(self): def test_acl_container(self):
@ -1468,10 +1468,7 @@ class TestContainerController(unittest.TestCase):
'x-trans-id': '-'})}) 'x-trans-id': '-'})})
def test_serv_reserv(self): def test_serv_reserv(self):
""" # Test replication_server flag was set from configuration file.
Test replication_server flag
was set from configuration file.
"""
container_controller = container_server.ContainerController container_controller = container_server.ContainerController
conf = {'devices': self.testdir, 'mount_check': 'false'} conf = {'devices': self.testdir, 'mount_check': 'false'}
self.assertEquals(container_controller(conf).replication_server, None) self.assertEquals(container_controller(conf).replication_server, None)
@ -1483,7 +1480,7 @@ class TestContainerController(unittest.TestCase):
self.assertFalse(container_controller(conf).replication_server) self.assertFalse(container_controller(conf).replication_server)
def test_list_allowed_methods(self): def test_list_allowed_methods(self):
""" Test list of allowed_methods """ # Test list of allowed_methods
obj_methods = ['DELETE', 'PUT', 'HEAD', 'GET', 'POST'] obj_methods = ['DELETE', 'PUT', 'HEAD', 'GET', 'POST']
repl_methods = ['REPLICATE'] repl_methods = ['REPLICATE']
for method_name in obj_methods: for method_name in obj_methods:
@ -1494,10 +1491,8 @@ class TestContainerController(unittest.TestCase):
self.assertEquals(method.replication, True) self.assertEquals(method.replication, True)
def test_correct_allowed_method(self): def test_correct_allowed_method(self):
""" # Test correct work for allowed method using
Test correct work for allowed method using # swift.container.server.ContainerController.__call__
swift.container_server.ContainerController.__call__
"""
inbuf = StringIO() inbuf = StringIO()
errbuf = StringIO() errbuf = StringIO()
outbuf = StringIO() outbuf = StringIO()
@ -1506,7 +1501,7 @@ class TestContainerController(unittest.TestCase):
'replication_server': 'false'}) 'replication_server': 'false'})
def start_response(*args): def start_response(*args):
""" Sends args to outbuf """ """Sends args to outbuf"""
outbuf.writelines(args) outbuf.writelines(args)
method = 'PUT' method = 'PUT'
@ -1533,10 +1528,8 @@ class TestContainerController(unittest.TestCase):
self.assertEqual(response, method_res) self.assertEqual(response, method_res)
def test_not_allowed_method(self): def test_not_allowed_method(self):
""" # Test correct work for NOT allowed method using
Test correct work for NOT allowed method using # swift.container.server.ContainerController.__call__
swift.container_server.ContainerController.__call__
"""
inbuf = StringIO() inbuf = StringIO()
errbuf = StringIO() errbuf = StringIO()
outbuf = StringIO() outbuf = StringIO()
@ -1545,7 +1538,7 @@ class TestContainerController(unittest.TestCase):
'replication_server': 'false'}) 'replication_server': 'false'})
def start_response(*args): def start_response(*args):
""" Sends args to outbuf """ """Sends args to outbuf"""
outbuf.writelines(args) outbuf.writelines(args)
method = 'PUT' method = 'PUT'

View File

@ -274,7 +274,8 @@ class TestAuditor(unittest.TestCase):
if with_ts: if with_ts:
name_hash = hash_path('a', 'c', 'o') name_hash = hash_path('a', 'c', 'o')
dir_path = os.path.join(self.devices, 'sda', dir_path = os.path.join(
self.devices, 'sda',
storage_directory(DATADIR, '0', name_hash)) storage_directory(DATADIR, '0', name_hash))
ts_file_path = os.path.join(dir_path, '99999.ts') ts_file_path = os.path.join(dir_path, '99999.ts')
if not os.path.exists(dir_path): if not os.path.exists(dir_path):

View File

@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
""" Tests for swift.obj.diskfile """ """Tests for swift.obj.diskfile"""
from __future__ import with_statement from __future__ import with_statement
@ -353,14 +353,14 @@ class TestDiskFile(unittest.TestCase):
"""Test swift.obj.diskfile.DiskFile""" """Test swift.obj.diskfile.DiskFile"""
def setUp(self): def setUp(self):
""" Set up for testing swift.obj.diskfile""" """Set up for testing swift.obj.diskfile"""
self.testdir = os.path.join(mkdtemp(), 'tmp_test_obj_server_DiskFile') self.testdir = os.path.join(mkdtemp(), 'tmp_test_obj_server_DiskFile')
mkdirs(os.path.join(self.testdir, 'sda1', 'tmp')) mkdirs(os.path.join(self.testdir, 'sda1', 'tmp'))
self._orig_tpool_exc = tpool.execute self._orig_tpool_exc = tpool.execute
tpool.execute = lambda f, *args, **kwargs: f(*args, **kwargs) tpool.execute = lambda f, *args, **kwargs: f(*args, **kwargs)
def tearDown(self): def tearDown(self):
""" Tear down for testing swift.obj.diskfile""" """Tear down for testing swift.obj.diskfile"""
rmtree(os.path.dirname(self.testdir)) rmtree(os.path.dirname(self.testdir))
tpool.execute = self._orig_tpool_exc tpool.execute = self._orig_tpool_exc

View File

@ -123,7 +123,7 @@ class TestObjectExpirer(TestCase):
self.deleted_objects = {} self.deleted_objects = {}
def delete_object(self, actual_obj, timestamp, container, obj): def delete_object(self, actual_obj, timestamp, container, obj):
if not container in self.deleted_objects: if container not in self.deleted_objects:
self.deleted_objects[container] = set() self.deleted_objects[container] = set()
self.deleted_objects[container].add(obj) self.deleted_objects[container].add(obj)

View File

@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
""" Tests for swift.obj.server """ """Tests for swift.obj.server"""
import cPickle as pickle import cPickle as pickle
import operator import operator
@ -42,10 +42,10 @@ from swift.common.swob import Request, HeaderKeyDict
class TestObjectController(unittest.TestCase): class TestObjectController(unittest.TestCase):
""" Test swift.obj.server.ObjectController """ """Test swift.obj.server.ObjectController"""
def setUp(self): def setUp(self):
""" Set up for testing swift.object_server.ObjectController """ """Set up for testing swift.object.server.ObjectController"""
utils.HASH_PATH_SUFFIX = 'endcap' utils.HASH_PATH_SUFFIX = 'endcap'
utils.HASH_PATH_PREFIX = 'startcap' utils.HASH_PATH_PREFIX = 'startcap'
self.testdir = \ self.testdir = \
@ -58,7 +58,7 @@ class TestObjectController(unittest.TestCase):
tpool.execute = lambda f, *args, **kwargs: f(*args, **kwargs) tpool.execute = lambda f, *args, **kwargs: f(*args, **kwargs)
def tearDown(self): def tearDown(self):
""" Tear down for testing swift.object_server.ObjectController """ """Tear down for testing swift.object.server.ObjectController"""
rmtree(os.path.dirname(self.testdir)) rmtree(os.path.dirname(self.testdir))
tpool.execute = self._orig_tpool_exc tpool.execute = self._orig_tpool_exc
@ -110,7 +110,7 @@ class TestObjectController(unittest.TestCase):
self.assertEquals(resp.status_int, 204) self.assertEquals(resp.status_int, 204)
def test_POST_update_meta(self): def test_POST_update_meta(self):
""" Test swift.object_server.ObjectController.POST """ # Test swift.obj.server.ObjectController.POST
original_headers = self.object_controller.allowed_headers original_headers = self.object_controller.allowed_headers
test_headers = 'content-encoding foo bar'.split() test_headers = 'content-encoding foo bar'.split()
self.object_controller.allowed_headers = set(test_headers) self.object_controller.allowed_headers = set(test_headers)
@ -348,7 +348,7 @@ class TestObjectController(unittest.TestCase):
object_server.http_connect = old_http_connect object_server.http_connect = old_http_connect
def test_POST_quarantine_zbyte(self): def test_POST_quarantine_zbyte(self):
""" Test swift.object_server.ObjectController.GET """ # Test swift.obj.server.ObjectController.GET
timestamp = normalize_timestamp(time()) timestamp = normalize_timestamp(time())
req = Request.blank('/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, req = Request.blank('/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
headers={'X-Timestamp': timestamp, headers={'X-Timestamp': timestamp,
@ -613,7 +613,7 @@ class TestObjectController(unittest.TestCase):
object_server.http_connect = old_http_connect object_server.http_connect = old_http_connect
def test_HEAD(self): def test_HEAD(self):
""" Test swift.object_server.ObjectController.HEAD """ # Test swift.obj.server.ObjectController.HEAD
req = Request.blank('/sda1/p/a/c', environ={'REQUEST_METHOD': 'HEAD'}) req = Request.blank('/sda1/p/a/c', environ={'REQUEST_METHOD': 'HEAD'})
resp = req.get_response(self.object_controller) resp = req.get_response(self.object_controller)
self.assertEquals(resp.status_int, 400) self.assertEquals(resp.status_int, 400)
@ -678,7 +678,7 @@ class TestObjectController(unittest.TestCase):
self.assertEquals(resp.status_int, 404) self.assertEquals(resp.status_int, 404)
def test_HEAD_quarantine_zbyte(self): def test_HEAD_quarantine_zbyte(self):
""" Test swift.object_server.ObjectController.GET """ # Test swift.obj.server.ObjectController.GET
timestamp = normalize_timestamp(time()) timestamp = normalize_timestamp(time())
req = Request.blank('/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, req = Request.blank('/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
headers={'X-Timestamp': timestamp, headers={'X-Timestamp': timestamp,
@ -706,7 +706,7 @@ class TestObjectController(unittest.TestCase):
self.assertEquals(os.listdir(quar_dir)[0], file_name) self.assertEquals(os.listdir(quar_dir)[0], file_name)
def test_GET(self): def test_GET(self):
""" Test swift.object_server.ObjectController.GET """ # Test swift.obj.server.ObjectController.GET
req = Request.blank('/sda1/p/a/c', environ={'REQUEST_METHOD': 'GET'}) req = Request.blank('/sda1/p/a/c', environ={'REQUEST_METHOD': 'GET'})
resp = req.get_response(self.object_controller) resp = req.get_response(self.object_controller)
self.assertEquals(resp.status_int, 400) self.assertEquals(resp.status_int, 400)
@ -967,7 +967,7 @@ class TestObjectController(unittest.TestCase):
self.assertEquals(resp.status_int, 200) self.assertEquals(resp.status_int, 200)
def test_GET_quarantine(self): def test_GET_quarantine(self):
""" Test swift.object_server.ObjectController.GET """ # Test swift.obj.server.ObjectController.GET
timestamp = normalize_timestamp(time()) timestamp = normalize_timestamp(time())
req = Request.blank('/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, req = Request.blank('/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
headers={'X-Timestamp': timestamp, headers={'X-Timestamp': timestamp,
@ -998,7 +998,7 @@ class TestObjectController(unittest.TestCase):
self.assertEquals(resp.status_int, 404) self.assertEquals(resp.status_int, 404)
def test_GET_quarantine_zbyte(self): def test_GET_quarantine_zbyte(self):
""" Test swift.object_server.ObjectController.GET """ # Test swift.obj.server.ObjectController.GET
timestamp = normalize_timestamp(time()) timestamp = normalize_timestamp(time())
req = Request.blank('/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, req = Request.blank('/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
headers={'X-Timestamp': timestamp, headers={'X-Timestamp': timestamp,
@ -1025,7 +1025,7 @@ class TestObjectController(unittest.TestCase):
self.assertEquals(os.listdir(quar_dir)[0], file_name) self.assertEquals(os.listdir(quar_dir)[0], file_name)
def test_GET_quarantine_range(self): def test_GET_quarantine_range(self):
""" Test swift.object_server.ObjectController.GET """ # Test swift.obj.server.ObjectController.GET
timestamp = normalize_timestamp(time()) timestamp = normalize_timestamp(time())
req = Request.blank('/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, req = Request.blank('/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
headers={'X-Timestamp': timestamp, headers={'X-Timestamp': timestamp,
@ -1077,7 +1077,7 @@ class TestObjectController(unittest.TestCase):
self.assertEquals(resp.status_int, 404) self.assertEquals(resp.status_int, 404)
def test_DELETE(self): def test_DELETE(self):
# Test swift.object_server.ObjectController.DELETE # Test swift.obj.server.ObjectController.DELETE
req = Request.blank('/sda1/p/a/c', req = Request.blank('/sda1/p/a/c',
environ={'REQUEST_METHOD': 'DELETE'}) environ={'REQUEST_METHOD': 'DELETE'})
resp = req.get_response(self.object_controller) resp = req.get_response(self.object_controller)
@ -1157,7 +1157,7 @@ class TestObjectController(unittest.TestCase):
self.assert_(os.path.isfile(objfile)) self.assert_(os.path.isfile(objfile))
def test_DELETE_container_updates(self): def test_DELETE_container_updates(self):
# Test swift.object_server.ObjectController.DELETE and container # Test swift.obj.server.ObjectController.DELETE and container
# updates, making sure container update is called in the correct # updates, making sure container update is called in the correct
# state. # state.
timestamp = normalize_timestamp(time()) timestamp = normalize_timestamp(time())
@ -1254,13 +1254,13 @@ class TestObjectController(unittest.TestCase):
self.object_controller.container_update = orig_cu self.object_controller.container_update = orig_cu
def test_call(self): def test_call(self):
""" Test swift.object_server.ObjectController.__call__ """ # Test swift.obj.server.ObjectController.__call__
inbuf = StringIO() inbuf = StringIO()
errbuf = StringIO() errbuf = StringIO()
outbuf = StringIO() outbuf = StringIO()
def start_response(*args): def start_response(*args):
""" Sends args to outbuf """ """Sends args to outbuf"""
outbuf.writelines(args) outbuf.writelines(args)
self.object_controller.__call__({'REQUEST_METHOD': 'PUT', self.object_controller.__call__({'REQUEST_METHOD': 'PUT',
@ -2623,10 +2623,7 @@ class TestObjectController(unittest.TestCase):
diskfile.fallocate = orig_fallocate diskfile.fallocate = orig_fallocate
def test_serv_reserv(self): def test_serv_reserv(self):
""" # Test replication_server flag was set from configuration file.
Test replication_server flag
was set from configuration file.
"""
conf = {'devices': self.testdir, 'mount_check': 'false'} conf = {'devices': self.testdir, 'mount_check': 'false'}
self.assertEquals( self.assertEquals(
object_server.ObjectController(conf).replication_server, None) object_server.ObjectController(conf).replication_server, None)
@ -2640,7 +2637,7 @@ class TestObjectController(unittest.TestCase):
object_server.ObjectController(conf).replication_server) object_server.ObjectController(conf).replication_server)
def test_list_allowed_methods(self): def test_list_allowed_methods(self):
""" Test list of allowed_methods """ # Test list of allowed_methods
obj_methods = ['DELETE', 'PUT', 'HEAD', 'GET', 'POST'] obj_methods = ['DELETE', 'PUT', 'HEAD', 'GET', 'POST']
repl_methods = ['REPLICATE'] repl_methods = ['REPLICATE']
for method_name in obj_methods: for method_name in obj_methods:
@ -2651,10 +2648,8 @@ class TestObjectController(unittest.TestCase):
self.assertEquals(method.replication, True) self.assertEquals(method.replication, True)
def test_correct_allowed_method(self): def test_correct_allowed_method(self):
""" # Test correct work for allowed method using
Test correct work for allowed method using # swift.obj.server.ObjectController.__call__
swift.object_server.ObjectController.__call__
"""
inbuf = StringIO() inbuf = StringIO()
errbuf = StringIO() errbuf = StringIO()
outbuf = StringIO() outbuf = StringIO()
@ -2663,7 +2658,7 @@ class TestObjectController(unittest.TestCase):
'replication_server': 'false'}) 'replication_server': 'false'})
def start_response(*args): def start_response(*args):
""" Sends args to outbuf """ # Sends args to outbuf
outbuf.writelines(args) outbuf.writelines(args)
method = 'PUT' method = 'PUT'
@ -2690,10 +2685,8 @@ class TestObjectController(unittest.TestCase):
self.assertEqual(response, method_res) self.assertEqual(response, method_res)
def test_not_allowed_method(self): def test_not_allowed_method(self):
""" # Test correct work for NOT allowed method using
Test correct work for NOT allowed method using # swift.obj.server.ObjectController.__call__
swift.object_server.ObjectController.__call__
"""
inbuf = StringIO() inbuf = StringIO()
errbuf = StringIO() errbuf = StringIO()
outbuf = StringIO() outbuf = StringIO()
@ -2702,7 +2695,7 @@ class TestObjectController(unittest.TestCase):
'replication_server': 'false'}) 'replication_server': 'false'})
def start_response(*args): def start_response(*args):
""" Sends args to outbuf """ # Sends args to outbuf
outbuf.writelines(args) outbuf.writelines(args)
method = 'PUT' method = 'PUT'