diff --git a/fuelclient/common/data_utils.py b/fuelclient/common/data_utils.py index 9344dbf..3561025 100644 --- a/fuelclient/common/data_utils.py +++ b/fuelclient/common/data_utils.py @@ -12,6 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. +from fuelclient.cli import error + def get_display_data_single(fields, data): """Performs slicing of data by set of given fields @@ -25,24 +27,11 @@ def get_display_data_single(fields, data): supplied attributes. """ - result = [] - - for field in fields: - if field not in data: - raise KeyError('{f} is not found in the supplied ' - 'data.'.format(f=field)) - - val = data.get(field) - - if not val and val not in (0, None, False, ''): - val = '-' - - if isinstance(val, list): - val = ', '.join(str(item) for item in val) - - result.append(val) - - return result + try: + return [data[field] for field in fields] + except KeyError as e: + raise error.BadDataException('{} is not found in the supplied ' + 'data.'.format(e.args[0])) def get_display_data_multi(fields, data): diff --git a/fuelclient/tests/unit/common/test_utils.py b/fuelclient/tests/unit/common/test_utils.py index e598be5..5262bb0 100644 --- a/fuelclient/tests/unit/common/test_utils.py +++ b/fuelclient/tests/unit/common/test_utils.py @@ -193,31 +193,17 @@ class TestUtils(base.UnitTestCase): error_body.decode('utf-8')) def test_get_display_data_single(self): - test_data = {'a': 1, 'b': 2, 'c': 3} - fields = ('b', 'c') - - result = data_utils.get_display_data_single(fields, test_data) - self.assertEqual([2, 3], result) - - def test_get_display_data_single_empty_val(self): - test_data = {'a': 1, 'b': {}, 'c': []} + test_data = {'a': 1, 'b': [], 'c': [1, 2, 3], 'd': 4} fields = ('a', 'b', 'c') result = data_utils.get_display_data_single(fields, test_data) - self.assertEqual([1, '-', '-'], result) - - def test_get_display_data_single_list_val(self): - test_data = {'a': 1, 'b': ['2'], 'c': ['3', '4']} - fields = ('a', 'b', 'c') - - result = data_utils.get_display_data_single(fields, test_data) - self.assertEqual([1, '2', '3, 4'], result) + self.assertEqual([1, [], [1, 2, 3]], result) def test_get_display_data_bad_key(self): test_data = {'a': 1, 'b': 2, 'c': 3} fields = ('b', 'bad_key') - self.assertRaises(KeyError, + self.assertRaises(error.BadDataException, data_utils.get_display_data_single, fields, test_data)