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