diff --git a/almanachclient/commands/list_entities.py b/almanachclient/commands/list_entities.py index 31080a1..45ad0b3 100644 --- a/almanachclient/commands/list_entities.py +++ b/almanachclient/commands/list_entities.py @@ -42,8 +42,10 @@ class ListEntityCommand(Lister): if entity_type == 'instance': properties = dict(flavor=entity.get('flavor'), image=entity.get('image_meta', entity.get('os'))) - else: + elif entity_type == 'volume': properties = dict(volume_type=entity.get('volume_type'), attached_to=entity.get('attached_to')) + else: + properties = None rows.append((entity.get('entity_id'), entity_type, entity.get('name'), entity.get('start'), entity.get('end'), properties)) diff --git a/almanachclient/tests/commands/test_list_entities.py b/almanachclient/tests/commands/test_list_entities.py new file mode 100644 index 0000000..829e919 --- /dev/null +++ b/almanachclient/tests/commands/test_list_entities.py @@ -0,0 +1,49 @@ +# Copyright 2017 INAP +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from argparse import Namespace +import datetime +from unittest import mock + +from almanachclient.commands.list_entities import ListEntityCommand + +from almanachclient.tests import base + + +class TestListEntityCommand(base.TestCase): + + def setUp(self): + super().setUp() + self.app = mock.Mock() + self.app_args = mock.Mock() + self.args = Namespace(tenant_id=None, start=None, end=None) + + self.client = mock.Mock() + self.app.get_client.return_value = self.client + self.command = ListEntityCommand(self.app, self.app_args) + + def test_execute_command(self): + self.args.tenant_id = 'some uuid' + self.args.start = '2017-01-01' + self.args.end = '2017-01-30' + self.client.get_tenant_entities.return_value = [{'entity_id': 'some uuid', 'project_id': 'tenant id'}] + + expected = (('Entity ID', 'Type', 'Name', 'Start', 'End', 'Properties'), + [('some uuid', None, None, None, None, None)]) + + self.assertEqual(expected, self.command.take_action(self.args)) + + self.client.get_tenant_entities.assert_called_once_with(self.args.tenant_id, + datetime.datetime(2017, 1, 1, 0, 0), + datetime.datetime(2017, 1, 30, 0, 0)) diff --git a/doc/source/usage.rst b/doc/source/usage.rst index 52a397d..b9e1704 100644 --- a/doc/source/usage.rst +++ b/doc/source/usage.rst @@ -73,8 +73,8 @@ Usage: :code:`almanach-client update instance --start --en Arguments: -* :code:`instance_id`: Instance ID +* :code:`instance_id`: Instance ID (UUID) * :code:`start`: Start date (ISO8601 format) -* :code:`end`: Start date (ISO8601 format) -* :code:`name`: Start date (ISO8601 format) -* :code:`flavor`: Start date (ISO8601 format) +* :code:`end`: End date (ISO8601 format) +* :code:`name`: Instance name (string) +* :code:`flavor`: Flavor (string)