Remove hacks for displaying lists in tables

get_display_data_single() should not do any transformation of
a supplied data in order to let Cliff's serializers to do that
in a way a user choses.

Change-Id: Ifb98fce21b6363296c87f67d05ee301943fa72b4
Closes-bug: #1548764
This commit is contained in:
Roman Prykhodchenko
2016-02-23 12:18:41 +01:00
parent d19891a121
commit 9d306e833e
2 changed files with 10 additions and 35 deletions

View File

@@ -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):

View File

@@ -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)