Browse Source

fixed some minor things in tests that pyflakes complained about

Change-Id: Ifeab56a964630bcf941e932fcbe39e6572e62975
changes/39/25439/1
Greg Lange 9 years ago
parent
commit
44f00a23c1
  1. 2
      test/__init__.py
  2. 4
      test/functional/swift_test_client.py
  3. 4
      test/functional/tests.py
  4. 7
      test/functionalnosetests/swift_testing.py
  5. 8
      test/functionalnosetests/test_object.py
  6. 2
      test/probe/common.py
  7. 2
      test/probe/test_empty_device_handoff.py
  8. 9
      test/unit/__init__.py
  9. 2
      test/unit/account/test_server.py
  10. 18
      test/unit/common/middleware/test_bulk.py
  11. 2
      test/unit/common/middleware/test_except.py
  12. 2
      test/unit/common/middleware/test_formpost.py
  13. 2
      test/unit/common/middleware/test_keystoneauth.py
  14. 1
      test/unit/common/middleware/test_list_endpoints.py
  15. 4
      test/unit/common/middleware/test_memcache.py
  16. 39
      test/unit/common/middleware/test_proxy_logging.py
  17. 2
      test/unit/common/middleware/test_quotas.py
  18. 2
      test/unit/common/middleware/test_ratelimit.py
  19. 12
      test/unit/common/middleware/test_recon.py
  20. 4
      test/unit/common/middleware/test_slo.py
  21. 6
      test/unit/common/middleware/test_staticweb.py
  22. 2
      test/unit/common/middleware/test_tempauth.py
  23. 2
      test/unit/common/middleware/test_tempurl.py
  24. 7
      test/unit/common/ring/test_builder.py
  25. 1
      test/unit/common/ring/test_ring.py
  26. 3
      test/unit/common/test_constraints.py
  27. 3
      test/unit/common/test_db.py
  28. 3
      test/unit/common/test_db_replicator.py
  29. 4
      test/unit/common/test_internal_client.py
  30. 1
      test/unit/common/test_manager.py
  31. 27
      test/unit/common/test_swob.py
  32. 14
      test/unit/common/test_utils.py
  33. 8
      test/unit/common/test_wsgi.py
  34. 4
      test/unit/container/test_server.py
  35. 1
      test/unit/container/test_updater.py
  36. 6
      test/unit/obj/test_auditor.py
  37. 9
      test/unit/obj/test_expirer.py
  38. 10
      test/unit/obj/test_replicator.py
  39. 6
      test/unit/obj/test_server.py
  40. 1
      test/unit/obj/test_updater.py
  41. 3
      test/unit/proxy/test_server.py

2
test/__init__.py

@ -4,8 +4,6 @@
import __builtin__
import sys
import os
from ConfigParser import MissingSectionHeaderError
from StringIO import StringIO
from swift.common.utils import readconf

4
test/functional/swift_test_client.py

@ -447,8 +447,8 @@ class Container(Base):
raise ResponseError(self.conn.response)
def info(self, hdrs={}, parms={}, cfg={}):
status = self.conn.make_request('HEAD', self.path, hdrs=hdrs,
parms=parms, cfg=cfg)
self.conn.make_request('HEAD', self.path, hdrs=hdrs,
parms=parms, cfg=cfg)
if self.conn.response.status == 204:
fields = [['bytes_used', 'x-container-bytes-used'],

4
test/functional/tests.py

@ -470,7 +470,6 @@ class TestContainer(Base):
prefixs = ['alpha/', 'beta/', 'kappa/']
prefix_files = {}
all_files = []
for prefix in prefixs:
prefix_files[prefix] = []
@ -746,7 +745,7 @@ class TestContainerPathsEnv:
stored_files.add(f)
cls.stored_files = sorted(stored_files)
class TestContainerPaths(Base):
@ -1186,7 +1185,6 @@ class TestFile(Base):
def testRangedGetsWithLWSinHeader(self):
#Skip this test until webob 1.2 can tolerate LWS in Range header.
file_length = 10000
range_size = file_length / 10
file = self.env.container.file(Utils.create_name())
data = file.write_random(file_length)

7
test/functionalnosetests/swift_testing.py

@ -13,13 +13,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import errno
import os
import socket
import sys
from time import sleep
from nose import SkipTest
from ConfigParser import MissingSectionHeaderError
from test import get_config
@ -153,10 +150,10 @@ def retry(func, *args, **kwargs):
if attempts > retries:
raise
parsed[use_account] = conn[use_account] = None
except AuthError, err:
except AuthError:
url[use_account] = token[use_account] = None
continue
except InternalServerError, err:
except InternalServerError:
pass
if attempts <= retries:
sleep(backoff)

8
test/functionalnosetests/test_object.py

@ -19,12 +19,8 @@ import unittest
from nose import SkipTest
from uuid import uuid4
from swift.common.constraints import MAX_META_COUNT, MAX_META_NAME_LENGTH, \
MAX_META_OVERALL_SIZE, MAX_META_VALUE_LENGTH
from swift_testing import check_response, retry, skip, skip3, \
swift_test_perm, web_front_end
from test import get_config
class TestObject(unittest.TestCase):
@ -112,7 +108,7 @@ class TestObject(unittest.TestCase):
'X-Copy-From': source})
return check_response(conn)
resp = retry(put)
contents = resp.read()
resp.read()
self.assertEquals(resp.status, 201)
# contents of dest should be the same as source
@ -146,7 +142,7 @@ class TestObject(unittest.TestCase):
'Destination': dest})
return check_response(conn)
resp = retry(copy)
contents = resp.read()
resp.read()
self.assertEquals(resp.status, 201)
# contents of dest should be the same as source

2
test/probe/common.py

@ -16,7 +16,7 @@
from httplib import HTTPConnection
from os import kill
from signal import SIGTERM
from subprocess import Popen, PIPE, STDOUT
from subprocess import Popen, PIPE
from time import sleep, time
from swiftclient import get_auth, head_account

2
test/probe/test_empty_device_handoff.py

@ -17,7 +17,7 @@
import os
import shutil
from subprocess import call, Popen
from subprocess import call
from unittest import main, TestCase
from uuid import uuid4

9
test/unit/__init__.py

@ -1,6 +1,5 @@
""" Swift tests """
import sys
import os
import copy
import logging
@ -12,13 +11,11 @@ from eventlet.green import socket
from tempfile import mkdtemp
from shutil import rmtree
from test import get_config
from ConfigParser import MissingSectionHeaderError
from StringIO import StringIO
from swift.common.utils import readconf, config_true_value
from logging import Handler
from swift.common.utils import config_true_value
from hashlib import md5
from eventlet import sleep, spawn, Timeout
from eventlet import sleep, Timeout
import logging.handlers
from httplib import HTTPException
def readuntil2crlfs(fd):

2
test/unit/account/test_server.py

@ -1097,7 +1097,6 @@ class TestAccountController(unittest.TestCase):
self.assertEquals(outbuf.getvalue()[:4], '412 ')
def test_invalid_method_doesnt_exist(self):
inbuf = StringIO()
errbuf = StringIO()
outbuf = StringIO()
@ -1111,7 +1110,6 @@ class TestAccountController(unittest.TestCase):
self.assertEquals(outbuf.getvalue()[:4], '405 ')
def test_invalid_method_is_not_public(self):
inbuf = StringIO()
errbuf = StringIO()
outbuf = StringIO()

18
test/unit/common/middleware/test_bulk.py

@ -254,7 +254,7 @@ class TestUntar(unittest.TestCase):
{'base_fails1': [{'sub_dir1': ['sub1_file1']},
{'sub_dir2': ['sub2_file1', 'sub2_file2']},
{'sub_dir3': [{'sub4_dir1': 'sub4_file1'}]}]}]
tar = self.build_tar(dir_tree)
self.build_tar(dir_tree)
req = Request.blank('/tar_works/acc/',
headers={'Accept': 'application/json'})
req.environ['wsgi.input'] = open(os.path.join(self.testdir,
@ -265,7 +265,7 @@ class TestUntar(unittest.TestCase):
self.assertEquals(resp_data['Number Files Created'], 4)
def test_extract_tar_fail_cont_401(self):
tar = self.build_tar()
self.build_tar()
req = Request.blank('/unauth/acc/')
req.environ['wsgi.input'] = open(os.path.join(self.testdir,
'tar_fails.tar'))
@ -274,7 +274,7 @@ class TestUntar(unittest.TestCase):
self.assertEquals(resp.status_int, 401)
def test_extract_tar_fail_obj_401(self):
tar = self.build_tar()
self.build_tar()
req = Request.blank('/create_obj_unauth/acc/cont/')
req.environ['wsgi.input'] = open(os.path.join(self.testdir,
'tar_fails.tar'))
@ -283,7 +283,7 @@ class TestUntar(unittest.TestCase):
self.assertEquals(resp.status_int, 401)
def test_extract_tar_fail_obj_name_len(self):
tar = self.build_tar()
self.build_tar()
req = Request.blank('/tar_works/acc/cont/',
headers={'Accept': 'application/json'})
req.environ['wsgi.input'] = open(os.path.join(self.testdir,
@ -296,7 +296,7 @@ class TestUntar(unittest.TestCase):
'/tar_works/acc/cont/base_fails1/' + ('f' * 101))
def test_extract_tar_fail_compress_type(self):
tar = self.build_tar()
self.build_tar()
req = Request.blank('/tar_works/acc/cont/')
req.environ['wsgi.input'] = open(os.path.join(self.testdir,
'tar_fails.tar'))
@ -306,7 +306,7 @@ class TestUntar(unittest.TestCase):
self.assertEquals(self.app.calls, 0)
def test_extract_tar_fail_max_file_name_length(self):
tar = self.build_tar()
self.build_tar()
with patch.object(self.bulk, 'max_failed_extractions', 1):
self.app.calls = 0
req = Request.blank('/tar_works/acc/cont/',
@ -345,7 +345,7 @@ class TestUntar(unittest.TestCase):
{'sub_dir2': ['sub2_file1', 'sub2_file2']},
'f' * 101,
{'sub_dir3': [{'sub4_dir1': 'sub4_file1'}]}]
tar = self.build_tar(dir_tree)
self.build_tar(dir_tree)
with patch.object(self.bulk, 'max_containers', 1):
self.app.calls = 0
body = open(os.path.join(self.testdir, 'tar_fails.tar')).read()
@ -361,7 +361,7 @@ class TestUntar(unittest.TestCase):
{'sub_dir2': ['sub2_file1', 'sub2_file2']},
'f\xde',
{'./sub_dir3': [{'sub4_dir1': 'sub4_file1'}]}]}]
tar = self.build_tar(dir_tree)
self.build_tar(dir_tree)
req = Request.blank('/create_cont_fail/acc/cont/',
headers={'Accept': 'application/json'})
req.environ['wsgi.input'] = open(os.path.join(self.testdir,
@ -373,7 +373,7 @@ class TestUntar(unittest.TestCase):
self.assertEquals(len(resp_data['Errors']), 5)
def test_extract_tar_fail_create_cont_value_err(self):
tar = self.build_tar()
self.build_tar()
req = Request.blank('/create_cont_fail/acc/cont/',
headers={'Accept': 'application/json'})
req.environ['wsgi.input'] = open(os.path.join(self.testdir,

2
test/unit/common/middleware/test_except.py

@ -15,7 +15,7 @@
import unittest
from swift.common.swob import Request, Response
from swift.common.swob import Request
from swift.common.middleware import catch_errors
from swift.common.utils import get_logger

2
test/unit/common/middleware/test_formpost.py

@ -280,7 +280,7 @@ class TestCappedFileLikeObject(unittest.TestCase):
self.assertEquals(fp.readline(), 'def')
except EOFError, err:
exc = err
self.assertEquals(str(err), 'max_file_size exceeded')
self.assertEquals(str(exc), 'max_file_size exceeded')
def test_read_sized(self):
fp = formpost._CappedFileLikeObject(StringIO('abcdefg'), 10)

2
test/unit/common/middleware/test_keystoneauth.py

@ -83,7 +83,7 @@ class SwiftAuth(unittest.TestCase):
role = self.test_auth.reseller_admin_role
headers = self._get_identity_headers(role=role)
req = self._make_request('/v1/AUTH_acct/c', headers)
resp = req.get_response(self._get_successful_middleware())
req.get_response(self._get_successful_middleware())
self.assertTrue(req.environ.get('reseller_request'))
def test_confirmed_identity_is_not_authorized(self):

1
test/unit/common/middleware/test_list_endpoints.py

@ -74,7 +74,6 @@ class TestListEndpoints(unittest.TestCase):
'ip': '10.1.2.2', 'port': 6000,
'device': 'sdd1'}]
intended_part_shift = 30
intended_reload_time = 15
ring.RingData(intended_replica2part2dev_id_a,
intended_devs, intended_part_shift).save(accountgz)
ring.RingData(intended_replica2part2dev_id_c,

4
test/unit/common/middleware/test_memcache.py

@ -74,7 +74,7 @@ class TestCacheMiddleware(unittest.TestCase):
memcache.ConfigParser = ExcConfigParser
exc = None
try:
app = memcache.MemcacheMiddleware(FakeApp(), {})
memcache.MemcacheMiddleware(FakeApp(), {})
except Exception, err:
exc = err
finally:
@ -87,7 +87,7 @@ class TestCacheMiddleware(unittest.TestCase):
memcache.ConfigParser = ExcConfigParser
exc = None
try:
app = memcache.MemcacheMiddleware(
memcache.MemcacheMiddleware(
FakeApp(), {'memcache_servers': '1.2.3.4:5',
'memcache_serialization_support': '2'})
except Exception, err:

39
test/unit/common/middleware/test_proxy_logging.py

@ -15,7 +15,7 @@
import unittest
import time
from urllib import quote, unquote
from urllib import unquote
import cStringIO as StringIO
from logging.handlers import SysLogHandler
@ -65,7 +65,7 @@ class FakeAppReadline(object):
def __call__(self, env, start_response):
start_response('200 OK', [('Content-Type', 'text/plain'),
('Content-Length', '8')])
line = env['wsgi.input'].readline()
env['wsgi.input'].readline()
return ["FAKE APP"]
@ -130,7 +130,8 @@ class TestProxyLogging(unittest.TestCase):
for url in ['/', '/foo', '/foo/bar', '/v1']:
req = Request.blank(url, environ={'REQUEST_METHOD': 'GET'})
resp = app(req.environ, start_response)
resp_body = ''.join(resp)
# get body
''.join(resp)
self.assertEqual([], app.access_logger.log_dict['timing'])
self.assertEqual([], app.access_logger.log_dict['update_stats'])
@ -295,7 +296,7 @@ class TestProxyLogging(unittest.TestCase):
'REQUEST_METHOD': 'GET'})
resp = app(req.environ, start_response)
resp_body = ''.join(resp)
log_parts = self._log_parts(app, should_be_empty=True)
self._log_parts(app, should_be_empty=True)
self.assertEquals(resp_body, 'FAKE APP')
def test_multi_segment_resp(self):
@ -321,7 +322,8 @@ class TestProxyLogging(unittest.TestCase):
app.access_logger = FakeLogger()
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
resp = app(req.environ, start_response)
exhaust_generator = [x for x in resp]
# exhaust generator
[x for x in resp]
log_parts = self._log_parts(app)
headers = unquote(log_parts[14]).split('\n')
self.assert_('Host: localhost:80' in headers)
@ -333,7 +335,8 @@ class TestProxyLogging(unittest.TestCase):
req = Request.blank('/v1/a/c/o/foo', environ={'REQUEST_METHOD': 'PUT',
'wsgi.input': StringIO.StringIO('some stuff')})
resp = app(req.environ, start_response)
exhaust_generator = [x for x in resp]
# exhaust generator
[x for x in resp]
log_parts = self._log_parts(app)
self.assertEquals(log_parts[11], str(len('FAKE APP')))
self.assertEquals(log_parts[10], str(len('some stuff')))
@ -349,7 +352,8 @@ class TestProxyLogging(unittest.TestCase):
'wsgi.input': StringIO.StringIO(
'some stuff\nsome other stuff\n')})
resp = app(req.environ, start_response)
exhaust_generator = [x for x in resp]
# exhaust generator
[x for x in resp]
log_parts = self._log_parts(app)
self.assertEquals(log_parts[11], str(len('FAKE APP')))
self.assertEquals(log_parts[10], str(len('some stuff\n')))
@ -363,7 +367,8 @@ class TestProxyLogging(unittest.TestCase):
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET',
'QUERY_STRING': 'x=3'})
resp = app(req.environ, start_response)
exhaust_generator = [x for x in resp]
# exhaust generator
[x for x in resp]
log_parts = self._log_parts(app)
self.assertEquals(unquote(log_parts[4]), '/?x=3')
@ -373,7 +378,8 @@ class TestProxyLogging(unittest.TestCase):
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET',
'REMOTE_ADDR': '1.2.3.4'})
resp = app(req.environ, start_response)
exhaust_generator = [x for x in resp]
# exhaust generator
[x for x in resp]
log_parts = self._log_parts(app)
self.assertEquals(log_parts[0], '1.2.3.4') # client ip
self.assertEquals(log_parts[1], '1.2.3.4') # remote addr
@ -386,7 +392,8 @@ class TestProxyLogging(unittest.TestCase):
'REMOTE_ADDR': '1.2.3.4',
'HTTP_X_FORWARDED_FOR': '4.5.6.7,8.9.10.11'})
resp = app(req.environ, start_response)
exhaust_generator = [x for x in resp]
# exhaust generator
[x for x in resp]
log_parts = self._log_parts(app)
self.assertEquals(log_parts[0], '4.5.6.7') # client ip
self.assertEquals(log_parts[1], '1.2.3.4') # remote addr
@ -398,7 +405,8 @@ class TestProxyLogging(unittest.TestCase):
'REMOTE_ADDR': '1.2.3.4',
'HTTP_X_CLUSTER_CLIENT_IP': '4.5.6.7'})
resp = app(req.environ, start_response)
exhaust_generator = [x for x in resp]
# exhaust generator
[x for x in resp]
log_parts = self._log_parts(app)
self.assertEquals(log_parts[0], '4.5.6.7') # client ip
self.assertEquals(log_parts[1], '1.2.3.4') # remote addr
@ -421,7 +429,8 @@ class TestProxyLogging(unittest.TestCase):
app.access_logger = FakeLogger()
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
resp = app(req.environ, start_response)
read_first_chunk = next(resp)
# read first chunk
next(resp)
resp.close() # raise a GeneratorExit in middleware app_iter loop
log_parts = self._log_parts(app)
self.assertEquals(log_parts[6], '499')
@ -434,7 +443,8 @@ class TestProxyLogging(unittest.TestCase):
'wsgi.input': FileLikeExceptor()})
try:
resp = app(req.environ, start_response)
body = ''.join(resp)
# read body
''.join(resp)
except IOError:
pass
log_parts = self._log_parts(app)
@ -449,7 +459,8 @@ class TestProxyLogging(unittest.TestCase):
'wsgi.input': FileLikeExceptor()})
try:
resp = app(req.environ, start_response)
body = ''.join(resp)
# read body
''.join(resp)
except IOError:
pass
log_parts = self._log_parts(app)

2
test/unit/common/middleware/test_quotas.py

@ -15,7 +15,7 @@
import unittest
from swift.common.swob import Request, Response, HTTPUnauthorized
from swift.common.swob import Request, HTTPUnauthorized
from swift.common.middleware import container_quotas
class FakeCache(object):

2
test/unit/common/middleware/test_ratelimit.py

@ -158,7 +158,7 @@ class TestRateLimit(unittest.TestCase):
global time_ticker
begin = time.time()
for x in range(0, num):
result = callable_func()
callable_func()
end = time.time()
total_time = float(num) / rate - 1.0 / rate # 1st request isn't limited
# Allow for one second of variation in the total time.

12
test/unit/common/middleware/test_recon.py

@ -620,14 +620,8 @@ class TestReconSuccess(TestCase):
'UDP: inuse 16 mem 4', 'UDPLITE: inuse 0',
'RAW: inuse 0', 'FRAG: inuse 0 memory 0',
'']
sockstat6_content = ['TCP6: inuse 1',
'UDP6: inuse 3',
'UDPLITE6: inuse 0',
'RAW6: inuse 0',
'FRAG6: inuse 0 memory 0',
'']
oart = OpenAndReadTester(sockstat_content)
rv = self.app.get_socket_info(openr=oart.open)
self.app.get_socket_info(openr=oart.open)
self.assertEquals(oart.open_calls, [(('/proc/net/sockstat', 'r'), {}),
(('/proc/net/sockstat6', 'r'), {})])
@ -672,7 +666,7 @@ class TestReconMiddleware(unittest.TestCase):
def test_get_device_info(self):
get_device_resp = ['{"/srv/1/node": ["sdb1"]}']
req = Request.blank('/recon/devices',
req = Request.blank('/recon/devices',
environ={'REQUEST_METHOD': 'GET'})
resp = self.app(req.environ, start_response)
self.assertEquals(resp, get_device_resp)
@ -811,7 +805,7 @@ class TestReconMiddleware(unittest.TestCase):
environ={'REQUEST_METHOD': 'GET'})
resp = self.app(req.environ, start_response)
self.assertEquals(resp, get_unmounted_resp)
def test_recon_no_get_unmounted(self):
get_unmounted_resp = '[]'
self.app.get_unmounted = self.frecon.fake_no_unmounted

4
test/unit/common/middleware/test_slo.py

@ -17,9 +17,7 @@ import unittest
from mock import patch
from swift.common.middleware import slo
from swift.common.utils import json
from swift.common.constraints import MAX_META_VALUE_LENGTH
from swift.common.swob import Request, Response, HTTPException, \
HTTPRequestEntityTooLarge
from swift.common.swob import Request, Response, HTTPException
class FakeApp(object):

6
test/unit/common/middleware/test_staticweb.py

@ -22,7 +22,6 @@ from contextlib import contextmanager
from swift.common.swob import Request, Response
from swift.common.middleware import staticweb
from test.unit import FakeLogger
class FakeMemcache(object):
@ -460,11 +459,6 @@ class TestStaticWeb(unittest.TestCase):
self.assertEquals(resp.status_int, 200)
self.assert_('Test main index.html file.' in resp.body)
def test_container3subdir(self):
resp = Request.blank(
'/v1/a/c3/subdir').get_response(self.test_staticweb)
self.assertEquals(resp.status_int, 301)
def test_container3subsubdir(self):
resp = Request.blank(
'/v1/a/c3/subdir3/subsubdir').get_response(self.test_staticweb)

2
test/unit/common/middleware/test_tempauth.py

@ -334,7 +334,7 @@ class TestAuth(unittest.TestCase):
cache_key = 'AUTH_/token/AUTH_t'
cache_entry = (time()+3600, '.reseller_admin')
req.environ['swift.cache'].set(cache_key, cache_entry)
resp = req.get_response(self.test_auth)
req.get_response(self.test_auth)
self.assertTrue(req.environ.get('reseller_request', False))
def test_account_put_permissions(self):

2
test/unit/common/middleware/test_tempurl.py

@ -201,7 +201,7 @@ class TestTempURL(unittest.TestCase):
path = '/v1/a/c/o'
key = 'abc'
hmac_body = '%s\n%s\n%s' % (method, expires, path)
sig = hmac.new(key, hmac_body, sha1).hexdigest()
hmac.new(key, hmac_body, sha1).hexdigest()
req = self._make_request(path,
environ={'QUERY_STRING': 'temp_url_expires=%s' % expires})
req.environ['swift.cache'].set('temp-url-key/a', key)

7
test/unit/common/ring/test_builder.py

@ -23,7 +23,6 @@ from mock import Mock, call as mock_call
from swift.common import exceptions
from swift.common import ring
from swift.common.ring import RingBuilder, RingData
class TestRingBuilder(unittest.TestCase):
@ -669,7 +668,7 @@ class TestRingBuilder(unittest.TestCase):
fake_pickle = Mock(return_value=rb)
fake_open = Mock(return_value=None)
pickle.load = fake_pickle
builder = RingBuilder.load('fake.builder', open=fake_open)
builder = ring.RingBuilder.load('fake.builder', open=fake_open)
self.assertEquals(fake_pickle.call_count, 1)
fake_open.assert_has_calls([mock_call('fake.builder', 'rb')])
self.assertEquals(builder, rb)
@ -679,7 +678,7 @@ class TestRingBuilder(unittest.TestCase):
#test old style builder
fake_pickle.return_value = rb.to_dict()
pickle.load = fake_pickle
builder = RingBuilder.load('fake.builder', open=fake_open)
builder = ring.RingBuilder.load('fake.builder', open=fake_open)
fake_open.assert_has_calls([mock_call('fake.builder', 'rb')])
self.assertEquals(builder.devs, rb.devs)
fake_pickle.reset_mock()
@ -691,7 +690,7 @@ class TestRingBuilder(unittest.TestCase):
del(dev['meta'])
fake_pickle.return_value = no_meta_builder
pickle.load = fake_pickle
builder = RingBuilder.load('fake.builder', open=fake_open)
builder = ring.RingBuilder.load('fake.builder', open=fake_open)
fake_open.assert_has_calls([mock_call('fake.builder', 'rb')])
self.assertEquals(builder.devs, rb.devs)
fake_pickle.reset_mock()

1
test/unit/common/ring/test_ring.py

@ -330,7 +330,6 @@ class TestRing(unittest.TestCase):
self.assertEquals(primary_zones, exp_zones)
devs = list(r.get_more_nodes(part))
self.assertEquals([d['id'] for d in devs], exp_handoffs)
seen_shared_zone = False
# The first 6 replicas plus the 3 primary nodes should cover all 9
# zones in this test

3
test/unit/common/test_constraints.py

@ -16,8 +16,7 @@
import unittest
from test.unit import MockTrue
from swift.common.swob import HTTPBadRequest, HTTPLengthRequired, \
HTTPRequestEntityTooLarge, Request
from swift.common.swob import HTTPBadRequest, Request
from swift.common.http import HTTP_REQUEST_ENTITY_TOO_LARGE, \
HTTP_BAD_REQUEST, HTTP_LENGTH_REQUIRED
from swift.common import constraints

3
test/unit/common/test_db.py

@ -20,7 +20,6 @@ import hashlib
import os
import unittest
from shutil import rmtree, copy
from StringIO import StringIO
from time import sleep, time
from uuid import uuid4
@ -695,7 +694,7 @@ class TestContainerBroker(unittest.TestCase):
broker.put_object('z', normalize_timestamp(time()), 0, 'text/plain',
'd41d8cd98f00b204e9800998ecf8427e')
# Test before deletion
res = broker.reclaim(normalize_timestamp(time()), time())
broker.reclaim(normalize_timestamp(time()), time())
broker.delete_db(normalize_timestamp(time()))
def test_delete_object(self):

3
test/unit/common/test_db_replicator.py

@ -22,7 +22,6 @@ from shutil import rmtree
from tempfile import mkdtemp, NamedTemporaryFile
from swift.common import db_replicator
from swift.common import utils
from swift.common.utils import normalize_timestamp
from swift.container import server as container_server
@ -215,11 +214,9 @@ class TestDBReplicator(unittest.TestCase):
def test_rsync_file(self):
replicator = TestReplicator({})
with _mock_process(-1):
fake_device = {'ip': '127.0.0.1', 'device': 'sda1'}
self.assertEquals(False,
replicator._rsync_file('/some/file', 'remote:/some/file'))
with _mock_process(0):
fake_device = {'ip': '127.0.0.1', 'device': 'sda1'}
self.assertEquals(True,
replicator._rsync_file('/some/file', 'remote:/some/file'))

4
test/unit/common/test_internal_client.py

@ -289,7 +289,7 @@ class TestInternalClient(unittest.TestCase):
try:
client.make_request('GET', '/', {}, (201,))
except Exception, err:
exc = err
pass
self.assertEquals(200, err.resp.status_int)
finally:
internal_client.sleep = old_sleep
@ -324,7 +324,7 @@ class TestInternalClient(unittest.TestCase):
try:
client.make_request('PUT', '/', {}, (2,), fobj)
except Exception, err:
exc = err
pass
self.assertEquals(404, err.resp.status_int)
finally:
internal_client.sleep = old_sleep

1
test/unit/common/test_manager.py

@ -21,7 +21,6 @@ import sys
import resource
import signal
import errno
from contextlib import contextmanager
from collections import defaultdict
from threading import Thread
from time import sleep, time

27
test/unit/common/test_swob.py

@ -580,14 +580,16 @@ class TestResponse(unittest.TestCase):
'/', environ={'HTTP_HOST': 'somehost'})
resp = self._get_response()
resp.location = '/something'
body = ''.join(resp(req.environ, start_response))
# read response
''.join(resp(req.environ, start_response))
self.assertEquals(resp.location, 'http://somehost/something')
req = swift.common.swob.Request.blank(
'/', environ={'HTTP_HOST': 'somehost:80'})
resp = self._get_response()
resp.location = '/something'
body = ''.join(resp(req.environ, start_response))
# read response
''.join(resp(req.environ, start_response))
self.assertEquals(resp.location, 'http://somehost/something')
req = swift.common.swob.Request.blank(
@ -595,7 +597,8 @@ class TestResponse(unittest.TestCase):
'wsgi.url_scheme': 'http'})
resp = self._get_response()
resp.location = '/something'
body = ''.join(resp(req.environ, start_response))
# read response
''.join(resp(req.environ, start_response))
self.assertEquals(resp.location, 'http://somehost:443/something')
req = swift.common.swob.Request.blank(
@ -603,7 +606,8 @@ class TestResponse(unittest.TestCase):
'wsgi.url_scheme': 'https'})
resp = self._get_response()
resp.location = '/something'
body = ''.join(resp(req.environ, start_response))
# read response
''.join(resp(req.environ, start_response))
self.assertEquals(resp.location, 'https://somehost/something')
def test_location_rewrite_no_host(self):
@ -614,7 +618,8 @@ class TestResponse(unittest.TestCase):
del req.environ['HTTP_HOST']
resp = self._get_response()
resp.location = '/something'
body = ''.join(resp(req.environ, start_response))
# read response
''.join(resp(req.environ, start_response))
self.assertEquals(resp.location, 'http://local/something')
req = swift.common.swob.Request.blank(
@ -622,7 +627,8 @@ class TestResponse(unittest.TestCase):
del req.environ['HTTP_HOST']
resp = self._get_response()
resp.location = '/something'
body = ''.join(resp(req.environ, start_response))
# read response
''.join(resp(req.environ, start_response))
self.assertEquals(resp.location, 'http://local:81/something')
def test_location_no_rewrite(self):
@ -632,7 +638,8 @@ class TestResponse(unittest.TestCase):
'/', environ={'HTTP_HOST': 'somehost'})
resp = self._get_response()
resp.location = 'http://www.google.com/'
body = ''.join(resp(req.environ, start_response))
# read response
''.join(resp(req.environ, start_response))
self.assertEquals(resp.location, 'http://www.google.com/')
def test_app_iter(self):
@ -655,7 +662,8 @@ class TestResponse(unittest.TestCase):
resp.conditional_response = True
resp.content_length = 10
content = ''.join(resp._response_iter(resp.app_iter, ''))
# read response
''.join(resp._response_iter(resp.app_iter, ''))
self.assertEquals(resp.status, '200 OK')
self.assertEqual(10, resp.content_length)
@ -672,7 +680,8 @@ class TestResponse(unittest.TestCase):
resp.conditional_response = True
resp.content_length = 10
content = ''.join(resp._response_iter(resp.app_iter, ''))
# read response
''.join(resp._response_iter(resp.app_iter, ''))
self.assertEquals(resp.status, '200 OK')
self.assertEqual(10, resp.content_length)

14
test/unit/common/test_utils.py

@ -20,7 +20,6 @@ from test.unit import temptree
import ctypes
import errno
import logging
import mimetools
import os
import random
import re
@ -35,9 +34,7 @@ from shutil import rmtree
from StringIO import StringIO
from functools import partial
from tempfile import TemporaryFile, NamedTemporaryFile
from logging import handlers as logging_handlers
from eventlet import sleep
from mock import patch
from swift.common.exceptions import (Timeout, MessageTimeout,
@ -422,7 +419,7 @@ class TestUtils(unittest.TestCase):
try:
utils.SysLogHandler = syslog_handler_catcher
logger = utils.get_logger({
utils.get_logger({
'log_facility': 'LOG_LOCAL3',
}, 'server', log_route='server')
self.assertEquals([
@ -431,7 +428,7 @@ class TestUtils(unittest.TestCase):
syslog_handler_args)
syslog_handler_args = []
logger = utils.get_logger({
utils.get_logger({
'log_facility': 'LOG_LOCAL3',
'log_address': '/foo/bar',
}, 'server', log_route='server')
@ -445,7 +442,7 @@ class TestUtils(unittest.TestCase):
# Using UDP with default port
syslog_handler_args = []
logger = utils.get_logger({
utils.get_logger({
'log_udp_host': 'syslog.funtimes.com',
}, 'server', log_route='server')
self.assertEquals([
@ -456,7 +453,7 @@ class TestUtils(unittest.TestCase):
# Using UDP with non-default port
syslog_handler_args = []
logger = utils.get_logger({
utils.get_logger({
'log_udp_host': 'syslog.funtimes.com',
'log_udp_port': '2123',
}, 'server', log_route='server')
@ -627,7 +624,7 @@ class TestUtils(unittest.TestCase):
self.assert_('127.0.0.1' in myips)
def test_hash_path(self):
_prefix = utils.HASH_PATH_PREFIX
_prefix = utils.HASH_PATH_PREFIX
utils.HASH_PATH_PREFIX = ''
# Yes, these tests are deliberately very fragile. We want to make sure
# that if someones changes the results hash_path produces, they know it
@ -1576,7 +1573,6 @@ class TestStatsdLoggingDelegation(unittest.TestCase):
self.assertEquals(called, [12345])
def test_fsync_bad_fullsync(self):
called = []
class FCNTL:
F_FULLSYNC = 123
def fcntl(self, fd, op):

8
test/unit/common/test_wsgi.py

@ -16,20 +16,14 @@
""" Tests for swift.common.utils """
from __future__ import with_statement
import logging
import errno
import mimetools
import os
import socket
import sys
import unittest
from getpass import getuser
from shutil import rmtree
from StringIO import StringIO
from collections import defaultdict
from urllib import quote
from eventlet import sleep
from swift.common.swob import Request
from swift.common import wsgi

4
test/unit/container/test_server.py

@ -24,7 +24,7 @@ from tempfile import mkdtemp
from eventlet import spawn, Timeout, listen
import simplejson
from swift.common.swob import Request, HTTPBadRequest
from swift.common.swob import Request
import swift.container
from swift.container import server as container_server
from swift.common.utils import normalize_timestamp, mkdirs
@ -1176,7 +1176,6 @@ class TestContainerController(unittest.TestCase):
self.assertEquals(outbuf.getvalue()[:4], '412 ')
def test_invalid_method_doesnt_exist(self):
inbuf = StringIO()
errbuf = StringIO()
outbuf = StringIO()
@ -1190,7 +1189,6 @@ class TestContainerController(unittest.TestCase):
self.assertEquals(outbuf.getvalue()[:4], '405 ')
def test_invalid_method_is_not_public(self):
inbuf = StringIO()
errbuf = StringIO()
outbuf = StringIO()

1
test/unit/container/test_updater.py

@ -15,7 +15,6 @@
import cPickle as pickle
import os
import sys
import unittest
from gzip import GzipFile
from shutil import rmtree

6
test/unit/obj/test_auditor.py

@ -15,7 +15,6 @@
from test import unit
import unittest
import tempfile
import os
import time
from shutil import rmtree
@ -26,9 +25,8 @@ from swift.obj import auditor
from swift.obj import server as object_server
from swift.obj.server import DiskFile, write_metadata, DATADIR
from swift.common.utils import hash_path, mkdirs, normalize_timestamp, \
renamer, storage_directory
storage_directory
from swift.obj.replicator import invalidate_hash
from swift.common.exceptions import AuditException
class TestAuditor(unittest.TestCase):
@ -303,8 +301,6 @@ class TestAuditor(unittest.TestCase):
def test_with_tombstone(self):
ts_file_path = self.setup_bad_zero_byte(with_ts=True)
self.auditor.run_once()
quarantine_path = os.path.join(self.devices,
'sda', 'quarantined', 'objects')
self.assertTrue(ts_file_path.endswith('ts'))
self.assertTrue(os.path.exists(ts_file_path))

9
test/unit/obj/test_expirer.py

@ -13,15 +13,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import json
from sys import exc_info
from time import time
from unittest import main, TestCase
from test.unit import FakeLogger
from swift.common import internal_client
from swift.obj import expirer
from swift.proxy.server import Application
def not_random():
@ -402,14 +399,13 @@ class TestObjectExpirer(TestCase):
'interval': interval})
orig_random = expirer.random
orig_sleep = expirer.sleep
exc = None
try:
expirer.random = not_random
expirer.sleep = not_sleep
x.run_once = raise_system_exit
x.run_forever()
except SystemExit, err:
exc = err
pass
finally:
expirer.random = orig_random
expirer.sleep = orig_sleep
@ -428,13 +424,12 @@ class TestObjectExpirer(TestCase):
x = expirer.ObjectExpirer({})
x.logger = FakeLogger()
orig_sleep = expirer.sleep
exc = None
try:
expirer.sleep = not_sleep
x.run_once = raise_exceptions
x.run_forever()
except SystemExit, err:
exc = err
pass
finally:
expirer.sleep = orig_sleep
self.assertEquals(str(err), 'exiting exception 2')

10
test/unit/obj/test_replicator.py

@ -20,8 +20,6 @@ import os
from gzip import GzipFile
from shutil import rmtree
import cPickle as pickle
import logging
import fcntl
import time
import tempfile
from contextlib import contextmanager
@ -407,7 +405,7 @@ class TestObjectReplicator(unittest.TestCase):
try:
rmtree(self.objects, ignore_errors=1)
object_replicator.mkdirs = blowup_mkdirs
jobs = self.replicator.collect_jobs()
self.replicator.collect_jobs()
self.assertTrue('exception' in self.replicator.logger.log_dict)
self.assertEquals(
len(self.replicator.logger.log_dict['exception']), 1)
@ -423,7 +421,6 @@ class TestObjectReplicator(unittest.TestCase):
def test_collect_jobs(self):
jobs = self.replicator.collect_jobs()
jobs_to_delete = [j for j in jobs if j['delete']]
jobs_to_keep = [j for j in jobs if not j['delete']]
jobs_by_part = {}
for job in jobs:
jobs_by_part[job['partition']] = job
@ -458,7 +455,6 @@ class TestObjectReplicator(unittest.TestCase):
self.assertTrue(os.path.isfile(part_1_path)) # sanity check
jobs = self.replicator.collect_jobs()
jobs_to_delete = [j for j in jobs if j['delete']]
jobs_to_keep = [j for j in jobs if not j['delete']]
jobs_by_part = {}
for job in jobs:
jobs_by_part[job['partition']] = job
@ -484,8 +480,6 @@ class TestObjectReplicator(unittest.TestCase):
def test_delete_partition(self):
df = DiskFile(self.devices, 'sda', '0', 'a', 'c', 'o', FakeLogger())
mkdirs(df.datadir)
ohash = hash_path('a', 'c', 'o')
data_dir = ohash[-3:]
part_path = os.path.join(self.objects, '1')
self.assertTrue(os.access(part_path, os.F_OK))
self.replicator.replicate()
@ -494,8 +488,6 @@ class TestObjectReplicator(unittest.TestCase):
def test_delete_partition_override_params(self):
df = DiskFile(self.devices, 'sda', '0', 'a', 'c', 'o', FakeLogger())
mkdirs(df.datadir)
ohash = hash_path('a', 'c', 'o')
data_dir = ohash[-3:]
part_path = os.path.join(self.objects, '1')
self.assertTrue(os.access(part_path, os.F_OK))
self.replicator.replicate(override_devices=['sdb'])

6
test/unit/obj/test_server.py

@ -22,7 +22,7 @@ import unittest
import email
from shutil import rmtree
from StringIO import StringIO
from time import gmtime, sleep, strftime, time
from time import gmtime, strftime, time
from tempfile import mkdtemp
from hashlib import md5
@ -31,7 +31,7 @@ from test.unit import FakeLogger
from test.unit import _getxattr as getxattr
from test.unit import _setxattr as setxattr
from test.unit import connect_tcp, readuntil2crlfs
from swift.obj import server as object_server, replicator
from swift.obj import server as object_server
from swift.common import utils
from swift.common.utils import hash_path, mkdirs, normalize_timestamp, \
NullLogger, storage_directory
@ -1421,7 +1421,6 @@ class TestObjectController(unittest.TestCase):
self.assertEquals(outbuf.getvalue()[:4], '405 ')
def test_invalid_method_doesnt_exist(self):
inbuf = StringIO()
errbuf = StringIO()
outbuf = StringIO()
def start_response(*args):
@ -1433,7 +1432,6 @@ class TestObjectController(unittest.TestCase):
self.assertEquals(outbuf.getvalue()[:4], '405 ')
def test_invalid_method_is_not_public(self):
inbuf = StringIO()
errbuf = StringIO()
outbuf = StringIO()
def start_response(*args):

1
test/unit/obj/test_updater.py

@ -14,7 +14,6 @@
# limitations under the License.
import cPickle as pickle
import json
import os
import unittest
from gzip import GzipFile

3
test/unit/proxy/test_server.py

@ -30,8 +30,7 @@ from hashlib import md5
from tempfile import mkdtemp
import random
import eventlet
from eventlet import sleep, spawn, Timeout, util, wsgi, listen
from eventlet import sleep, spawn, wsgi, listen
import simplejson
from test.unit import connect_tcp, readuntil2crlfs, FakeLogger, fake_http_connect

Loading…
Cancel
Save