Merge "Create schema generation for AddressBase"

This commit is contained in:
Jenkins 2016-12-06 13:25:17 +00:00 committed by Gerrit Code Review
commit f61db221f3
2 changed files with 19 additions and 0 deletions

View File

@ -943,6 +943,9 @@ class AddressBase(FieldType):
else:
raise ValueError(_('Value must match %s') % obj.PATTERN)
def get_schema(self):
return {'type': ['string'], 'pattern': self.PATTERN}
class PCIAddress(AddressBase):
PATTERN = '[a-f0-9]{4}:[a-f0-9]{2}:[a-f0-9]{2}.[a-f0-9]'

View File

@ -64,6 +64,14 @@ class FakeEnumAlt(fields.Enum):
**kwargs)
class FakeAddress(fields.AddressBase):
PATTERN = '[a-z]+[0-9]+'
class FakeAddressField(fields.AutoTypedField):
AUTO_TYPE = FakeAddress()
class FakeEnumField(fields.BaseEnumField):
AUTO_TYPE = FakeEnum()
@ -735,3 +743,11 @@ class TestSecureBoot(TestField):
def test_stringify_invalid(self):
self.assertRaises(ValueError, self.field.stringify, 'enabled')
class TestSchemaGeneration(test.NoDBTestCase):
def test_address_base_get_schema(self):
field = FakeAddressField()
expected = {'type': ['string'], 'pattern': '[a-z]+[0-9]+',
'readonly': False}
self.assertEqual(expected, field.get_schema())