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