def test_nested_to_json(self): n = Nested('elem', 'sub1', Bool('my_bool1'), 'sub2', 'sub3', Dict('my_dict1', 'key1', 'key2')) expected_sub1_2 = rand_string() expected_sub2_2 = rand_string() expected_sub3_2 = rand_string() expected_my_bool1_2 = rand_bool() expected_key1_2 = rand_string() expected_key2_2 = rand_string() value2 = {'elem': { 'sub1': expected_sub1_2, 'sub2': expected_sub2_2, 'my_bool1': expected_my_bool1_2, 'sub3': expected_sub3_2, 'my_dict1' : { 'key1': expected_key1_2, 'key2': expected_key2_2, } }} ret_value = n.to_json(value2) eq_(ret_value, {'elem': {'my_bool1': expected_my_bool1_2, 'sub2': expected_sub2_2, 'sub3': expected_sub3_2, 'my_dict1': {'key2': expected_key2_2, 'key1': expected_key1_2}, 'sub1': expected_sub1_2}} )
def _get_sio_msg(): meta = (Int('limit'), 'next', Int('offset'), 'previous', Int('total_count')) location = Nested('location', 'building', Bool('confidential'), 'flat_number', 'level', Dict('point', 'lat', 'non'), 'postcode', 'state', 'street_name', 'street_number', 'street_suffix', 'street_type', 'suburb', 'unit') phones = ListOfDicts('phones', 'comment', Bool('confidential'), 'kind', 'number') postal_address = Dict('postal_address', Bool('confidential'), 'line1', 'line2', 'postcode', 'state', 'suburb') objects = (List('also_known_as'), 'catchment', 'description', ListOfDicts('emails'), Int('id'), Bool('is_mobile'), 'last_updated', location, 'name', Bool('ndis_approved'), Dict('organisation', 'id', 'name'), 'parking_info', phones, postal_address, 'provider_type', 'public_transport_info', 'type', 'web') return [Nested('meta', meta), Nested('objects', objects)]
def test_nested_from_json(self): n = Nested('elem', 'sub1', Bool('my_bool1'), 'sub2', 'sub3', Dict('my_dict1', 'key1', 'key2')) expected_sub1_1 = rand_string() expected_sub2_1 = rand_string() expected_sub3_1 = rand_string() expected_my_bool1_1 = rand_bool() expected_key1_1 = rand_string() expected_key2_1 = rand_string() value1 = {'elem': { 'sub1': expected_sub1_1, 'sub2': expected_sub2_1, 'my_bool1': expected_my_bool1_1, 'sub3': expected_sub3_1, 'my_dict1' : { 'key1': expected_key1_1, 'key2': expected_key2_1, } }} ret_value = n.from_json(value1) eq_(ret_value, {'elem': {'my_bool1': expected_my_bool1_1, 'sub2': expected_sub2_1, 'sub3': expected_sub3_1, 'my_dict1': {'key2': expected_key2_1, 'key1': expected_key1_1}, 'sub1': expected_sub1_1}} )
class SimpleIO: input_required = (AsIs('is_a'), Boolean('b'), Bool('c'), CSV('d'), Dict('e'), Float('f'), Int('g'), Integer('h'), List('i'), ListOfDicts('j'), Nested('k'), Opaque('l'), Unicode('m'), UTC('n')) input_optional = (AsIs('is_aa'), Boolean('bb'), Bool('cc'), CSV('dd'), Dict('ee'), Float('ff'), Int('gg'), Integer('hh'), List('ii'), ListOfDicts('jj'), Nested('kk'), Opaque('ll'), Unicode('mm'), UTC('nn')) output_required = (AsIs('is_aaa'), Boolean('bbb'), Bool('ccc'), CSV('ddd'), Dict('eee'), Float('fff'), Int('ggg'), Integer('hhh'), List('iii'), ListOfDicts('jjj'), Nested('kkk'), Opaque('lll'), Unicode('mmm'), UTC('nnn')) output_optional = (AsIs('is_aaaa'), Boolean('bbbb'), Bool('cccc'), CSV('dddd'), Dict('eeee'), Float('ffff'), Int('gggg'), Integer('hhhh'), List('iiii'), ListOfDicts('jjjj'), Nested('kkkk'), Opaque('llll'), Unicode('mmmm'), UTC('nnnn'))