Merge "Add DictOfListOfStrings type of field"

This commit is contained in:
Jenkins 2015-07-30 11:16:13 +00:00 committed by Gerrit Code Review
commit 3fa3ea7def
2 changed files with 21 additions and 0 deletions

View File

@ -690,6 +690,11 @@ class ListOfIntegersField(AutoTypedField):
AUTO_TYPE = List(fields.Integer())
# FIXME(sbauza): Remove this after oslo.versionedobjects releases it
class DictOfListOfStringsField(AutoTypedField):
AUTO_TYPE = Dict(List(fields.String()))
# FIXME(danms): Remove this after we convert to oslo.versionedobjects' registry
class ObjectField(AutoTypedField):
def __init__(self, objtype, **kwargs):

View File

@ -802,6 +802,22 @@ class TestListOfSetsOfIntegers(TestField):
self.assertEqual('[set([1,2])]', self.field.stringify([set([1, 2])]))
class TestDictOfListOfStrings(TestField):
def setUp(self):
super(TestDictOfListOfStrings, self).setUp()
self.field = fields.DictOfListOfStringsField()
self.coerce_good_values = [({'foo': ['1', '2']}, {'foo': ['1', '2']}),
({'foo': [1]}, {'foo': ['1']})]
self.coerce_bad_values = [{'foo': [None, None]}, 'foo']
self.to_primitive_values = [({'foo': ['1', '2']}, {'foo': ['1', '2']})]
self.from_primitive_values = [({'foo': ['1', '2']},
{'foo': ['1', '2']})]
def test_stringify(self):
self.assertEqual("{foo=['1','2']}",
self.field.stringify({'foo': ['1', '2']}))
class TestObject(TestField):
def setUp(self):
super(TestObject, self).setUp()