Esempio n. 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)
Esempio n. 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')
Esempio n. 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)
Esempio n. 4
0
    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)
Esempio n. 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')
Esempio n. 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)
Esempio n. 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, '*****@*****.**')
Esempio n. 8
0
 def test_optional_good_003(self):
     x = {Optional('foo'): int, 'a': 'b'}
     validate(x, {'foo': 10, 'a': 'b'})
Esempio n. 9
0
 def test_optional_good_001(self):
     x = {Optional('foo'): 10}
     validate(x, {'foo': 10})
     validate(x, {})
Esempio n. 10
0
 def test_callables_004(self):
     d = {'x': "foo"}
     scheme = {'x': lambda x: len(x) > 0}
     validate(scheme, d)
Esempio n. 11
0
 def test_good_005(self):
     x = {}
     validate(x, {})
Esempio n. 12
0
 def test_optional_bad_002(self):
     x = {Optional('foo'): int}
     validate(x, {})
Esempio n. 13
0
 def test_callables_003(self):
     d = {'x': 'boom'}
     scheme = {'x': lambda x: x > 0}
     validate(scheme, d) # NOTE what the hell, seriously!
Esempio n. 14
0
 def test_good_002(self):
     x = [int]
     validate(x, [1,2,3,4])
Esempio n. 15
0
 def test_good_004(self):
     x = ()
     validate(x, ())
Esempio n. 16
0
 def test_good_002(self):
     scheme = {Optional('select'): [str],
               Optional('limit'): int,
               Optional('offset'): int,}
     data = {}
     validate(scheme, data)
Esempio n. 17
0
 def test_good_003(self):
     x = {
         'foo': AnyOf(int, str)
         }
     validate(x, {'foo': 10})
     validate(x, {'foo': 'bar'})
Esempio n. 18
0
 def test_unicode_001(self):
     x = Text()
     validate(x, unicode('abc'))
Esempio n. 19
0
 def test_str_001(self):
     x = Text()
     validate(x, str('abc'))
Esempio n. 20
0
 def test_001(self):
     x = {'a': ArbitraryDict()}
     validate(x, {'a': {}})
     validate(x, {'a': {'xx': 'yy'}})
     self.assertRaises(ValidationError, validate, x, {'a': []})
Esempio n. 21
0
 def test_nested_dict_001(self):
     x = {'a': 'b', 'c': {'d': 'e'}}
     validate(x, {'a': 'b', 'c': {'d': 'e'}})
Esempio n. 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'})
Esempio n. 23
0
 def test_good_001(self):
     x = [object]
     validate(x, [1,2,3,4])
Esempio n. 24
0
 def test_good_002(self):
     x = {'foo': int}
     validate(x, {'foo': 10})
Esempio n. 25
0
 def test_good_003(self):
     x = []
     validate(x, [])
Esempio n. 26
0
 def test_callables_001(self):
     d = {'x': 10}
     scheme = {'x': lambda x: x > 0}
     validate(scheme,  d)
Esempio n. 27
0
 def test_good_005(self):
     x = (int, str, bool)
     validate(x, (10, "foo", True))
Esempio n. 28
0
 def test_optional_good_002(self):
     x = {Optional('foo'): int}
     validate(x, {'foo': 10})