Merge "Create schema generation for AddressBase"
This commit is contained in:
commit
f61db221f3
@ -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]'
|
||||
|
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user