Check marker params in SimpleClient full listing requests
Follow up for change [1] to add some assertions to check that marker param is included in sequential GET requests sent during a full listing. Extract multiple FakeConn class definitions to single class at module level and share between all classes. Also, explicitly unpack the return values from base request calls made in the full listing section of base_request, and explicitly return a list to make more consistent with rest of the method. [1] Change-Id: I6892390d72f70f1bc519b482d4f72603e1570163 Change-Id: Iad038709f46364b8324d25ac79be4317add79df5
This commit is contained in:
parent
a696c1e89e
commit
2f24fb9683
@ -747,18 +747,18 @@ class SimpleClient(object):
|
|||||||
url = self.url
|
url = self.url
|
||||||
|
|
||||||
if full_listing:
|
if full_listing:
|
||||||
body_data = self.base_request(method, container, name, prefix,
|
info, body_data = self.base_request(
|
||||||
headers, proxy, timeout=timeout,
|
method, container, name, prefix, headers, proxy,
|
||||||
marker=marker)
|
timeout=timeout, marker=marker)
|
||||||
listing = body_data[1]
|
listing = body_data
|
||||||
while listing:
|
while listing:
|
||||||
marker = listing[-1]['name']
|
marker = listing[-1]['name']
|
||||||
listing = self.base_request(method, container, name, prefix,
|
info, listing = self.base_request(
|
||||||
headers, proxy, timeout=timeout,
|
method, container, name, prefix, headers, proxy,
|
||||||
marker=marker)[1]
|
timeout=timeout, marker=marker)
|
||||||
if listing:
|
if listing:
|
||||||
body_data[1].extend(listing)
|
body_data.extend(listing)
|
||||||
return body_data
|
return [info, body_data]
|
||||||
|
|
||||||
if headers is None:
|
if headers is None:
|
||||||
headers = {}
|
headers = {}
|
||||||
|
@ -34,6 +34,19 @@ from test.unit import with_tempdir, write_fake_ring, patch_policies
|
|||||||
from test.unit.common.middleware.helpers import FakeSwift
|
from test.unit.common.middleware.helpers import FakeSwift
|
||||||
|
|
||||||
|
|
||||||
|
class FakeConn(object):
|
||||||
|
def __init__(self, body=None):
|
||||||
|
if body is None:
|
||||||
|
body = []
|
||||||
|
self.body = body
|
||||||
|
|
||||||
|
def read(self):
|
||||||
|
return json.dumps(self.body)
|
||||||
|
|
||||||
|
def info(self):
|
||||||
|
return {}
|
||||||
|
|
||||||
|
|
||||||
def not_sleep(seconds):
|
def not_sleep(seconds):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -339,17 +352,10 @@ class TestInternalClient(unittest.TestCase):
|
|||||||
# verify that base_request passes timeout arg on to urlopen
|
# verify that base_request passes timeout arg on to urlopen
|
||||||
body = {"some": "content"}
|
body = {"some": "content"}
|
||||||
|
|
||||||
class FakeConn(object):
|
|
||||||
def read(self):
|
|
||||||
return json.dumps(body)
|
|
||||||
|
|
||||||
def info(self):
|
|
||||||
return {}
|
|
||||||
|
|
||||||
for timeout in (0.0, 42.0, None):
|
for timeout in (0.0, 42.0, None):
|
||||||
mocked_func = 'swift.common.internal_client.urllib2.urlopen'
|
mocked_func = 'swift.common.internal_client.urllib2.urlopen'
|
||||||
with mock.patch(mocked_func) as mock_urlopen:
|
with mock.patch(mocked_func) as mock_urlopen:
|
||||||
mock_urlopen.side_effect = [FakeConn()]
|
mock_urlopen.side_effect = [FakeConn(body)]
|
||||||
sc = internal_client.SimpleClient('http://0.0.0.0/')
|
sc = internal_client.SimpleClient('http://0.0.0.0/')
|
||||||
_, resp_body = sc.base_request('GET', timeout=timeout)
|
_, resp_body = sc.base_request('GET', timeout=timeout)
|
||||||
mock_urlopen.assert_called_once_with(mock.ANY, timeout=timeout)
|
mock_urlopen.assert_called_once_with(mock.ANY, timeout=timeout)
|
||||||
@ -361,23 +367,21 @@ class TestInternalClient(unittest.TestCase):
|
|||||||
body2 = [{'name': 'd'}]
|
body2 = [{'name': 'd'}]
|
||||||
body3 = []
|
body3 = []
|
||||||
|
|
||||||
class FakeConn(object):
|
|
||||||
def __init__(self, body):
|
|
||||||
self.body = body
|
|
||||||
|
|
||||||
def read(self):
|
|
||||||
return json.dumps(self.body)
|
|
||||||
|
|
||||||
def info(self):
|
|
||||||
return {}
|
|
||||||
|
|
||||||
mocked_func = 'swift.common.internal_client.urllib2.urlopen'
|
mocked_func = 'swift.common.internal_client.urllib2.urlopen'
|
||||||
with mock.patch(mocked_func) as mock_urlopen:
|
with mock.patch(mocked_func) as mock_urlopen:
|
||||||
mock_urlopen.side_effect = [
|
mock_urlopen.side_effect = [
|
||||||
FakeConn(body1), FakeConn(body2), FakeConn(body3)]
|
FakeConn(body1), FakeConn(body2), FakeConn(body3)]
|
||||||
sc = internal_client.SimpleClient('http://0.0.0.0/')
|
sc = internal_client.SimpleClient('http://0.0.0.0/')
|
||||||
_, resp_body = sc.base_request('GET', full_listing=True)
|
_, resp_body = sc.base_request('GET', full_listing=True)
|
||||||
self.assertEqual(body1 + body2, resp_body)
|
self.assertEqual(body1 + body2, resp_body)
|
||||||
|
self.assertEqual(3, mock_urlopen.call_count)
|
||||||
|
actual_requests = map(
|
||||||
|
lambda call: call[0][0], mock_urlopen.call_args_list)
|
||||||
|
self.assertEqual('/?format=json', actual_requests[0].get_selector())
|
||||||
|
self.assertEqual(
|
||||||
|
'/?format=json&marker=c', actual_requests[1].get_selector())
|
||||||
|
self.assertEqual(
|
||||||
|
'/?format=json&marker=d', actual_requests[2].get_selector())
|
||||||
|
|
||||||
def test_make_request_method_path_headers(self):
|
def test_make_request_method_path_headers(self):
|
||||||
class InternalClient(internal_client.InternalClient):
|
class InternalClient(internal_client.InternalClient):
|
||||||
@ -1415,14 +1419,6 @@ class TestSimpleClient(unittest.TestCase):
|
|||||||
proxy = '%s://%s' % (scheme, proxy_host)
|
proxy = '%s://%s' % (scheme, proxy_host)
|
||||||
url = 'https://127.0.0.1:1/a'
|
url = 'https://127.0.0.1:1/a'
|
||||||
|
|
||||||
class FakeConn(object):
|
|
||||||
|
|
||||||
def read(self):
|
|
||||||
return 'irrelevant'
|
|
||||||
|
|
||||||
def info(self):
|
|
||||||
return {}
|
|
||||||
|
|
||||||
mocked = 'swift.common.internal_client.urllib2.urlopen'
|
mocked = 'swift.common.internal_client.urllib2.urlopen'
|
||||||
|
|
||||||
# module level methods
|
# module level methods
|
||||||
|
Loading…
Reference in New Issue
Block a user