示例#1
0
 def test_integer_list_001(self):
     """ test case for integer list sample #1 """
     l = [1,2,3,4,5,6]
     scheme = [int]
     validate(scheme, l)
     l.append('bad_end')
     self.assertRaises(ValidationError, validate, scheme, l)
示例#2
0
 def test_validator(self):
     x = IsoDatetime()
     validate(x, datetime.datetime.now().isoformat())
     self.assertRaises(ValidationError, validate, x, datetime.date.today().isoformat())
     self.assertRaises(ValidationError, validate, x, 7)
     self.assertRaises(ValidationError, validate, x, 'some trash')
     self.assertRaises(ValidationError, validate, x, '2010')
示例#3
0
 def test_integer_list_003(self):
     """ test case for integer list sample #3 """
     l = [10, "foo", 15," bar"]
     scheme = [AnyOf(int, str)]
     validate(scheme, l)
     l.append(True)
     self.assertRaises(ValidationError, validate, scheme, l)
示例#4
0
文件: api.py 项目: sand8080/helixcore
    def _validate(self, call_name, data):
        scheme = self.scheme_dict.get(call_name)
        if scheme is None:
            raise ValidationError('Scheme for %s not found' % call_name)

        try:
            json_validator.validate(scheme, data)
        except json_validator.ValidationError, e:
            raise ValidationError(str(e), fields=e.path)
示例#5
0
 def test_validator(self):
     x = PositiveDecimalText()
     validate(x, '08.0009')
     validate(x, '198.0105')
     self.assertRaises(ValidationError, validate, x, 'e2e4')
     self.assertRaises(ValidationError, validate, x, 7)
     self.assertRaises(ValidationError, validate, x, 'some trash')
     self.assertRaises(ValidationError, validate, x, '-0.0')
     self.assertRaises(ValidationError, validate, x, '0.0')
     self.assertRaises(ValidationError, validate, x, '-10.06')
示例#6
0
 def test_dictionary_001(self):
     """ test case for dictionary #1 """
     d = {'firstName': 'John', 'lastName': 'Smith'}
     scheme = {
         'firstName': str,
         'lastName':  str
         }
     validate(scheme, d)
     d['foo'] = 10
     self.assertRaises(ValidationError, validate, scheme, d)
示例#7
0
 def test_validator(self):
     x = EmailText()
     self.assertRaises(ValidationError, validate, x, 33)
     self.assertRaises(ValidationError, validate, x, 'xzy')
     self.assertRaises(ValidationError, validate, x, 'a-b @m.travel')
     validate(x, '*****@*****.**')
     validate(x, '*****@*****.**')
     validate(x, '*****@*****.**')
示例#8
0
 def test_optional_good_003(self):
     x = {Optional('foo'): int, 'a': 'b'}
     validate(x, {'foo': 10, 'a': 'b'})
示例#9
0
 def test_optional_good_001(self):
     x = {Optional('foo'): 10}
     validate(x, {'foo': 10})
     validate(x, {})
示例#10
0
 def test_callables_004(self):
     d = {'x': "foo"}
     scheme = {'x': lambda x: len(x) > 0}
     validate(scheme, d)
示例#11
0
 def test_good_005(self):
     x = {}
     validate(x, {})
示例#12
0
 def test_optional_bad_002(self):
     x = {Optional('foo'): int}
     validate(x, {})
示例#13
0
 def test_callables_003(self):
     d = {'x': 'boom'}
     scheme = {'x': lambda x: x > 0}
     validate(scheme, d) # NOTE what the hell, seriously!
示例#14
0
 def test_good_002(self):
     x = [int]
     validate(x, [1,2,3,4])
示例#15
0
 def test_good_004(self):
     x = ()
     validate(x, ())
示例#16
0
 def test_good_002(self):
     scheme = {Optional('select'): [str],
               Optional('limit'): int,
               Optional('offset'): int,}
     data = {}
     validate(scheme, data)
示例#17
0
 def test_good_003(self):
     x = {
         'foo': AnyOf(int, str)
         }
     validate(x, {'foo': 10})
     validate(x, {'foo': 'bar'})
示例#18
0
 def test_unicode_001(self):
     x = Text()
     validate(x, unicode('abc'))
示例#19
0
 def test_str_001(self):
     x = Text()
     validate(x, str('abc'))
示例#20
0
 def test_001(self):
     x = {'a': ArbitraryDict()}
     validate(x, {'a': {}})
     validate(x, {'a': {'xx': 'yy'}})
     self.assertRaises(ValidationError, validate, x, {'a': []})
示例#21
0
 def test_nested_dict_001(self):
     x = {'a': 'b', 'c': {'d': 'e'}}
     validate(x, {'a': 'b', 'c': {'d': 'e'}})
示例#22
0
 def test_optional_good_004(self):
     x = {'a': 'b', 'c': 'd', Optional('foo'): 'bar', Optional('zoo'): 'xar'}
     validate(x, {'a': 'b', 'c': 'd', 'zoo': 'xar'})
示例#23
0
 def test_good_001(self):
     x = [object]
     validate(x, [1,2,3,4])
示例#24
0
 def test_good_002(self):
     x = {'foo': int}
     validate(x, {'foo': 10})
示例#25
0
 def test_good_003(self):
     x = []
     validate(x, [])
示例#26
0
 def test_callables_001(self):
     d = {'x': 10}
     scheme = {'x': lambda x: x > 0}
     validate(scheme,  d)
示例#27
0
 def test_good_005(self):
     x = (int, str, bool)
     validate(x, (10, "foo", True))
示例#28
0
 def test_optional_good_002(self):
     x = {Optional('foo'): int}
     validate(x, {'foo': 10})