Merge "Fix limit handling to not send value of -1"

This commit is contained in:
Zuul 2017-12-13 09:07:10 +00:00 committed by Gerrit Code Review
commit 02985bb30e
10 changed files with 67 additions and 5 deletions

View File

@ -76,7 +76,7 @@ class ActionExecutionManager(base.ResourceManager):
qparams = {}
if limit:
if limit and limit > 0:
qparams['limit'] = limit
query_string = ("?%s" % urlparse.urlencode(list(qparams.items()))

View File

@ -74,7 +74,7 @@ class ActionManager(base.ResourceManager):
if marker:
qparams['marker'] = marker
if limit:
if limit and limit > 0:
qparams['limit'] = limit
if sort_keys:

View File

@ -82,7 +82,7 @@ class ExecutionManager(base.ResourceManager):
if marker:
qparams['marker'] = marker
if limit:
if limit and limit > 0:
qparams['limit'] = limit
if sort_keys:

View File

@ -42,7 +42,7 @@ class TaskManager(base.ResourceManager):
if marker:
qparams['marker'] = marker
if limit:
if limit and limit > 0:
qparams['limit'] = limit
if sort_keys:

View File

@ -82,7 +82,7 @@ class WorkflowManager(base.ResourceManager):
if marker:
qparams['marker'] = marker
if limit:
if limit and limit > 0:
qparams['limit'] = limit
if sort_keys:

View File

@ -108,6 +108,20 @@ class TestActionExecutions(base.BaseClientV2Test):
# Make sure that limit is passed to the server correctly.
self.assertEqual(['1'], last_request.qs['limit'])
def test_list_with_no_limit(self):
self.requests_mock.get(
self.TEST_URL + URL_TEMPLATE,
json={'action_executions': [ACTION_EXEC]}
)
action_execution_list = self.action_executions.list(limit=-1)
self.assertEqual(1, len(action_execution_list))
last_request = self.requests_mock.last_request
self.assertNotIn('limit', last_request.qs)
def test_get(self):
url = self.TEST_URL + URL_TEMPLATE_ID % ACTION_EXEC['id']
self.requests_mock.get(url, json=ACTION_EXEC)

View File

@ -182,6 +182,18 @@ class TestActionsV2(base.BaseClientV2Test):
self.assertEqual(['created_at'], last_request.qs['sort_keys'])
self.assertEqual(['asc'], last_request.qs['sort_dirs'])
def test_list_with_no_limit(self):
self.requests_mock.get(self.TEST_URL + URL_TEMPLATE,
json={'actions': [ACTION]})
action_list = self.actions.list(limit=-1)
self.assertEqual(1, len(action_list))
last_request = self.requests_mock.last_request
self.assertNotIn('limit', last_request.qs)
def test_get(self):
self.requests_mock.get(self.TEST_URL + URL_TEMPLATE_NAME % 'action',
json=ACTION)

View File

@ -195,6 +195,18 @@ class TestExecutionsV2(base.BaseClientV2Test):
self.assertEqual(['created_at'], last_request.qs['sort_keys'])
self.assertEqual(['asc'], last_request.qs['sort_dirs'])
def test_list_with_no_limit(self):
self.requests_mock.get(self.TEST_URL + URL_TEMPLATE,
json={'executions': [EXEC]})
execution_list = self.executions.list(limit=-1)
self.assertEqual(1, len(execution_list))
last_request = self.requests_mock.last_request
self.assertNotIn('limit', last_request.qs)
def test_get(self):
url = self.TEST_URL + URL_TEMPLATE_ID % EXEC['id']
self.requests_mock.get(url, json=EXEC)

View File

@ -59,6 +59,18 @@ class TestTasksV2(base.BaseClientV2Test):
self.tasks.list(fields=["id,name"])
self.assertTrue(self.requests_mock.called_once)
def test_list_with_no_limit(self):
self.requests_mock.get(self.TEST_URL + URL_TEMPLATE,
json={'tasks': [TASK]})
task_list = self.tasks.list(limit=-1)
self.assertEqual(1, len(task_list))
last_request = self.requests_mock.last_request
self.assertNotIn('limit', last_request.qs)
def test_get(self):
url = self.TEST_URL + URL_TEMPLATE_ID % TASK['id']
self.requests_mock.get(url, json=TASK)

View File

@ -168,6 +168,18 @@ class TestWorkflowsV2(base.BaseClientV2Test):
self.assertEqual(['created_at'], last_request.qs['sort_keys'])
self.assertEqual(['asc'], last_request.qs['sort_dirs'])
def test_list_with_no_limit(self):
self.requests_mock.get(self.TEST_URL + URL_TEMPLATE,
json={'workflows': [WORKFLOW]})
workflows_list = self.workflows.list(limit=-1)
self.assertEqual(1, len(workflows_list))
last_request = self.requests_mock.last_request
self.assertNotIn('limit', last_request.qs)
def test_get(self):
url = self.TEST_URL + URL_TEMPLATE_NAME % 'wf'
self.requests_mock.get(url, json=WORKFLOW)