diff --git a/rally/cmd/commands/deployment.py b/rally/cmd/commands/deployment.py index 48d565cfac..571f52fd21 100644 --- a/rally/cmd/commands/deployment.py +++ b/rally/cmd/commands/deployment.py @@ -126,7 +126,9 @@ class DeploymentCommands(object): r = [str(t[column]) for column in headers[:-1]] r.append("" if t["uuid"] != current_deploy_id else "*") table_rows.append(utils.Struct(**dict(zip(headers, r)))) - common_cliutils.print_list(table_rows, headers) + common_cliutils.print_list(table_rows, headers, + sortby_index=headers.index( + 'created_at')) else: print(_("There are no deployments. " "To create a new deployment, use:" diff --git a/rally/cmd/commands/task.py b/rally/cmd/commands/task.py index 1a04199c61..ef8bac2f13 100644 --- a/rally/cmd/commands/task.py +++ b/rally/cmd/commands/task.py @@ -313,7 +313,9 @@ class TaskCommands(object): headers = ['uuid', 'created_at', 'status', 'failed', 'tag'] task_list = task_list or db.task_list() if task_list: - common_cliutils.print_list(task_list, headers) + common_cliutils.print_list(task_list, headers, + sortby_index=headers.index( + 'created_at')) else: print(_("There are no tasks. To run a new task, use:" "\nrally task start")) diff --git a/rally/cmd/commands/verify.py b/rally/cmd/commands/verify.py index db85e201a4..673fdb818c 100644 --- a/rally/cmd/commands/verify.py +++ b/rally/cmd/commands/verify.py @@ -119,7 +119,9 @@ class VerifyCommands(object): print ("Total results of verification:\n") total_fields = ['UUID', 'Deployment UUID', 'Set name', 'Tests', 'Failures', 'Created at', 'Status'] - common_cliutils.print_list([verification], fields=total_fields) + common_cliutils.print_list([verification], fields=total_fields, + sortby_index=total_fields.index( + 'Created at')) print ("\nTests:\n") fields = ['name', 'time', 'status'] diff --git a/tests/cmd/commands/test_deployment.py b/tests/cmd/commands/test_deployment.py index eaf7da1a93..a17dc4a8d5 100644 --- a/tests/cmd/commands/test_deployment.py +++ b/tests/cmd/commands/test_deployment.py @@ -123,7 +123,9 @@ class DeploymentCommandsTestCase(test.TestCase): mock_struct.assert_called_once_with(**fake_deployment) headers = ['uuid', 'created_at', 'name', 'status', 'active'] - mock_print_list.assert_called_once_with([mock_struct()], headers) + mock_print_list.assert_called_once_with([mock_struct()], headers, + sortby_index=headers.index( + 'created_at')) @mock.patch('rally.cmd.commands.deployment.common_cliutils.print_list') @mock.patch('rally.cmd.commands.deployment.utils.Struct') @@ -147,7 +149,9 @@ class DeploymentCommandsTestCase(test.TestCase): mock_struct.assert_called_once_with(**fake_deployment) headers = ['uuid', 'created_at', 'name', 'status', 'active'] - mock_print_list.assert_called_once_with([mock_struct()], headers) + mock_print_list.assert_called_once_with([mock_struct()], headers, + sortby_index=headers.index( + 'created_at')) @mock.patch('rally.cmd.commands.deployment.db.deployment_get') def test_config(self, mock_deployment): diff --git a/tests/cmd/commands/test_task.py b/tests/cmd/commands/test_task.py index f56973e292..c0b7cfabfd 100644 --- a/tests/cmd/commands/test_task.py +++ b/tests/cmd/commands/test_task.py @@ -144,7 +144,9 @@ class TaskCommandsTestCase(test.TestCase): mock_db.task_list.assert_called_once_with() headers = ['uuid', 'created_at', 'status', 'failed', 'tag'] - mock_print_list.assert_called_once_with(db_response, headers) + mock_print_list.assert_called_once_with(db_response, headers, + sortby_index=headers.index( + 'created_at')) def test_delete(self): task_uuid = str(uuid.uuid4()) diff --git a/tests/cmd/commands/test_verify.py b/tests/cmd/commands/test_verify.py index d31ef0f587..4c480f6d7c 100644 --- a/tests/cmd/commands/test_verify.py +++ b/tests/cmd/commands/test_verify.py @@ -16,9 +16,11 @@ import uuid import mock +import six from rally.cmd.commands import verify from rally import consts +from rally import objects from tests import test @@ -71,3 +73,51 @@ class VerifyCommandsTestCase(test.TestCase): self.assertNotIn(wrong_set_name, consts.TEMPEST_TEST_SETS) self.assertFalse(mock_verify.called) + + @mock.patch('rally.openstack.common.cliutils.print_list') + @mock.patch('rally.db.verification_list') + def test_list(self, mock_db_verification_list, mock_print_list): + fields = ['UUID', 'Deployment UUID', 'Set name', 'Tests', 'Failures', + 'Created at', 'Status'] + verifications = {'dummy': []} + mock_db_verification_list.return_value = verifications + self.verify.list() + mock_db_verification_list.assert_called_once() + mock_print_list.assert_called_once_with(verifications, fields, + sortby_index=fields.index( + 'Created at')) + + @mock.patch('rally.openstack.common.cliutils.print_list') + @mock.patch('rally.db.verification_get') + @mock.patch('rally.db.verification_result_get') + @mock.patch('rally.objects.Verification') + def test_show(self, mock_obj_verification, + mock_verification_result_get, mock_verification_get, + mock_print_list): + + class Test_dummy(): + data = {'test_cases': {'test_a': {'name': 'test_a', 'time': 20, + 'status': 'PASS'}, + 'test_b': {'name': 'test_b', 'time': 20, + 'status': 'SKIP'}, + 'test_c': {'name': 'test_c', 'time': 20, + 'status': 'FAIL'}}} + + verification_id = '39121186-b9a4-421d-b094-6c6b270cf9e9' + total_fields = ['UUID', 'Deployment UUID', 'Set name', 'Tests', + 'Failures', 'Created at', 'Status'] + fields = ['name', 'time', 'status'] + verification = mock.MagicMock() + tests = Test_dummy() + mock_verification_result_get.return_value = tests + mock_verification_get.return_value = verification + mock_obj_verification.return_value = 1 + values = map(objects.Verification, + six.itervalues(tests.data['test_cases'])) + self.verify.show(verification_id) + mock_print_list.assert_any_call( + [verification], fields=total_fields, + sortby_index=total_fields.index('Created at')) + mock_verification_get.assert_called_once_with(verification_id) + mock_verification_result_get.assert_called_once_with(verification_id) + mock_print_list.assert_any_call(values, fields, sortby_index=0)