Corrected many style violations in the tests.
I focussed primarily on F-category violations, they are all but all fixed with this patch. Change-Id: I343f6945c97984ed1093bc347b6def6994297041
This commit is contained in:
parent
3748b54a1b
commit
ff5a6d0111
@ -18,7 +18,7 @@ import httplib
|
||||
import re
|
||||
import unittest
|
||||
|
||||
from swiftclient import client, get_auth
|
||||
from swiftclient import get_auth
|
||||
from test.probe.common import kill_servers, reset_environment
|
||||
from urlparse import urlparse
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from subprocess import call, Popen
|
||||
from subprocess import Popen
|
||||
from unittest import main, TestCase
|
||||
from uuid import uuid4
|
||||
import os
|
||||
@ -23,8 +23,7 @@ import shutil
|
||||
|
||||
from swiftclient import client
|
||||
|
||||
from test.probe.common import kill_server, kill_servers, reset_environment, \
|
||||
start_server
|
||||
from test.probe.common import kill_servers, reset_environment
|
||||
from swift.common.utils import readconf
|
||||
|
||||
|
||||
@ -102,7 +101,7 @@ class TestReplicatorFunctions(TestCase):
|
||||
# Check, that all files were replicated.
|
||||
path_list = []
|
||||
# Figure out where the devices are
|
||||
for node_id in range(1,5):
|
||||
for node_id in range(1, 5):
|
||||
conf = readconf(self.configs['object'] % node_id)
|
||||
device_path = conf['app:object-server']['devices']
|
||||
for dev in self.object_ring.devs:
|
||||
|
@ -16,10 +16,9 @@
|
||||
# TODO: Tests
|
||||
|
||||
import unittest
|
||||
from swift.account import auditor
|
||||
|
||||
|
||||
class TestAuditor(unittest.TestCase):
|
||||
|
||||
def test_placeholder(self):
|
||||
pass
|
||||
|
||||
|
@ -14,7 +14,6 @@
|
||||
# limitations under the License.
|
||||
|
||||
import unittest
|
||||
from swift.account import replicator
|
||||
|
||||
|
||||
class TestReplicator(unittest.TestCase):
|
||||
|
@ -26,6 +26,7 @@ else: # executed if the try has no errors
|
||||
from swift.common.middleware import cname_lookup
|
||||
from swift.common.swob import Request
|
||||
|
||||
|
||||
class FakeApp(object):
|
||||
|
||||
def __call__(self, env, start_response):
|
||||
@ -38,6 +39,7 @@ def start_response(*args):
|
||||
|
||||
original_lookup = cname_lookup.lookup_cname
|
||||
|
||||
|
||||
class TestCNAMELookup(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
@ -82,11 +84,11 @@ class TestCNAMELookup(unittest.TestCase):
|
||||
def test_good_lookup(self):
|
||||
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'},
|
||||
headers={'Host': 'mysite.com'})
|
||||
|
||||
|
||||
def my_lookup(d):
|
||||
return 0, '%s.example.com' % d
|
||||
cname_lookup.lookup_cname = my_lookup
|
||||
|
||||
|
||||
resp = self.app(req.environ, start_response)
|
||||
self.assertEquals(resp, 'FAKE APP')
|
||||
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'},
|
||||
@ -102,7 +104,7 @@ class TestCNAMELookup(unittest.TestCase):
|
||||
def test_lookup_chain_too_long(self):
|
||||
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'},
|
||||
headers={'Host': 'mysite.com'})
|
||||
|
||||
|
||||
def my_lookup(d):
|
||||
if d == 'mysite.com':
|
||||
site = 'level1.foo.com'
|
||||
@ -112,18 +114,18 @@ class TestCNAMELookup(unittest.TestCase):
|
||||
site = 'bar.example.com'
|
||||
return 0, site
|
||||
cname_lookup.lookup_cname = my_lookup
|
||||
|
||||
|
||||
resp = self.app(req.environ, start_response)
|
||||
self.assertEquals(resp, ['CNAME lookup failed after 2 tries'])
|
||||
|
||||
def test_lookup_chain_bad_target(self):
|
||||
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'},
|
||||
headers={'Host': 'mysite.com'})
|
||||
|
||||
|
||||
def my_lookup(d):
|
||||
return 0, 'some.invalid.site.com'
|
||||
cname_lookup.lookup_cname = my_lookup
|
||||
|
||||
|
||||
resp = self.app(req.environ, start_response)
|
||||
self.assertEquals(resp,
|
||||
['CNAME lookup failed to resolve to a valid domain'])
|
||||
@ -131,11 +133,11 @@ class TestCNAMELookup(unittest.TestCase):
|
||||
def test_something_weird(self):
|
||||
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'},
|
||||
headers={'Host': 'mysite.com'})
|
||||
|
||||
|
||||
def my_lookup(d):
|
||||
return 0, None
|
||||
cname_lookup.lookup_cname = my_lookup
|
||||
|
||||
|
||||
resp = self.app(req.environ, start_response)
|
||||
self.assertEquals(resp,
|
||||
['CNAME lookup failed to resolve to a valid domain'])
|
||||
@ -144,11 +146,14 @@ class TestCNAMELookup(unittest.TestCase):
|
||||
def my_lookup(d):
|
||||
return 0, '%s.example.com' % d
|
||||
cname_lookup.lookup_cname = my_lookup
|
||||
|
||||
class memcache_stub(object):
|
||||
def __init__(self):
|
||||
self.cache = {}
|
||||
|
||||
def get(self, key):
|
||||
return self.cache.get(key, None)
|
||||
|
||||
def set(self, key, value, *a, **kw):
|
||||
self.cache[key] = value
|
||||
memcache = memcache_stub()
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
import unittest
|
||||
|
||||
from swift.common.swob import Request, Response
|
||||
from swift.common.swob import Request
|
||||
|
||||
from swift.common.middleware import crossdomain
|
||||
|
||||
|
@ -16,7 +16,6 @@
|
||||
import hmac
|
||||
import unittest
|
||||
from hashlib import sha1
|
||||
from contextlib import contextmanager
|
||||
from StringIO import StringIO
|
||||
from time import time
|
||||
|
||||
@ -1203,6 +1202,7 @@ class TestFormPost(unittest.TestCase):
|
||||
|
||||
status = [None]
|
||||
headers = [None]
|
||||
|
||||
def start_response(s, h, e=None):
|
||||
status[0] = s
|
||||
headers[0] = h
|
||||
|
@ -541,8 +541,7 @@ class TestProxyLogging(unittest.TestCase):
|
||||
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(), {})
|
||||
app.access_logger = FakeLogger()
|
||||
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
|
||||
resp = app(req.environ, start_response)
|
||||
resp_body = ''.join(resp)
|
||||
list(app(req.environ, start_response))
|
||||
log_parts = self._log_parts(app)
|
||||
self.assertEquals(log_parts[17], '-')
|
||||
|
||||
@ -550,8 +549,7 @@ class TestProxyLogging(unittest.TestCase):
|
||||
app.access_logger = FakeLogger()
|
||||
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
|
||||
req.environ['swift.log_info'] = []
|
||||
resp = app(req.environ, start_response)
|
||||
resp_body = ''.join(resp)
|
||||
list(app(req.environ, start_response))
|
||||
log_parts = self._log_parts(app)
|
||||
self.assertEquals(log_parts[17], '-')
|
||||
|
||||
@ -560,8 +558,7 @@ class TestProxyLogging(unittest.TestCase):
|
||||
app.access_logger = FakeLogger()
|
||||
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
|
||||
req.environ['swift.log_info'] = ['one']
|
||||
resp = app(req.environ, start_response)
|
||||
resp_body = ''.join(resp)
|
||||
list(app(req.environ, start_response))
|
||||
log_parts = self._log_parts(app)
|
||||
self.assertEquals(log_parts[17], 'one')
|
||||
|
||||
@ -570,8 +567,7 @@ class TestProxyLogging(unittest.TestCase):
|
||||
app.access_logger = FakeLogger()
|
||||
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
|
||||
req.environ['swift.log_info'] = ['one', 'and two']
|
||||
resp = app(req.environ, start_response)
|
||||
resp_body = ''.join(resp)
|
||||
list(app(req.environ, start_response))
|
||||
log_parts = self._log_parts(app)
|
||||
self.assertEquals(log_parts[17], 'one%2Cand%20two')
|
||||
|
||||
|
@ -18,7 +18,6 @@ try:
|
||||
except ImportError:
|
||||
import json
|
||||
import unittest
|
||||
from contextlib import contextmanager
|
||||
|
||||
from swift.common.swob import Request, Response
|
||||
from swift.common.middleware import staticweb
|
||||
|
@ -16,7 +16,6 @@
|
||||
import hmac
|
||||
import unittest
|
||||
from hashlib import sha1
|
||||
from contextlib import contextmanager
|
||||
from time import time
|
||||
|
||||
from swift.common.middleware import tempauth, tempurl
|
||||
|
@ -16,11 +16,9 @@
|
||||
# TODO: Tests
|
||||
|
||||
import unittest
|
||||
from swift.common import bench
|
||||
|
||||
|
||||
class TestBench(unittest.TestCase):
|
||||
|
||||
def test_placeholder(self):
|
||||
pass
|
||||
|
||||
|
@ -1861,7 +1861,7 @@ class TestAccountBroker(unittest.TestCase):
|
||||
broker.put_container('x', 0, 0, 0, 0)
|
||||
broker.put_container('y', 0, 0, 0, 0)
|
||||
broker.put_container('z', 0, 0, 0, 0)
|
||||
res = broker.reclaim(normalize_timestamp(time()), time())
|
||||
broker.reclaim(normalize_timestamp(time()), time())
|
||||
# self.assertEquals(len(res), 2)
|
||||
# self.assert_(isinstance(res, tuple))
|
||||
# containers, account_name = res
|
||||
@ -1869,7 +1869,7 @@ class TestAccountBroker(unittest.TestCase):
|
||||
# self.assert_(account_name is None)
|
||||
# Now delete the account
|
||||
broker.delete_db(normalize_timestamp(time()))
|
||||
res = broker.reclaim(normalize_timestamp(time()), time())
|
||||
broker.reclaim(normalize_timestamp(time()), time())
|
||||
# self.assertEquals(len(res), 2)
|
||||
# self.assert_(isinstance(res, tuple))
|
||||
# containers, account_name = res
|
||||
|
@ -418,6 +418,7 @@ class TestDBReplicator(unittest.TestCase):
|
||||
replicator = TestReplicator({})
|
||||
replicator._zero_stats()
|
||||
replicator._report_stats()
|
||||
|
||||
def test_replicate_object(self):
|
||||
db_replicator.ring = FakeRingWithNodes()
|
||||
replicator = TestReplicator({})
|
||||
@ -431,6 +432,7 @@ class TestDBReplicator(unittest.TestCase):
|
||||
'/a/b/c/d/e/hey')
|
||||
self._patch(patch.object, replicator.brokerclass,
|
||||
'get_repl_missing_table', True)
|
||||
|
||||
def mock_renamer(was, new, cause_colision=False):
|
||||
if cause_colision and '-' not in new:
|
||||
raise OSError(errno.EEXIST, "File already exists")
|
||||
@ -500,7 +502,6 @@ class TestDBReplicator(unittest.TestCase):
|
||||
[(('Found /path/to/file for /a%20c%20t/c%20o%20n when it should '
|
||||
'be on partition 0; will replicate out and remove.',), {})])
|
||||
|
||||
|
||||
def test_delete_db(self):
|
||||
db_replicator.lock_parent_directory = lock_parent_directory
|
||||
replicator = TestReplicator({})
|
||||
@ -775,13 +776,12 @@ class TestReplToNode(unittest.TestCase):
|
||||
'created_at': 100, 'put_timestamp': 0,
|
||||
'delete_timestamp': 0, 'count': 0,
|
||||
'metadata': {'Test': ('Value', normalize_timestamp(1))}}
|
||||
self.replicator.logger= mock.Mock()
|
||||
self.replicator.logger = mock.Mock()
|
||||
self.replicator._rsync_db = mock.Mock(return_value=True)
|
||||
self.replicator._usync_db = mock.Mock(return_value=True)
|
||||
self.http = ReplHttp('{"id": 3, "point": -1}')
|
||||
self.replicator._http_connect = lambda *args: self.http
|
||||
|
||||
|
||||
def test_repl_to_node_usync_success(self):
|
||||
rinfo = {"id": 3, "point": -1, "max_row": 5, "hash": "c"}
|
||||
self.http = ReplHttp(simplejson.dumps(rinfo))
|
||||
@ -796,7 +796,7 @@ class TestReplToNode(unittest.TestCase):
|
||||
def test_repl_to_node_rsync_success(self):
|
||||
rinfo = {"id": 3, "point": -1, "max_row": 4, "hash": "c"}
|
||||
self.http = ReplHttp(simplejson.dumps(rinfo))
|
||||
local_sync = self.broker.get_sync()
|
||||
self.broker.get_sync()
|
||||
self.assertEquals(self.replicator._repl_to_node(
|
||||
self.fake_node, self.broker, '0', self.fake_info), True)
|
||||
self.replicator.logger.increment.assert_has_calls([
|
||||
@ -811,13 +811,13 @@ class TestReplToNode(unittest.TestCase):
|
||||
def test_repl_to_node_already_in_sync(self):
|
||||
rinfo = {"id": 3, "point": -1, "max_row": 10, "hash": "b"}
|
||||
self.http = ReplHttp(simplejson.dumps(rinfo))
|
||||
local_sync = self.broker.get_sync()
|
||||
self.broker.get_sync()
|
||||
self.assertEquals(self.replicator._repl_to_node(
|
||||
self.fake_node, self.broker, '0', self.fake_info), True)
|
||||
self.assertEquals(self.replicator._rsync_db.call_count, 0)
|
||||
self.assertEquals(self.replicator._usync_db.call_count, 0)
|
||||
|
||||
def test_repl_to_node_not_found(self):
|
||||
def test_repl_to_node_not_found(self):
|
||||
self.http = ReplHttp('{"id": 3, "point": -1}', set_status=404)
|
||||
self.assertEquals(self.replicator._repl_to_node(
|
||||
self.fake_node, self.broker, '0', self.fake_info), True)
|
||||
|
@ -17,11 +17,10 @@ import unittest
|
||||
import os
|
||||
|
||||
import StringIO
|
||||
import cPickle as pickle
|
||||
from hashlib import md5
|
||||
|
||||
from swift.common import direct_client
|
||||
from swiftclient import ClientException, json_loads
|
||||
from swiftclient import json_loads
|
||||
|
||||
|
||||
def mock_http_connect(status, fake_headers=None, body=None):
|
||||
@ -46,7 +45,7 @@ def mock_http_connect(status, fake_headers=None, body=None):
|
||||
raise Exception('test')
|
||||
|
||||
if self.fake_headers is not None and self.method == 'POST':
|
||||
self.fake_headers.append(self.headers)
|
||||
self.fake_headers.append(self.headers)
|
||||
return self
|
||||
|
||||
def getheader(self, header, default=None):
|
||||
@ -55,7 +54,7 @@ def mock_http_connect(status, fake_headers=None, body=None):
|
||||
def getheaders(self):
|
||||
if self.fake_headers is not None:
|
||||
for key in self.fake_headers:
|
||||
self.headers.update({key: self.fake_headers[key]})
|
||||
self.headers.update({key: self.fake_headers[key]})
|
||||
return self.headers.items()
|
||||
|
||||
def read(self):
|
||||
@ -104,11 +103,9 @@ class TestDirectClient(unittest.TestCase):
|
||||
assert len(hdrs.keys()) == 1
|
||||
|
||||
def test_direct_get_account(self):
|
||||
node = {'ip':'1.2.3.4', 'port':'6000', 'device':'sda'}
|
||||
node = {'ip': '1.2.3.4', 'port': '6000', 'device': 'sda'}
|
||||
part = '0'
|
||||
account = 'a'
|
||||
container = 'c'
|
||||
name = 'o'
|
||||
headers = {
|
||||
'X-Account-Container-Count': '1',
|
||||
'X-Account-Object-Count': '1',
|
||||
@ -121,91 +118,77 @@ class TestDirectClient(unittest.TestCase):
|
||||
fake_headers = {}
|
||||
for header, value in headers.items():
|
||||
fake_headers[header.lower()] = value
|
||||
|
||||
|
||||
was_http_connector = direct_client.http_connect
|
||||
direct_client.http_connect = mock_http_connect(200, fake_headers, body)
|
||||
|
||||
resp_headers, resp = direct_client.direct_get_account(node, part, account)
|
||||
|
||||
fake_headers.update({'user-agent':'direct-client %s' % os.getpid()})
|
||||
fake_headers.update({'user-agent': 'direct-client %s' % os.getpid()})
|
||||
self.assertEqual(fake_headers, resp_headers)
|
||||
self.assertEqual(json_loads(body), resp)
|
||||
|
||||
|
||||
direct_client.http_connect = mock_http_connect(204, fake_headers, body)
|
||||
|
||||
resp_headers, resp = direct_client.direct_get_account(node, part, account)
|
||||
|
||||
fake_headers.update({'user-agent':'direct-client %s' % os.getpid()})
|
||||
fake_headers.update({'user-agent': 'direct-client %s' % os.getpid()})
|
||||
self.assertEqual(fake_headers, resp_headers)
|
||||
self.assertEqual([], resp)
|
||||
|
||||
|
||||
direct_client.http_connect = was_http_connector
|
||||
|
||||
def test_direct_head_container(self):
|
||||
node = {'ip':'1.2.3.4', 'port':'6000', 'device':'sda'}
|
||||
node = {'ip': '1.2.3.4', 'port': '6000', 'device': 'sda'}
|
||||
part = '0'
|
||||
account = 'a'
|
||||
container = 'c'
|
||||
name = 'o'
|
||||
contents = StringIO.StringIO('123456')
|
||||
headers = {'key':'value'}
|
||||
|
||||
headers = {'key': 'value'}
|
||||
|
||||
was_http_connector = direct_client.http_connect
|
||||
direct_client.http_connect = mock_http_connect(200, headers)
|
||||
|
||||
resp = direct_client.direct_head_container(node, part, account, container)
|
||||
|
||||
headers.update({'user-agent':'direct-client %s' % os.getpid()})
|
||||
headers.update({'user-agent': 'direct-client %s' % os.getpid()})
|
||||
self.assertEqual(headers, resp)
|
||||
|
||||
direct_client.http_connect = was_http_connector
|
||||
|
||||
def test_direct_get_container(self):
|
||||
node = {'ip':'1.2.3.4', 'port':'6000', 'device':'sda'}
|
||||
node = {'ip': '1.2.3.4', 'port': '6000', 'device': 'sda'}
|
||||
part = '0'
|
||||
account = 'a'
|
||||
container = 'c'
|
||||
name = 'o'
|
||||
contents = StringIO.StringIO('123456')
|
||||
headers = {'key':'value'}
|
||||
headers = {'key': 'value'}
|
||||
body = '[{"hash": "8f4e3", "last_modified": "317260", "bytes": 209}]'
|
||||
|
||||
|
||||
was_http_connector = direct_client.http_connect
|
||||
direct_client.http_connect = mock_http_connect(200, headers, body)
|
||||
|
||||
resp_headers, resp = \
|
||||
direct_client.direct_get_container(node, part, account, container)
|
||||
resp_headers, resp = (
|
||||
direct_client.direct_get_container(node, part, account, container))
|
||||
|
||||
headers.update({'user-agent':'direct-client %s' % os.getpid()})
|
||||
headers.update({'user-agent': 'direct-client %s' % os.getpid()})
|
||||
self.assertEqual(headers, resp_headers)
|
||||
self.assertEqual(json_loads(body), resp)
|
||||
|
||||
|
||||
direct_client.http_connect = mock_http_connect(204, headers, body)
|
||||
|
||||
resp_headers, resp = \
|
||||
direct_client.direct_get_container(node, part, account, container)
|
||||
resp_headers, resp = (
|
||||
direct_client.direct_get_container(node, part, account, container))
|
||||
|
||||
headers.update({'user-agent':'direct-client %s' % os.getpid()})
|
||||
headers.update({'user-agent': 'direct-client %s' % os.getpid()})
|
||||
self.assertEqual(headers, resp_headers)
|
||||
self.assertEqual([], resp)
|
||||
|
||||
|
||||
direct_client.http_connect = was_http_connector
|
||||
|
||||
def test_direct_delete_container(self):
|
||||
node = {'ip':'1.2.3.4', 'port':'6000', 'device':'sda'}
|
||||
node = {'ip': '1.2.3.4', 'port': '6000', 'device': 'sda'}
|
||||
part = '0'
|
||||
account = 'a'
|
||||
container = 'c'
|
||||
name = 'o'
|
||||
contents = StringIO.StringIO('123456')
|
||||
headers = {'key':'value'}
|
||||
|
||||
|
||||
was_http_connector = direct_client.http_connect
|
||||
direct_client.http_connect = mock_http_connect(200)
|
||||
@ -215,27 +198,25 @@ class TestDirectClient(unittest.TestCase):
|
||||
direct_client.http_connect = was_http_connector
|
||||
|
||||
def test_direct_head_object(self):
|
||||
node = {'ip':'1.2.3.4', 'port':'6000', 'device':'sda'}
|
||||
node = {'ip': '1.2.3.4', 'port': '6000', 'device': 'sda'}
|
||||
part = '0'
|
||||
account = 'a'
|
||||
container = 'c'
|
||||
name = 'o'
|
||||
contents = StringIO.StringIO('123456')
|
||||
headers = {'key':'value'}
|
||||
|
||||
headers = {'key': 'value'}
|
||||
|
||||
was_http_connector = direct_client.http_connect
|
||||
direct_client.http_connect = mock_http_connect(200, headers)
|
||||
|
||||
resp = direct_client.direct_head_object(node, part, account,
|
||||
container, name)
|
||||
headers.update({'user-agent':'direct-client %s' % os.getpid()})
|
||||
headers.update({'user-agent': 'direct-client %s' % os.getpid()})
|
||||
self.assertEqual(headers, resp)
|
||||
|
||||
direct_client.http_connect = was_http_connector
|
||||
|
||||
def test_direct_get_object(self):
|
||||
node = {'ip':'1.2.3.4', 'port':'6000', 'device':'sda'}
|
||||
node = {'ip': '1.2.3.4', 'port': '6000', 'device': 'sda'}
|
||||
part = '0'
|
||||
account = 'a'
|
||||
container = 'c'
|
||||
@ -245,8 +226,8 @@ class TestDirectClient(unittest.TestCase):
|
||||
was_http_connector = direct_client.http_connect
|
||||
direct_client.http_connect = mock_http_connect(200, body=contents)
|
||||
|
||||
resp_header, obj_body = \
|
||||
direct_client.direct_get_object(node, part, account, container, name)
|
||||
resp_header, obj_body = (
|
||||
direct_client.direct_get_object(node, part, account, container, name))
|
||||
self.assertEqual(obj_body, contents)
|
||||
|
||||
direct_client.http_connect = was_http_connector
|
||||
@ -254,13 +235,12 @@ class TestDirectClient(unittest.TestCase):
|
||||
pass
|
||||
|
||||
def test_direct_post_object(self):
|
||||
node = {'ip':'1.2.3.4', 'port':'6000', 'device':'sda'}
|
||||
node = {'ip': '1.2.3.4', 'port': '6000', 'device': 'sda'}
|
||||
part = '0'
|
||||
account = 'a'
|
||||
container = 'c'
|
||||
name = 'o'
|
||||
contents = StringIO.StringIO('123456')
|
||||
headers = {'Key':'value'}
|
||||
headers = {'Key': 'value'}
|
||||
|
||||
fake_headers = []
|
||||
|
||||
@ -274,12 +254,11 @@ class TestDirectClient(unittest.TestCase):
|
||||
direct_client.http_connect = was_http_connector
|
||||
|
||||
def test_direct_delete_object(self):
|
||||
node = {'ip':'1.2.3.4', 'port':'6000', 'device':'sda'}
|
||||
node = {'ip': '1.2.3.4', 'port': '6000', 'device': 'sda'}
|
||||
part = '0'
|
||||
account = 'a'
|
||||
container = 'c'
|
||||
name = 'o'
|
||||
contents = StringIO.StringIO('123456')
|
||||
|
||||
was_http_connector = direct_client.http_connect
|
||||
direct_client.http_connect = mock_http_connect(200)
|
||||
@ -289,7 +268,7 @@ class TestDirectClient(unittest.TestCase):
|
||||
direct_client.http_connect = was_http_connector
|
||||
|
||||
def test_direct_put_object(self):
|
||||
node = {'ip':'1.2.3.4', 'port':'6000', 'device':'sda'}
|
||||
node = {'ip': '1.2.3.4', 'port': '6000', 'device': 'sda'}
|
||||
part = '0'
|
||||
account = 'a'
|
||||
container = 'c'
|
||||
@ -306,7 +285,7 @@ class TestDirectClient(unittest.TestCase):
|
||||
direct_client.http_connect = was_http_connector
|
||||
|
||||
def test_direct_put_object_fail(self):
|
||||
node = {'ip':'1.2.3.4', 'port':'6000', 'device':'sda'}
|
||||
node = {'ip': '1.2.3.4', 'port': '6000', 'device': 'sda'}
|
||||
part = '0'
|
||||
account = 'a'
|
||||
container = 'c'
|
||||
@ -316,14 +295,14 @@ class TestDirectClient(unittest.TestCase):
|
||||
was_http_connector = direct_client.http_connect
|
||||
direct_client.http_connect = mock_http_connect(500)
|
||||
|
||||
self.assertRaises(direct_client.ClientException,\
|
||||
direct_client.direct_put_object, node, part, account,\
|
||||
self.assertRaises(direct_client.ClientException,
|
||||
direct_client.direct_put_object, node, part, account,
|
||||
container, name, contents)
|
||||
|
||||
direct_client.http_connect = was_http_connector
|
||||
|
||||
def test_direct_put_object_chunked(self):
|
||||
node = {'ip':'1.2.3.4', 'port':'6000', 'device':'sda'}
|
||||
node = {'ip': '1.2.3.4', 'port': '6000', 'device': 'sda'}
|
||||
part = '0'
|
||||
account = 'a'
|
||||
container = 'c'
|
||||
@ -333,33 +312,30 @@ class TestDirectClient(unittest.TestCase):
|
||||
was_http_connector = direct_client.http_connect
|
||||
direct_client.http_connect = mock_http_connect(200)
|
||||
|
||||
resp = direct_client.direct_put_object(node, part, account,\
|
||||
resp = direct_client.direct_put_object(node, part, account,
|
||||
container, name, contents)
|
||||
self.assertEqual(md5('6\r\n123456\r\n0\r\n\r\n').hexdigest(), resp)
|
||||
|
||||
direct_client.http_connect = was_http_connector
|
||||
|
||||
def test_retry(self):
|
||||
node = {'ip':'1.2.3.4', 'port':'6000', 'device':'sda'}
|
||||
node = {'ip': '1.2.3.4', 'port': '6000', 'device': 'sda'}
|
||||
part = '0'
|
||||
account = 'a'
|
||||
container = 'c'
|
||||
name = 'o'
|
||||
contents = StringIO.StringIO('123456')
|
||||
headers = {'key':'value'}
|
||||
headers = {'key': 'value'}
|
||||
|
||||
was_http_connector = direct_client.http_connect
|
||||
direct_client.http_connect = mock_http_connect(200, headers)
|
||||
|
||||
attempts, resp = direct_client.retry(direct_client.direct_head_object,\
|
||||
attempts, resp = direct_client.retry(direct_client.direct_head_object,
|
||||
node, part, account, container, name)
|
||||
headers.update({'user-agent':'direct-client %s' % os.getpid()})
|
||||
headers.update({'user-agent': 'direct-client %s' % os.getpid()})
|
||||
self.assertEqual(headers, resp)
|
||||
self.assertEqual(attempts, 1)
|
||||
|
||||
|
||||
direct_client.http_connect = was_http_connector
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
|
@ -16,7 +16,6 @@
|
||||
# TODO: Tests
|
||||
|
||||
import unittest
|
||||
from swift.common import exceptions
|
||||
|
||||
|
||||
class TestExceptions(unittest.TestCase):
|
||||
|
@ -284,7 +284,7 @@ class TestInternalClient(unittest.TestCase):
|
||||
try:
|
||||
client.make_request('GET', '/', {}, (400,))
|
||||
except Exception, err:
|
||||
exc = err
|
||||
pass
|
||||
self.assertEquals(200, err.resp.status_int)
|
||||
try:
|
||||
client.make_request('GET', '/', {}, (201,))
|
||||
|
@ -526,7 +526,7 @@ class TestRequest(unittest.TestCase):
|
||||
req.query_string = u'x=\u2661'
|
||||
self.assertEquals(req.params['x'], u'\u2661'.encode('utf-8'))
|
||||
|
||||
def test_url(self):
|
||||
def test_url2(self):
|
||||
pi = '/hi/there'
|
||||
path = pi
|
||||
req = swift.common.swob.Request.blank(path)
|
||||
@ -595,7 +595,7 @@ class TestRequest(unittest.TestCase):
|
||||
|
||||
req.headers['Content-Length'] = 'abc'
|
||||
try:
|
||||
l = req.message_length()
|
||||
req.message_length()
|
||||
except ValueError as e:
|
||||
self.assertEquals(str(e), "Invalid Content-Length header value")
|
||||
else:
|
||||
@ -611,7 +611,7 @@ class TestRequest(unittest.TestCase):
|
||||
|
||||
req.headers['Transfer-Encoding'] = 'gzip,chunked'
|
||||
try:
|
||||
l = req.message_length()
|
||||
req.message_length()
|
||||
except AttributeError as e:
|
||||
self.assertEquals(str(e), "Unsupported Transfer-Coding header"
|
||||
" value specified in Transfer-Encoding header")
|
||||
@ -620,7 +620,7 @@ class TestRequest(unittest.TestCase):
|
||||
|
||||
req.headers['Transfer-Encoding'] = 'gzip'
|
||||
try:
|
||||
l = req.message_length()
|
||||
req.message_length()
|
||||
except ValueError as e:
|
||||
self.assertEquals(str(e), "Invalid Transfer-Encoding header value")
|
||||
else:
|
||||
@ -628,7 +628,7 @@ class TestRequest(unittest.TestCase):
|
||||
|
||||
req.headers['Transfer-Encoding'] = 'gzip,identity'
|
||||
try:
|
||||
l = req.message_length()
|
||||
req.message_length()
|
||||
except AttributeError as e:
|
||||
self.assertEquals(str(e), "Unsupported Transfer-Coding header"
|
||||
" value specified in Transfer-Encoding header")
|
||||
|
@ -1910,7 +1910,7 @@ class TestGreenthreadSafeIterator(unittest.TestCase):
|
||||
pile.spawn(self.increment, iterable)
|
||||
|
||||
try:
|
||||
response = sorted([resp for resp in pile])
|
||||
sorted([resp for resp in pile])
|
||||
self.assertTrue(False, "test setup is insufficiently crazy")
|
||||
except ValueError:
|
||||
pass
|
||||
|
@ -16,10 +16,9 @@
|
||||
# TODO: Tests
|
||||
|
||||
import unittest
|
||||
from swift.container import auditor
|
||||
|
||||
|
||||
class TestReaper(unittest.TestCase):
|
||||
|
||||
def test_placeholder(self):
|
||||
pass
|
||||
|
||||
|
@ -17,30 +17,21 @@
|
||||
""" Tests for swift.obj.diskfile """
|
||||
|
||||
import cPickle as pickle
|
||||
import operator
|
||||
import os
|
||||
import mock
|
||||
import unittest
|
||||
import email
|
||||
from shutil import rmtree
|
||||
from StringIO import StringIO
|
||||
from time import gmtime, strftime, time
|
||||
from time import time
|
||||
from tempfile import mkdtemp
|
||||
from hashlib import md5
|
||||
|
||||
from eventlet import sleep, spawn, wsgi, listen, Timeout, tpool
|
||||
from eventlet import tpool
|
||||
from test.unit import FakeLogger
|
||||
from test.unit import _setxattr as setxattr
|
||||
from test.unit import connect_tcp, readuntil2crlfs
|
||||
from swift.obj import diskfile
|
||||
from swift.common import utils
|
||||
from swift.common.utils import hash_path, mkdirs, normalize_timestamp, \
|
||||
NullLogger, storage_directory, public, \
|
||||
replication
|
||||
from swift.common.utils import mkdirs, normalize_timestamp
|
||||
from swift.common.exceptions import DiskFileNotExist, DiskFileDeviceUnavailable
|
||||
from swift.common import constraints
|
||||
from eventlet import tpool
|
||||
from swift.common.swob import Request, HeaderKeyDict
|
||||
|
||||
|
||||
class TestDiskFile(unittest.TestCase):
|
||||
@ -146,11 +137,12 @@ class TestDiskFile(unittest.TestCase):
|
||||
tmpdir = os.path.join(self.testdir, 'sda1', 'tmp')
|
||||
os.rmdir(tmpdir)
|
||||
with diskfile.DiskFile(self.testdir, 'sda1', '0', 'a', 'c',
|
||||
'o', FakeLogger()).writer() as writer:
|
||||
'o', FakeLogger()).writer():
|
||||
self.assert_(os.path.exists(tmpdir))
|
||||
|
||||
def test_iter_hook(self):
|
||||
hook_call_count = [0]
|
||||
|
||||
def hook():
|
||||
hook_call_count[0] += 1
|
||||
|
||||
@ -334,7 +326,7 @@ class TestDiskFile(unittest.TestCase):
|
||||
def test_put_metadata(self):
|
||||
df = self._get_disk_file()
|
||||
ts = time()
|
||||
metadata = { 'X-Timestamp': ts, 'X-Object-Meta-test': 'data' }
|
||||
metadata = {'X-Timestamp': ts, 'X-Object-Meta-test': 'data'}
|
||||
df.put_metadata(metadata)
|
||||
exp_name = '%s.meta' % str(normalize_timestamp(ts))
|
||||
dl = os.listdir(df.datadir)
|
||||
@ -344,7 +336,7 @@ class TestDiskFile(unittest.TestCase):
|
||||
def test_put_metadata_ts(self):
|
||||
df = self._get_disk_file()
|
||||
ts = time()
|
||||
metadata = { 'X-Timestamp': ts, 'X-Object-Meta-test': 'data' }
|
||||
metadata = {'X-Timestamp': ts, 'X-Object-Meta-test': 'data'}
|
||||
df.put_metadata(metadata, tombstone=True)
|
||||
exp_name = '%s.ts' % str(normalize_timestamp(ts))
|
||||
dl = os.listdir(df.datadir)
|
||||
@ -354,7 +346,7 @@ class TestDiskFile(unittest.TestCase):
|
||||
def test_unlinkold(self):
|
||||
df1 = self._get_disk_file()
|
||||
future_time = str(normalize_timestamp(time() + 100))
|
||||
df2 = self._get_disk_file(ts=future_time)
|
||||
self._get_disk_file(ts=future_time)
|
||||
self.assertEquals(len(os.listdir(df1.datadir)), 2)
|
||||
df1.unlinkold(future_time)
|
||||
self.assertEquals(len(os.listdir(df1.datadir)), 1)
|
||||
|
@ -188,7 +188,6 @@ class TestObjectExpirer(TestCase):
|
||||
self.test.assertEqual(self.timestamp, timestamp)
|
||||
self.called = True
|
||||
|
||||
account = 'account'
|
||||
container = 'container'
|
||||
obj = 'obj'
|
||||
actual_obj = 'actual_obj'
|
||||
|
@ -985,7 +985,7 @@ class TestObjectController(unittest.TestCase):
|
||||
resp = self.object_controller.GET(req)
|
||||
quar_dir = os.path.join(self.testdir, 'sda1', 'quarantined', 'objects',
|
||||
os.path.basename(os.path.dirname(file.data_file)))
|
||||
body = resp.body
|
||||
resp.body
|
||||
self.assertEquals(os.listdir(file.datadir)[0], file_name)
|
||||
self.assertFalse(os.path.isdir(quar_dir))
|
||||
req = Request.blank('/sda1/p/a/c/o')
|
||||
@ -997,7 +997,7 @@ class TestObjectController(unittest.TestCase):
|
||||
resp = self.object_controller.GET(req)
|
||||
quar_dir = os.path.join(self.testdir, 'sda1', 'quarantined', 'objects',
|
||||
os.path.basename(os.path.dirname(file.data_file)))
|
||||
body = resp.body
|
||||
resp.body
|
||||
self.assertEquals(os.listdir(file.datadir)[0], file_name)
|
||||
self.assertFalse(os.path.isdir(quar_dir))
|
||||
|
||||
@ -1007,7 +1007,7 @@ class TestObjectController(unittest.TestCase):
|
||||
quar_dir = os.path.join(self.testdir, 'sda1', 'quarantined', 'objects',
|
||||
os.path.basename(os.path.dirname(file.data_file)))
|
||||
self.assertEquals(os.listdir(file.datadir)[0], file_name)
|
||||
body = resp.body
|
||||
resp.body
|
||||
self.assertTrue(os.path.isdir(quar_dir))
|
||||
req = Request.blank('/sda1/p/a/c/o')
|
||||
resp = self.object_controller.GET(req)
|
||||
@ -1142,6 +1142,7 @@ class TestObjectController(unittest.TestCase):
|
||||
|
||||
def my_check(*args):
|
||||
return False
|
||||
|
||||
def my_storage_directory(*args):
|
||||
return self.testdir+'/collide'
|
||||
_storage_directory = diskfile.storage_directory
|
||||
@ -1202,6 +1203,7 @@ class TestObjectController(unittest.TestCase):
|
||||
def test_invalid_method_doesnt_exist(self):
|
||||
errbuf = StringIO()
|
||||
outbuf = StringIO()
|
||||
|
||||
def start_response(*args):
|
||||
outbuf.writelines(args)
|
||||
self.object_controller.__call__({'REQUEST_METHOD': 'method_doesnt_exist',
|
||||
@ -1213,6 +1215,7 @@ class TestObjectController(unittest.TestCase):
|
||||
def test_invalid_method_is_not_public(self):
|
||||
errbuf = StringIO()
|
||||
outbuf = StringIO()
|
||||
|
||||
def start_response(*args):
|
||||
outbuf.writelines(args)
|
||||
self.object_controller.__call__({'REQUEST_METHOD': '__init__',
|
||||
@ -1448,12 +1451,12 @@ class TestObjectController(unittest.TestCase):
|
||||
'/a/c/o', {'x-timestamp': '1', 'x-out': 'set',
|
||||
'user-agent': 'obj-server %s' % os.getpid()}])
|
||||
|
||||
|
||||
def test_updating_multiple_delete_at_container_servers(self):
|
||||
self.object_controller.expiring_objects_account = 'exp'
|
||||
self.object_controller.expiring_objects_container_divisor = 60
|
||||
|
||||
http_connect_args = []
|
||||
|
||||
def fake_http_connect(ipaddr, port, device, partition, method, path,
|
||||
headers=None, query_string=None, ssl=False):
|
||||
class SuccessfulFakeConn(object):
|
||||
@ -1473,7 +1476,7 @@ class TestObjectController(unittest.TestCase):
|
||||
'headers': headers, 'query_string': query_string}
|
||||
|
||||
http_connect_args.append(
|
||||
dict((k,v) for k,v in captured_args.iteritems()
|
||||
dict((k, v) for k, v in captured_args.iteritems()
|
||||
if v is not None))
|
||||
|
||||
req = Request.blank(
|
||||
@ -1500,7 +1503,6 @@ class TestObjectController(unittest.TestCase):
|
||||
|
||||
self.assertEqual(resp.status_int, 201)
|
||||
|
||||
|
||||
http_connect_args.sort(key=operator.itemgetter('ipaddr'))
|
||||
|
||||
self.assertEquals(len(http_connect_args), 3)
|
||||
@ -1555,6 +1557,7 @@ class TestObjectController(unittest.TestCase):
|
||||
|
||||
def test_updating_multiple_container_servers(self):
|
||||
http_connect_args = []
|
||||
|
||||
def fake_http_connect(ipaddr, port, device, partition, method, path,
|
||||
headers=None, query_string=None, ssl=False):
|
||||
class SuccessfulFakeConn(object):
|
||||
@ -1574,7 +1577,7 @@ class TestObjectController(unittest.TestCase):
|
||||
'headers': headers, 'query_string': query_string}
|
||||
|
||||
http_connect_args.append(
|
||||
dict((k,v) for k,v in captured_args.iteritems()
|
||||
dict((k, v) for k, v in captured_args.iteritems()
|
||||
if v is not None))
|
||||
|
||||
req = Request.blank(
|
||||
@ -2472,7 +2475,6 @@ class TestObjectController(unittest.TestCase):
|
||||
inbuf = StringIO()
|
||||
errbuf = StringIO()
|
||||
outbuf = StringIO()
|
||||
method_called = False
|
||||
self.object_controller = object_server.ObjectController(
|
||||
{'devices': self.testdir, 'mount_check': 'false',
|
||||
'replication_server': 'false'})
|
||||
|
@ -15,9 +15,7 @@
|
||||
|
||||
import mock
|
||||
import unittest
|
||||
import swift.proxy.controllers.base
|
||||
|
||||
from contextlib import contextmanager
|
||||
from swift.common.swob import Request
|
||||
from swift.proxy import server as proxy_server
|
||||
from swift.proxy.controllers.base import headers_to_account_info
|
||||
|
@ -21,12 +21,13 @@ from swift.proxy.controllers.base import headers_to_container_info, \
|
||||
Controller
|
||||
from swift.common.swob import Request
|
||||
from swift.common.utils import split_path
|
||||
import swift.proxy.controllers.base
|
||||
from test.unit import FakeLogger, fake_http_connect, FakeRing, FakeMemcache
|
||||
from test.unit import fake_http_connect, FakeRing, FakeMemcache
|
||||
from swift.proxy import server as proxy_server
|
||||
|
||||
|
||||
FakeResponse_status_int = 201
|
||||
|
||||
|
||||
class FakeResponse(object):
|
||||
def __init__(self, headers, env, account, container):
|
||||
self.headers = headers
|
||||
|
@ -15,9 +15,7 @@
|
||||
|
||||
import mock
|
||||
import unittest
|
||||
import swift.proxy.controllers.base
|
||||
|
||||
from contextlib import contextmanager
|
||||
from swift.common.swob import Request
|
||||
from swift.proxy import server as proxy_server
|
||||
from swift.proxy.controllers.base import headers_to_container_info
|
||||
|
@ -14,11 +14,10 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import mock
|
||||
import unittest
|
||||
|
||||
from swift.proxy import server as proxy_server
|
||||
from test.unit import fake_http_connect, FakeRing, FakeMemcache
|
||||
from test.unit import FakeRing, FakeMemcache
|
||||
|
||||
|
||||
class TestObjControllerWriteAffinity(unittest.TestCase):
|
||||
@ -39,8 +38,6 @@ class TestObjControllerWriteAffinity(unittest.TestCase):
|
||||
local_first_nodes = list(controller.iter_nodes_local_first(
|
||||
self.app.object_ring, 1))
|
||||
|
||||
fr = FakeRing()
|
||||
|
||||
self.maxDiff = None
|
||||
|
||||
self.assertEqual(all_nodes, local_first_nodes)
|
||||
|
@ -28,7 +28,6 @@ import time
|
||||
from urllib import quote
|
||||
from hashlib import md5
|
||||
from tempfile import mkdtemp
|
||||
import random
|
||||
|
||||
import mock
|
||||
from eventlet import sleep, spawn, wsgi, listen
|
||||
@ -61,6 +60,8 @@ logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
|
||||
|
||||
STATIC_TIME = time.time()
|
||||
_request_instances = 0
|
||||
_test_coros = _test_servers = _test_sockets = _orig_container_listing_limit = \
|
||||
_testdir = _orig_SysLogHandler = None
|
||||
|
||||
|
||||
def request_init(self, *args, **kwargs):
|
||||
@ -548,7 +549,7 @@ class TestProxyServer(unittest.TestCase):
|
||||
req = Request.blank('/v1/a')
|
||||
req.environ['swift.authorize'] = authorize
|
||||
app.update_request(req)
|
||||
resp = app.handle_request(req)
|
||||
app.handle_request(req)
|
||||
self.assert_(called[0])
|
||||
|
||||
def test_calls_authorize_deny(self):
|
||||
@ -564,7 +565,7 @@ class TestProxyServer(unittest.TestCase):
|
||||
req = Request.blank('/v1/a')
|
||||
req.environ['swift.authorize'] = authorize
|
||||
app.update_request(req)
|
||||
resp = app.handle_request(req)
|
||||
app.handle_request(req)
|
||||
self.assert_(called[0])
|
||||
|
||||
def test_negative_content_length(self):
|
||||
@ -639,7 +640,7 @@ class TestProxyServer(unittest.TestCase):
|
||||
|
||||
nodes = [{'region': 2, 'zone': 1, 'ip': '127.0.0.1'},
|
||||
{'region': 1, 'zone': 2, 'ip': '127.0.0.2'}]
|
||||
with mock.patch('swift.proxy.server.shuffle', lambda x:x):
|
||||
with mock.patch('swift.proxy.server.shuffle', lambda x: x):
|
||||
app_sorted = baseapp.sort_nodes(nodes)
|
||||
exp_sorted = [{'region': 1, 'zone': 2, 'ip': '127.0.0.2'},
|
||||
{'region': 2, 'zone': 1, 'ip': '127.0.0.1'}]
|
||||
@ -1042,7 +1043,7 @@ class TestObjectController(unittest.TestCase):
|
||||
headers={'X-If-Delete-At': 1},
|
||||
environ={'REQUEST_METHOD': 'DELETE'})
|
||||
self.app.update_request(req)
|
||||
res = controller.DELETE(req)
|
||||
controller.DELETE(req)
|
||||
self.assertEquals(test_errors, [])
|
||||
|
||||
def test_GET_manifest_no_segments(self):
|
||||
@ -1627,10 +1628,10 @@ class TestObjectController(unittest.TestCase):
|
||||
try:
|
||||
with open(os.path.join(swift_dir, 'mime.types'), 'w') as fp:
|
||||
fp.write('foo/bar foo\n')
|
||||
ba = proxy_server.Application({'swift_dir': swift_dir},
|
||||
FakeMemcache(), FakeLogger(),
|
||||
FakeRing(), FakeRing(),
|
||||
FakeRing())
|
||||
proxy_server.Application({'swift_dir': swift_dir},
|
||||
FakeMemcache(), FakeLogger(),
|
||||
FakeRing(), FakeRing(),
|
||||
FakeRing())
|
||||
self.assertEquals(proxy_server.mimetypes.guess_type('blah.foo')[0],
|
||||
'foo/bar')
|
||||
self.assertEquals(proxy_server.mimetypes.guess_type('blah.jpg')[0],
|
||||
@ -4040,7 +4041,7 @@ class TestObjectController(unittest.TestCase):
|
||||
req = Request.blank('/a/c/o')
|
||||
req.environ['swift.authorize'] = authorize
|
||||
self.app.update_request(req)
|
||||
res = controller.GET(req)
|
||||
controller.GET(req)
|
||||
self.assert_(called[0])
|
||||
|
||||
def test_HEAD_calls_authorize(self):
|
||||
@ -4056,7 +4057,7 @@ class TestObjectController(unittest.TestCase):
|
||||
req = Request.blank('/a/c/o', {'REQUEST_METHOD': 'HEAD'})
|
||||
req.environ['swift.authorize'] = authorize
|
||||
self.app.update_request(req)
|
||||
res = controller.HEAD(req)
|
||||
controller.HEAD(req)
|
||||
self.assert_(called[0])
|
||||
|
||||
def test_POST_calls_authorize(self):
|
||||
@ -4074,7 +4075,7 @@ class TestObjectController(unittest.TestCase):
|
||||
headers={'Content-Length': '5'}, body='12345')
|
||||
req.environ['swift.authorize'] = authorize
|
||||
self.app.update_request(req)
|
||||
res = controller.POST(req)
|
||||
controller.POST(req)
|
||||
self.assert_(called[0])
|
||||
|
||||
def test_POST_as_copy_calls_authorize(self):
|
||||
@ -4091,7 +4092,7 @@ class TestObjectController(unittest.TestCase):
|
||||
headers={'Content-Length': '5'}, body='12345')
|
||||
req.environ['swift.authorize'] = authorize
|
||||
self.app.update_request(req)
|
||||
res = controller.POST(req)
|
||||
controller.POST(req)
|
||||
self.assert_(called[0])
|
||||
|
||||
def test_PUT_calls_authorize(self):
|
||||
@ -4108,7 +4109,7 @@ class TestObjectController(unittest.TestCase):
|
||||
headers={'Content-Length': '5'}, body='12345')
|
||||
req.environ['swift.authorize'] = authorize
|
||||
self.app.update_request(req)
|
||||
res = controller.PUT(req)
|
||||
controller.PUT(req)
|
||||
self.assert_(called[0])
|
||||
|
||||
def test_COPY_calls_authorize(self):
|
||||
@ -4125,7 +4126,7 @@ class TestObjectController(unittest.TestCase):
|
||||
headers={'Destination': 'c/o'})
|
||||
req.environ['swift.authorize'] = authorize
|
||||
self.app.update_request(req)
|
||||
res = controller.COPY(req)
|
||||
controller.COPY(req)
|
||||
self.assert_(called[0])
|
||||
|
||||
def test_POST_converts_delete_after_to_delete_at(self):
|
||||
@ -4643,15 +4644,16 @@ class TestObjectController(unittest.TestCase):
|
||||
200, 200, 200, 200, 200) # HEAD HEAD DELETE DELETE DELETE
|
||||
|
||||
self.assertEqual(seen_headers, [
|
||||
{'X-Container-Host': '10.0.0.0:1000,10.0.0.3:1003',
|
||||
'X-Container-Partition': '1',
|
||||
'X-Container-Device': 'sda,sdd'},
|
||||
{'X-Container-Host': '10.0.0.1:1001',
|
||||
'X-Container-Partition': '1',
|
||||
'X-Container-Device': 'sdb'},
|
||||
{'X-Container-Host': '10.0.0.2:1002',
|
||||
'X-Container-Partition': '1',
|
||||
'X-Container-Device': 'sdc'}])
|
||||
{'X-Container-Host': '10.0.0.0:1000,10.0.0.3:1003',
|
||||
'X-Container-Partition': '1',
|
||||
'X-Container-Device': 'sda,sdd'},
|
||||
{'X-Container-Host': '10.0.0.1:1001',
|
||||
'X-Container-Partition': '1',
|
||||
'X-Container-Device': 'sdb'},
|
||||
{'X-Container-Host': '10.0.0.2:1002',
|
||||
'X-Container-Partition': '1',
|
||||
'X-Container-Device': 'sdc'}
|
||||
])
|
||||
|
||||
@mock.patch('time.time', new=lambda: STATIC_TIME)
|
||||
def test_PUT_x_delete_at_with_fewer_container_replicas(self):
|
||||
@ -4674,18 +4676,19 @@ class TestObjectController(unittest.TestCase):
|
||||
'X-Delete-At-Partition', 'X-Delete-At-Container'))
|
||||
|
||||
self.assertEqual(seen_headers, [
|
||||
{'X-Delete-At-Host': '10.0.0.0:1000',
|
||||
'X-Delete-At-Container': delete_at_container,
|
||||
'X-Delete-At-Partition': '1',
|
||||
'X-Delete-At-Device': 'sda'},
|
||||
{'X-Delete-At-Host': '10.0.0.1:1001',
|
||||
'X-Delete-At-Container': delete_at_container,
|
||||
'X-Delete-At-Partition': '1',
|
||||
'X-Delete-At-Device': 'sdb'},
|
||||
{'X-Delete-At-Host': None,
|
||||
'X-Delete-At-Container': None,
|
||||
'X-Delete-At-Partition': None,
|
||||
'X-Delete-At-Device': None}])
|
||||
{'X-Delete-At-Host': '10.0.0.0:1000',
|
||||
'X-Delete-At-Container': delete_at_container,
|
||||
'X-Delete-At-Partition': '1',
|
||||
'X-Delete-At-Device': 'sda'},
|
||||
{'X-Delete-At-Host': '10.0.0.1:1001',
|
||||
'X-Delete-At-Container': delete_at_container,
|
||||
'X-Delete-At-Partition': '1',
|
||||
'X-Delete-At-Device': 'sdb'},
|
||||
{'X-Delete-At-Host': None,
|
||||
'X-Delete-At-Container': None,
|
||||
'X-Delete-At-Partition': None,
|
||||
'X-Delete-At-Device': None}
|
||||
])
|
||||
|
||||
@mock.patch('time.time', new=lambda: STATIC_TIME)
|
||||
def test_PUT_x_delete_at_with_more_container_replicas(self):
|
||||
@ -4709,18 +4712,19 @@ class TestObjectController(unittest.TestCase):
|
||||
header_list=('X-Delete-At-Host', 'X-Delete-At-Device',
|
||||
'X-Delete-At-Partition', 'X-Delete-At-Container'))
|
||||
self.assertEqual(seen_headers, [
|
||||
{'X-Delete-At-Host': '10.0.0.0:1000,10.0.0.3:1003',
|
||||
'X-Delete-At-Container': delete_at_container,
|
||||
'X-Delete-At-Partition': '1',
|
||||
'X-Delete-At-Device': 'sda,sdd'},
|
||||
{'X-Delete-At-Host': '10.0.0.1:1001',
|
||||
'X-Delete-At-Container': delete_at_container,
|
||||
'X-Delete-At-Partition': '1',
|
||||
'X-Delete-At-Device': 'sdb'},
|
||||
{'X-Delete-At-Host': '10.0.0.2:1002',
|
||||
'X-Delete-At-Container': delete_at_container,
|
||||
'X-Delete-At-Partition': '1',
|
||||
'X-Delete-At-Device': 'sdc'}])
|
||||
{'X-Delete-At-Host': '10.0.0.0:1000,10.0.0.3:1003',
|
||||
'X-Delete-At-Container': delete_at_container,
|
||||
'X-Delete-At-Partition': '1',
|
||||
'X-Delete-At-Device': 'sda,sdd'},
|
||||
{'X-Delete-At-Host': '10.0.0.1:1001',
|
||||
'X-Delete-At-Container': delete_at_container,
|
||||
'X-Delete-At-Partition': '1',
|
||||
'X-Delete-At-Device': 'sdb'},
|
||||
{'X-Delete-At-Host': '10.0.0.2:1002',
|
||||
'X-Delete-At-Container': delete_at_container,
|
||||
'X-Delete-At-Partition': '1',
|
||||
'X-Delete-At-Device': 'sdc'}
|
||||
])
|
||||
|
||||
|
||||
class TestContainerController(unittest.TestCase):
|
||||
@ -5026,7 +5030,7 @@ class TestContainerController(unittest.TestCase):
|
||||
if self.allow_lock:
|
||||
yield True
|
||||
else:
|
||||
raise MemcacheLockError()
|
||||
raise NotImplementedError
|
||||
|
||||
with save_globals():
|
||||
controller = proxy_server.ContainerController(self.app, 'account',
|
||||
@ -5149,7 +5153,7 @@ class TestContainerController(unittest.TestCase):
|
||||
req = Request.blank('/a/c', environ={'REQUEST_METHOD': method},
|
||||
headers={test_header: test_value})
|
||||
self.app.update_request(req)
|
||||
res = getattr(controller, method)(req)
|
||||
getattr(controller, method)(req)
|
||||
self.assertEquals(test_errors, [])
|
||||
|
||||
def test_PUT_bad_metadata(self):
|
||||
@ -5256,7 +5260,7 @@ class TestContainerController(unittest.TestCase):
|
||||
headers={'X-Container-Read': '.r:*'})
|
||||
req.environ['swift.clean_acl'] = clean_acl
|
||||
self.app.update_request(req)
|
||||
res = controller.POST(req)
|
||||
controller.POST(req)
|
||||
self.assert_(called[0])
|
||||
called[0] = False
|
||||
with save_globals():
|
||||
@ -5267,7 +5271,7 @@ class TestContainerController(unittest.TestCase):
|
||||
headers={'X-Container-Write': '.r:*'})
|
||||
req.environ['swift.clean_acl'] = clean_acl
|
||||
self.app.update_request(req)
|
||||
res = controller.POST(req)
|
||||
controller.POST(req)
|
||||
self.assert_(called[0])
|
||||
|
||||
def test_PUT_calls_clean_acl(self):
|
||||
@ -5284,7 +5288,7 @@ class TestContainerController(unittest.TestCase):
|
||||
headers={'X-Container-Read': '.r:*'})
|
||||
req.environ['swift.clean_acl'] = clean_acl
|
||||
self.app.update_request(req)
|
||||
res = controller.PUT(req)
|
||||
controller.PUT(req)
|
||||
self.assert_(called[0])
|
||||
called[0] = False
|
||||
with save_globals():
|
||||
@ -5295,7 +5299,7 @@ class TestContainerController(unittest.TestCase):
|
||||
headers={'X-Container-Write': '.r:*'})
|
||||
req.environ['swift.clean_acl'] = clean_acl
|
||||
self.app.update_request(req)
|
||||
res = controller.PUT(req)
|
||||
controller.PUT(req)
|
||||
self.assert_(called[0])
|
||||
|
||||
def test_GET_no_content(self):
|
||||
@ -5340,7 +5344,7 @@ class TestContainerController(unittest.TestCase):
|
||||
req = Request.blank('/a/c', {'REQUEST_METHOD': 'HEAD'})
|
||||
req.environ['swift.authorize'] = authorize
|
||||
self.app.update_request(req)
|
||||
res = controller.HEAD(req)
|
||||
controller.HEAD(req)
|
||||
self.assert_(called[0])
|
||||
|
||||
def test_OPTIONS(self):
|
||||
@ -5544,15 +5548,16 @@ class TestContainerController(unittest.TestCase):
|
||||
controller.PUT, req,
|
||||
200, 201, 201, 201) # HEAD PUT PUT PUT
|
||||
self.assertEqual(seen_headers, [
|
||||
{'X-Account-Host': '10.0.0.0:1000',
|
||||
'X-Account-Partition': '1',
|
||||
'X-Account-Device': 'sda'},
|
||||
{'X-Account-Host': '10.0.0.1:1001',
|
||||
'X-Account-Partition': '1',
|
||||
'X-Account-Device': 'sdb'},
|
||||
{'X-Account-Host': None,
|
||||
'X-Account-Partition': None,
|
||||
'X-Account-Device': None}])
|
||||
{'X-Account-Host': '10.0.0.0:1000',
|
||||
'X-Account-Partition': '1',
|
||||
'X-Account-Device': 'sda'},
|
||||
{'X-Account-Host': '10.0.0.1:1001',
|
||||
'X-Account-Partition': '1',
|
||||
'X-Account-Device': 'sdb'},
|
||||
{'X-Account-Host': None,
|
||||
'X-Account-Partition': None,
|
||||
'X-Account-Device': None}
|
||||
])
|
||||
|
||||
def test_PUT_x_account_headers_with_more_account_replicas(self):
|
||||
self.app.account_ring.set_replicas(4)
|
||||
@ -5563,15 +5568,16 @@ class TestContainerController(unittest.TestCase):
|
||||
controller.PUT, req,
|
||||
200, 201, 201, 201) # HEAD PUT PUT PUT
|
||||
self.assertEqual(seen_headers, [
|
||||
{'X-Account-Host': '10.0.0.0:1000,10.0.0.3:1003',
|
||||
'X-Account-Partition': '1',
|
||||
'X-Account-Device': 'sda,sdd'},
|
||||
{'X-Account-Host': '10.0.0.1:1001',
|
||||
'X-Account-Partition': '1',
|
||||
'X-Account-Device': 'sdb'},
|
||||
{'X-Account-Host': '10.0.0.2:1002',
|
||||
'X-Account-Partition': '1',
|
||||
'X-Account-Device': 'sdc'}])
|
||||
{'X-Account-Host': '10.0.0.0:1000,10.0.0.3:1003',
|
||||
'X-Account-Partition': '1',
|
||||
'X-Account-Device': 'sda,sdd'},
|
||||
{'X-Account-Host': '10.0.0.1:1001',
|
||||
'X-Account-Partition': '1',
|
||||
'X-Account-Device': 'sdb'},
|
||||
{'X-Account-Host': '10.0.0.2:1002',
|
||||
'X-Account-Partition': '1',
|
||||
'X-Account-Device': 'sdc'}
|
||||
])
|
||||
|
||||
def test_DELETE_x_account_headers_with_fewer_account_replicas(self):
|
||||
self.app.account_ring.set_replicas(2)
|
||||
@ -5582,15 +5588,16 @@ class TestContainerController(unittest.TestCase):
|
||||
controller.DELETE, req,
|
||||
200, 204, 204, 204) # HEAD DELETE DELETE DELETE
|
||||
self.assertEqual(seen_headers, [
|
||||
{'X-Account-Host': '10.0.0.0:1000',
|
||||
'X-Account-Partition': '1',
|
||||
'X-Account-Device': 'sda'},
|
||||
{'X-Account-Host': '10.0.0.1:1001',
|
||||
'X-Account-Partition': '1',
|
||||
'X-Account-Device': 'sdb'},
|
||||
{'X-Account-Host': None,
|
||||
'X-Account-Partition': None,
|
||||
'X-Account-Device': None}])
|
||||
{'X-Account-Host': '10.0.0.0:1000',
|
||||
'X-Account-Partition': '1',
|
||||
'X-Account-Device': 'sda'},
|
||||
{'X-Account-Host': '10.0.0.1:1001',
|
||||
'X-Account-Partition': '1',
|
||||
'X-Account-Device': 'sdb'},
|
||||
{'X-Account-Host': None,
|
||||
'X-Account-Partition': None,
|
||||
'X-Account-Device': None}
|
||||
])
|
||||
|
||||
def test_DELETE_x_account_headers_with_more_account_replicas(self):
|
||||
self.app.account_ring.set_replicas(4)
|
||||
@ -5601,15 +5608,16 @@ class TestContainerController(unittest.TestCase):
|
||||
controller.DELETE, req,
|
||||
200, 204, 204, 204) # HEAD DELETE DELETE DELETE
|
||||
self.assertEqual(seen_headers, [
|
||||
{'X-Account-Host': '10.0.0.0:1000,10.0.0.3:1003',
|
||||
'X-Account-Partition': '1',
|
||||
'X-Account-Device': 'sda,sdd'},
|
||||
{'X-Account-Host': '10.0.0.1:1001',
|
||||
'X-Account-Partition': '1',
|
||||
'X-Account-Device': 'sdb'},
|
||||
{'X-Account-Host': '10.0.0.2:1002',
|
||||
'X-Account-Partition': '1',
|
||||
'X-Account-Device': 'sdc'}])
|
||||
{'X-Account-Host': '10.0.0.0:1000,10.0.0.3:1003',
|
||||
'X-Account-Partition': '1',
|
||||
'X-Account-Device': 'sda,sdd'},
|
||||
{'X-Account-Host': '10.0.0.1:1001',
|
||||
'X-Account-Partition': '1',
|
||||
'X-Account-Device': 'sdb'},
|
||||
{'X-Account-Host': '10.0.0.2:1002',
|
||||
'X-Account-Partition': '1',
|
||||
'X-Account-Device': 'sdc'}
|
||||
])
|
||||
|
||||
|
||||
class TestAccountController(unittest.TestCase):
|
||||
@ -5701,7 +5709,6 @@ class TestAccountController(unittest.TestCase):
|
||||
self.app.memcache = FakeMemcacheReturnsNone()
|
||||
self.assert_status_map(controller.GET, (404, 404, 404), 404, 404)
|
||||
|
||||
|
||||
def test_GET_autocreate(self):
|
||||
with save_globals():
|
||||
controller = proxy_server.AccountController(self.app, 'account')
|
||||
@ -5898,7 +5905,7 @@ class TestAccountController(unittest.TestCase):
|
||||
req = Request.blank('/a/c', environ={'REQUEST_METHOD': method},
|
||||
headers={test_header: test_value})
|
||||
self.app.update_request(req)
|
||||
res = getattr(controller, method)(req)
|
||||
getattr(controller, method)(req)
|
||||
self.assertEquals(test_errors, [])
|
||||
|
||||
def test_PUT_bad_metadata(self):
|
||||
|
Loading…
Reference in New Issue
Block a user