Example #1
0
 def test_firstchild(self):
     d = {'a': 1, 'b': 2, 'c': datetime.date(1966,1,1)}
     schema = sS(SI('a'),SI('b'),SD('c'))
     w = Wrapper(d, schema)
     out = w.convert('python','json')
     expected = {'a': 1, 'b': 2, 'c': {'month': 1, '__type__': 'date', 'day': 1, 'year': 1966}}
     assert out == expected
Example #2
0
 def test_sublists(self):
     d = {'a': 1, 'b': {'p':12,'q':13}, 'c': [{'x':25,'y': 26},{'x':None,'y': 26}]}
     schema = sS(SI('a'),SS('b',[SI('p'),SI('q')]),SQ('c',sS(SI('x',validator=v.Required()),SI('y'))))
     w = Wrapper(d, schema)
     try:
         w.validate()
     except schemaish.Invalid, e:
         assert e.message=='field "c.1.x" is required'
Example #3
0
 def test_subchildren(self):
     d = {'a': 1, 'b': {'p':12,'q':None}, 'c': {'x':25,'y': 26}}
     schema = sS(SI('a'),SS('b',[SI('p'),SI('q',validator=v.Required())]),SS('c',[SI('x'),SI('y')]))
     w = Wrapper(d, schema)        
     try:
         w.validate()
     except schemaish.Invalid, e:
         assert e.message=='field "b.q" is required'
Example #4
0
 def test_firstchild(self):
     d = {'a': None, 'b': 2, 'c': 3}
     schema = sS(SI('a', validator=v.Required()),SI('b'),SI('c'))
     w = Wrapper(d, schema)
     try:
         w.validate()
     except schemaish.Invalid, e:
         assert e.message=='field "a" is required'
Example #5
0
 def test_sublistnodata(self):
     d = {'a': 1, 'b': {'p':12,'q':13}, 'c': []}
     schema = sS(SI('a'),SS('b',[SI('p'),SI('q')]),SQ('c',sS(SI('x'),SD('y'))))
     w = Wrapper(d, schema)
     wc = w.c
     out = wc.convert('python','json')
     expected = []
     assert out == expected
     out = w.convert('python','json')
     expected = {'a': 1, 'b': {'p': 12, 'q': 13}, 'c': expected}
     assert out == expected
Example #6
0
 def test_subchildren(self):
     d = {'a': 1, 'b': {'p':12,'q':13}, 'c': {'x':25,'y': datetime.date(1966,1,1)}}
     schema = sS(SI('a'),SS('b',[SI('p'),SI('q')]),SS('c',[SI('x'),SD('y')]))
     w = Wrapper(d, schema)        
     wc = w.c
     out = w.c.convert('python','json')
     expected = {'x':25,'y': {'month': 1, '__type__': 'date', 'day': 1, 'year': 1966}}
     assert out == expected
     out = w.convert('python','json')
     expected = {'a': 1, 'b': {'p':12,'q':13}, 'c': expected}
     assert out == expected
Example #7
0
 def test_sublists(self):
     d = {'a': 1, 'b': {'p':12,'q':13}, 'c': [
         {'x':25,'y': datetime.date(1999,12,30)},
         {'x':None,'y': datetime.date(1966,1,1)}]}
     schema = sS(SI('a'),SS('b',[SI('p'),SI('q')]),SQ('c',sS(SI('x'),SD('y'))))
     w = Wrapper(d, schema)
     wc = w.c
     out = wc.convert('python','json')
     expected = [
         {'y': {'month': 12, '__type__': 'date', 'day': 30, 'year': 1999}, 'x': 25}, 
         {'y': {'month': 1, '__type__': 'date', 'day': 1, 'year': 1966}, 'x': None}]
     assert out == expected
     out = w.convert('python','json')
     expected = {'a': 1, 'b': {'p': 12, 'q': 13}, 'c': expected}
     assert out == expected