Convert set() to list in ListType
ListType should return a list instead of set, As set is not json serializable Change-Id: I06011929022c124883a00cdf5784ed63f79f48a5
This commit is contained in:
parent
b80e59148c
commit
cd687bc503
@ -196,12 +196,12 @@ class ListType(wtypes.UserType):
|
|||||||
"""Validate and convert the input to a ListType.
|
"""Validate and convert the input to a ListType.
|
||||||
|
|
||||||
:param value: A comma separated string of values
|
:param value: A comma separated string of values
|
||||||
:returns: A list of values.
|
:returns: A list of unique values, whose order is not guaranteed.
|
||||||
"""
|
"""
|
||||||
items = [v.strip().lower() for v in six.text_type(value).split(',')]
|
items = [v.strip().lower() for v in six.text_type(value).split(',')]
|
||||||
# filter() to remove empty items
|
# filter() to remove empty items
|
||||||
# set() to remove duplicated items
|
# set() to remove duplicated items
|
||||||
return set(filter(None, items))
|
return list(set(filter(None, items)))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def frombasetype(value):
|
def frombasetype(value):
|
||||||
|
@ -277,3 +277,4 @@ class TestListType(base.TestCase):
|
|||||||
v.validate("foo, ,,bar"))
|
v.validate("foo, ,,bar"))
|
||||||
self.assertItemsEqual(['foo', 'bar'],
|
self.assertItemsEqual(['foo', 'bar'],
|
||||||
v.validate("foo,foo,foo,bar"))
|
v.validate("foo,foo,foo,bar"))
|
||||||
|
self.assertIsInstance(v.validate('foo,bar'), list)
|
||||||
|
Loading…
Reference in New Issue
Block a user