Exemple #1
0
 def test_schema_map_schema(self):
     d = {
         'type': 'map',
         'description': 'A map',
         'schema': {
             'Foo': {
                 'type': 'string',
                 'description': 'A string',
                 'default': 'wibble',
                 'required': True,
                 'constraints': [
                     {
                         'length': {
                             'min': 4,
                             'max': 8
                         }
                     },
                 ]
             }
         },
         'required': False,
     }
     s = properties.Schema(properties.STRING,
                           'A string',
                           default='wibble',
                           required=True,
                           constraints=[properties.Length(4, 8)])
     m = properties.Schema(properties.MAP, 'A map', schema={'Foo': s})
     self.assertEqual(d, dict(m))
Exemple #2
0
 def test_schema_list_schema(self):
     d = {
         'type': 'list',
         'description': 'A list',
         'schema': {
             '*': {
                 'type': 'string',
                 'description': 'A string',
                 'default': 'wibble',
                 'required': True,
                 'constraints': [
                     {
                         'length': {
                             'min': 4,
                             'max': 8
                         }
                     },
                 ]
             }
         },
         'required': False,
     }
     s = properties.Schema(properties.STRING,
                           'A string',
                           default='wibble',
                           required=True,
                           constraints=[properties.Length(4, 8)])
     l = properties.Schema(properties.LIST, 'A list', schema=s)
     self.assertEqual(d, dict(l))
Exemple #3
0
 def test_schema_all(self):
     d = {
         'type': 'string',
         'description': 'A string',
         'default': 'wibble',
         'required': True,
         'constraints': [
             {
                 'length': {
                     'min': 4,
                     'max': 8
                 }
             },
         ]
     }
     s = properties.Schema(properties.STRING,
                           'A string',
                           default='wibble',
                           required=True,
                           constraints=[properties.Length(4, 8)])
     self.assertEqual(d, dict(s))
Exemple #4
0
 def test_length_max_fail(self):
     l = properties.Length(max=5, description='a range')
     self.assertRaises(ValueError, l.validate, 'abcdef')
Exemple #5
0
 def test_length_validate(self):
     l = properties.Length(min=5, max=5, description='a range')
     l.validate('abcde')
Exemple #6
0
 def test_length_max_schema(self):
     d = {'length': {'max': 10}, 'description': 'a length range'}
     r = properties.Length(max=10, description='a length range')
     self.assertEqual(d, dict(r))
Exemple #7
0
 def test_length_min_schema(self):
     d = {'length': {'min': 5}, 'description': 'a length range'}
     r = properties.Length(min=5, description='a length range')
     self.assertEqual(d, dict(r))
Exemple #8
0
 def test_length_invalid_type(self):
     self.assertRaises(properties.InvalidPropertySchemaError,
                       properties.Schema,
                       'Integer',
                       constraints=[properties.Length(1, 10)])