Created
October 15, 2021 11:13
-
-
Save RyanKor/aa615bedda5976044a2db5ba62c4cefe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestTaskList(TestTask): | |
_data = task_fakes.FakeTask.create_one_task() | |
columns = ( | |
'ID', 'Type', 'Status', 'Owner' | |
) | |
datalist = ( | |
_data.id, | |
_data.type, | |
_data.status, | |
_data.owner_id | |
) | |
def setUp(self): | |
super(TestTaskList, self).setUp() | |
self.api_mock = mock.Mock() | |
self.api_mock.side_effect = [ | |
[self._data], [], | |
] | |
self.client.tasks = self.api_mock | |
# Get the command object to test | |
self.cmd = image.TaskImage(self.app, None) | |
def test_task_list_no_options(self): | |
arglist = [ | |
] | |
verifylist = [ | |
('sort_key', None), | |
('sort_dir', None), | |
('page_size', None), | |
('type', None), | |
('status', None), | |
] | |
parsed_args = self.check_parser(self.cmd, arglist, verifylist) | |
# In base command class ShowOne in cliff, abstract method take_action() | |
# returns a two-part tuple with a tuple of column names and a tuple of | |
# data to be shown. | |
columns, data = self.cmd.take_action(parsed_args) | |
self.client.tasks.assert_called_with( | |
) | |
self.assertEqual(self.columns, columns) | |
self.assertCountEqual(self.datalist, *data) | |
def test_task_list_sort_key_option(self): | |
arglist = ['--sort-key', 'created_at'] | |
verifylist = [('sort_key', 'created_at')] | |
parsed_args = self.check_parser(self.cmd, arglist, verifylist) | |
# In base command class Lister in cliff, abstract method take_action() | |
# returns a tuple containing the column names and an iterable | |
# containing the data to be listed. | |
columns, data = self.cmd.take_action(parsed_args) | |
self.client.tasks.assert_called_with( | |
sort_key=parsed_args.sort_key | |
) | |
self.assertEqual(self.columns, columns) | |
self.assertCountEqual(self.datalist, *data) | |
def test_task_list_sort_dir_option(self): | |
arglist = ['--sort-dir', 'desc'] | |
verifylist = [('sort_dir', 'desc')] | |
parsed_args = self.check_parser(self.cmd, arglist, verifylist) | |
# In base command class Lister in cliff, abstract method take_action() | |
# returns a tuple containing the column names and an iterable | |
# containing the data to be listed. | |
columns, data = self.cmd.take_action(parsed_args) | |
self.client.tasks.assert_called_with( | |
sort_dir=parsed_args.sort_dir | |
) | |
self.assertEqual(self.columns, columns) | |
self.assertCountEqual(self.datalist, *data) | |
def test_task_list_page_size_option(self): | |
ret_size = 1 | |
arglist = [ | |
'--page-size', str(ret_size), | |
] | |
verifylist = [ | |
('page_size', str(ret_size)), | |
] | |
parsed_args = self.check_parser(self.cmd, arglist, verifylist) | |
columns, data = self.cmd.take_action(parsed_args) | |
self.client.tasks.assert_called_with( | |
page_size=str(ret_size), | |
) | |
self.assertEqual(self.columns, columns) | |
self.assertEqual(ret_size, len(tuple(data))) | |
def test_task_list_type_option(self): | |
arglist = ['--type', self._data.type] | |
verifylist = [('type', self._data.type)] | |
parsed_args = self.check_parser(self.cmd, arglist, verifylist) | |
# In base command class Lister in cliff, abstract method take_action() | |
# returns a tuple containing the column names and an iterable | |
# containing the data to be listed. | |
columns, data = self.cmd.take_action(parsed_args) | |
self.client.tasks.assert_called_with( | |
type=self._data.type, | |
) | |
self.assertEqual(self.columns, columns) | |
self.assertCountEqual(self.datalist, *data) | |
def test_task_list_status_option(self): | |
arglist = ['--status', self._data.status] | |
verifylist = [('status', self._data.status)] | |
parsed_args = self.check_parser(self.cmd, arglist, verifylist) | |
# In base command class Lister in cliff, abstract method take_action() | |
# returns a tuple containing the column names and an iterable | |
# containing the data to be listed. | |
columns, data = self.cmd.take_action(parsed_args) | |
self.client.tasks.assert_called_with( | |
status=self._data.status, | |
) | |
self.assertEqual(self.columns, columns) | |
self.assertCountEqual(self.datalist, *data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment