Add unit tests for swift.proxy.controllers.base

This patch adds more unit tests to diminish missing pieces
of the coverage in the proxy_controllers_base unit test.

Change-Id: I85ba1955c681cc9d5b2a70ac31155678d2e5b6fd
This commit is contained in:
Bill Huber 2015-10-22 10:14:29 -05:00
parent e283718ed0
commit faef717cd3
2 changed files with 46 additions and 1 deletions

View File

@ -1287,7 +1287,7 @@ class Controller(object):
def generate_request_headers(self, orig_req=None, additional=None, def generate_request_headers(self, orig_req=None, additional=None,
transfer=False): transfer=False):
""" """
Create a list of headers to be used in backend requets Create a list of headers to be used in backend requests
:param orig_req: the original request sent by the client to the proxy :param orig_req: the original request sent by the client to the proxy
:param additional: additional headers to send to the backend :param additional: additional headers to send to the backend

View File

@ -452,6 +452,28 @@ class TestFuncs(unittest.TestCase):
resp = base.OPTIONS(req) resp = base.OPTIONS(req)
self.assertEqual(resp.status_int, 200) self.assertEqual(resp.status_int, 200)
def test_options_with_null_allow_origin(self):
base = Controller(self.app)
base.account_name = 'a'
base.container_name = 'c'
def my_container_info(*args):
return {
'cors': {
'allow_origin': '*',
}
}
base.container_info = my_container_info
req = Request.blank('/v1/a/c/o',
environ={'swift.cache': FakeCache()},
headers={'Origin': '*',
'Access-Control-Request-Method': 'GET'})
with patch('swift.proxy.controllers.base.'
'http_connect', fake_http_connect(200)):
resp = base.OPTIONS(req)
self.assertEqual(resp.status_int, 200)
def test_options_unauthorized(self): def test_options_unauthorized(self):
base = Controller(self.app) base = Controller(self.app)
base.account_name = 'a' base.account_name = 'a'
@ -507,6 +529,16 @@ class TestFuncs(unittest.TestCase):
resp, resp,
headers_to_container_info(headers.items(), 200)) headers_to_container_info(headers.items(), 200))
def test_container_info_without_req(self):
base = Controller(self.app)
base.account_name = 'a'
base.container_name = 'c'
container_info = \
base.container_info(base.account_name,
base.container_name)
self.assertEqual(container_info['status'], 0)
def test_headers_to_account_info_missing(self): def test_headers_to_account_info_missing(self):
resp = headers_to_account_info({}, 404) resp = headers_to_account_info({}, 404)
self.assertEqual(resp['status'], 404) self.assertEqual(resp['status'], 404)
@ -684,6 +716,19 @@ class TestFuncs(unittest.TestCase):
for k, v in bad_hdrs.items(): for k, v in bad_hdrs.items():
self.assertFalse(k.lower() in dst_headers) self.assertFalse(k.lower() in dst_headers)
def test_generate_request_headers_with_no_orig_req(self):
base = Controller(self.app)
src_headers = {'x-remove-base-meta-owner': 'x',
'x-base-meta-size': '151M',
'new-owner': 'Kun'}
dst_headers = base.generate_request_headers(None,
additional=src_headers)
expected_headers = {'x-base-meta-size': '151M',
'connection': 'close'}
for k, v in expected_headers.items():
self.assertDictContainsSubset(expected_headers, dst_headers)
self.assertEqual('', dst_headers['Referer'])
def test_client_chunk_size(self): def test_client_chunk_size(self):
class TestSource(object): class TestSource(object):