Exemplo n.º 1
0
 class SimpleIO:
     input_required = (Integer('id'))
     input_optional = (Integer('id_guest'), Integer('id_room'),
                       Integer('guests'), Date('check_in'),
                       Date('check_out'), DateTime('checked_in'),
                       DateTime('checked_out'), DateTime('cancelled'),
                       Float('base_price'), Float('taxes_percentage'),
                       Float('taxes_value'), Float('total_price'), 'status',
                       'meal_plan', Dict('extras'))
     output_optional = (
         'id',
         'id_guest',
         'id_room',
         DateTime('reserved'),
         'guests',
         Date('check_in'),
         Date('check_out'),
         DateTime('checked_in'),
         DateTime('checked_out'),
         DateTime('cancelled'),
         'base_price',
         'taxes_percentage',
         'taxes_value',
         'total_price',
         'locator',
         'pin',
         'status',
         'meal_plan',
         Dict('extras'),
         # 'uuid' # JSON serializaction error
         # https://forum.zato.io/t/returning-uuid-types-from-services-using-json/1735
         'nights')
     skip_empty_keys = True
Exemplo n.º 2
0
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)]
Exemplo n.º 3
0
 class SimpleIO(object):
     input_required = (Integer('guests'), Date('check_in'),
                       Date('check_out'), Integer('id_room'), 'uuid',
                       'name', 'surname', 'email')
     input_optional = ('status', 'meal_plan', List('extras', default=[]),
                       'gender', 'passport', Date('birthdate'), 'address1',
                       'address2', 'locality', 'postcode', 'province',
                       'country', 'home_phone', 'mobile_phone')
     output_optional = (
         Dict(
             'booking',
             # 'id', 'id_guest', 'id_room', DateTime('reserved'),
             # 'guests', Date('check_in'), Date('check_out'),
             # DateTime('checked_in'), DateTime('checked_out'),
             # DateTime('cancelled'), 'base_price', 'taxes_percentage',
             # 'taxes_value', 'total_price', 'locator', 'pin', 'status',
             # 'meal_plan', Dict('extras'),
             # 'uuid' # JSON serializaction error
             # https://forum.zato.io/t/returning-uuid-types-from-services-using-json/1735
             # 'nights'
         ),
         Dict(
             'guest',
             # 'id',  'name', 'surname', 'gender', 'email', 'passport',
             # Date('birthdate'), 'address1', 'address2', 'locality',
             # 'postcode', 'province', 'country', 'home_phone',
             # 'mobile_phone'
         ),
         Dict(
             'room',
             # 'id', 'floor_no', 'room_no', 'sgl_beds', 'dbl_beds',
             # 'supplement', 'code', 'name', 'accommodates', 'number'
         ),
         Dict('error'))
     skip_empty_keys = True
Exemplo n.º 4
0
    class SimpleIO:
        input_required = (AsIs('should_as_is'), 'is_boolean', 'should_boolean',
                          CSV('csv1'), Dict('dict'), Float('float'),
                          Integer('integer'), Integer('integer2'),
                          List('list'), ListOfDicts('list_of_dicts'),
                          Unicode('unicode1'), Unicode('unicode2'), UTC('utc'))

        output_required = (AsIs('should_as_is'),
                           'is_boolean', 'should_boolean', CSV('csv1'),
                           CSV('csv2'), CSV('csv3'), Dict('dict'),
                           Float('float'), Integer('integer'),
                           Integer('integer2'), List('list'),
                           ListOfDicts('list_of_dicts'), Unicode('unicode1'),
                           Unicode('unicode2'), UTC('utc'))
Exemplo n.º 5
0
    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}}
        )
Exemplo n.º 6
0
    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}}
        )
Exemplo n.º 7
0
    def test_dict_keys_missing_has_default_value(self):
        default = rand_string()
        d = Dict('d', 'k1', 'k2', 'k3', 'k4', default=default)
        value = {'k1':'v1', 'k2':'v2', 'k3':'v3'} # k4 doesn't exist but no exception is raised because a default value is set

        ret_value = d.from_json(value)
        eq_(sorted(ret_value.items()), [('k1', 'v1'), ('k2', 'v2'), ('k3', 'v3'), ('k4', default)])
Exemplo n.º 8
0
 class SimpleIO:
     input_optional = (List('page'), List('size'), List('sort'),
                       List('filters'), List('fields'), List('operator'))
     # Fields projection makes all output fields optional
     output_optional = (
         'id',
         'id_guest',
         'id_room',
         DateTime('reserved'),
         'guests',
         Date('check_in'),
         Date('check_out'),
         DateTime('checked_in'),
         DateTime('checked_out'),
         DateTime('cancelled'),
         'base_price',
         'taxes_percentage',
         'taxes_value',
         'total_price',
         'locator',
         'pin',
         'status',
         'meal_plan',
         Dict('extras'),
         'uuid',
         # UUID('uuid'),
         # 'uuid' # JSON serializaction error
         # https://forum.zato.io/t/returning-uuid-types-from-services-using-json/1735
         'nights',
         'count')
     skip_empty_keys = True
     output_repeated = True
Exemplo n.º 9
0
    def test_dict_keys_missing_no_default_value(self):
        d = Dict('d', 'k1', 'k2', 'k3', 'k4')
        value = {'k1':'v1', 'k2':'v2', 'k3':'v3'} # k4 doesn't exist so an exception should be raised

        try:
            d.from_json(value)
        except ValidationException, e:
            eq_(e.name, 'd')
            eq_(sorted(e.value.items()), [('k1', 'v1'), ('k2', 'v2'), ('k3', 'v3')])
            eq_(e.missing_elem, 'k4')
Exemplo n.º 10
0
 class SimpleIO:
     input_required = ('name', 'surname', 'email')
     input_optional = ('gender', 'passport', Date('birthdate'), 'address1',
                       'address2', 'locality', 'postcode', 'province',
                       'country', 'home_phone', 'mobile_phone')
     output_optional = ('id', 'name', 'surname', 'gender', 'email',
                        'passport', Date('birthdate'), 'address1',
                        'address2', 'locality', 'postcode', 'province',
                        'country', 'home_phone', 'mobile_phone',
                        Dict('error'))
     skip_empty_keys = True
Exemplo n.º 11
0
    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'))
Exemplo n.º 12
0
 class SimpleIO:
     input_required = (List('sub_key_list'), )
     output_optional = (Dict('messages'), )
Exemplo n.º 13
0
 class SimpleIO(AdminSIO):
     input_optional = ('sub_key', List('sub_key_list'))
     output_optional = (Dict('queue_depth'), )
Exemplo n.º 14
0
    def test_dict_keys_all_exist(self):
        d = Dict('d', 'k1', 'k2')
        value = {'k1':'v1', 'k2':'v2', 'k3':'v3'} # k3 is superfluous and should not be returned

        ret_value = d.from_json(value)
        eq_(sorted(ret_value.items()), [('k1', 'v1'), ('k2', 'v2')])
Exemplo n.º 15
0
    def test_dict_no_keys_specified(self):
        d = Dict('d')
        value = {rand_string(): rand_string(), rand_string(): rand_string()}

        ret_value = d.from_json(value)
        eq_(value, ret_value)
Exemplo n.º 16
0
 class SimpleIO:
     input_required = (Dict('dict1'), Dict('dict2'))
     output_required = (Dict('dict3'), Dict('dict4'))