Пример #1
0
 def test_sio_list_data_type_input_xml(self):
     cid = rand_string()
     data_format = DATA_FORMAT.XML
     transport = rand_string()
     
     sio_config = {'int_parameters': [rand_string()]} # Not really used but needed
     
     service_sio = Bunch()
     service_sio.input_required = ('first_name', 'last_name', List('emails'))
     
     expected_first_name = faker.first_name()
     expected_last_name = faker.last_name()
     expected_emails = sorted([faker.email(), faker.email()])
     
     r = Request(getLogger(__name__), sio_config)
     r.payload = etree.fromstring("""<request>
       <first_name>{}</first_name>
       <last_name>{}</last_name>
       <emails>
        <item>{}</item>
        <item>{}</item>
       </emails>
     </request>""".format(
         expected_first_name, expected_last_name, expected_emails[0], expected_emails[1]))
     
     r.init(True, cid, service_sio, data_format, transport, {})
     
     eq_(r.input.first_name, expected_first_name)
     eq_(r.input.last_name, expected_last_name)
     eq_(r.input.emails, expected_emails)
Пример #2
0
 def test_sio_list_data_type_input_json(self):
     cid = rand_string()
     data_format = DATA_FORMAT.JSON
     transport = rand_string()
     
     sio_config = {'int_parameters': [rand_string()]} # Not really used but needed
     
     service_sio = Bunch()
     service_sio.input_required = ('first_name', 'last_name', List('emails'))
     
     expected_first_name = faker.first_name()
     expected_last_name = faker.last_name()
     expected_emails = sorted([faker.email(), faker.email()])
     
     r = Request(getLogger(__name__), sio_config)
     r.payload = {
         'first_name': expected_first_name,
         'last_name': expected_last_name,
         'emails': expected_emails,
         }
     
     r.init(True, cid, service_sio, data_format, transport, {})
     
     eq_(r.input.first_name, expected_first_name)
     eq_(r.input.last_name, expected_last_name)
     eq_(r.input.emails, expected_emails)
Пример #3
0
 def test_init_no_sio(self):
     is_sio = False
     cid = uuid4().hex
     data_format = uuid4().hex
     io = uuid4().hex
     
     wsgi_environ = {
         'zato.http.GET': {uuid4().hex:uuid4().hex}, 
         'zato.http.POST': {uuid4().hex:uuid4().hex}, 
         'REQUEST_METHOD': uuid4().hex, 
     }
     
     for transport in(None, URL_TYPE.PLAIN_HTTP, URL_TYPE.SOAP):
         r = Request(None)
         r.init(is_sio, cid, io, data_format, transport, wsgi_environ)
         
         if transport is None:
             eq_(r.http.method, None)
             eq_(r.http.GET, None)
             eq_(r.http.POST, None)
         else:
             eq_(r.http.method, wsgi_environ['REQUEST_METHOD'])
             eq_(sorted(r.http.GET.items()), sorted(wsgi_environ['zato.http.GET'].items()))
             eq_(sorted(r.http.POST.items()), sorted(wsgi_environ['zato.http.POST'].items()))
Пример #4
0
 def test_init_no_sio(self):
     is_sio = False
     cid = uuid4().hex
     data_format = uuid4().hex
     io = uuid4().hex
     
     wsgi_environ = {
         'zato.http.GET': {uuid4().hex:uuid4().hex}, 
         'zato.http.POST': {uuid4().hex:uuid4().hex}, 
         'REQUEST_METHOD': uuid4().hex, 
     }
     
     for transport in(None, URL_TYPE.PLAIN_HTTP, URL_TYPE.SOAP):
         r = Request(None)
         r.init(is_sio, cid, io, data_format, transport, wsgi_environ)
         
         if transport is None:
             eq_(r.http.method, None)
             eq_(r.http.GET, None)
             eq_(r.http.POST, None)
         else:
             eq_(r.http.method, wsgi_environ['REQUEST_METHOD'])
             eq_(sorted(r.http.GET.items()), sorted(wsgi_environ['zato.http.GET'].items()))
             eq_(sorted(r.http.POST.items()), sorted(wsgi_environ['zato.http.POST'].items()))
Пример #5
0
    def test_init_sio(self):

        is_sio = True
        cid = uuid4().hex
        data_format = uuid4().hex
        transport = uuid4().hex
        
        io_default = {}
        io_custom = Bunch({
            'request_elem': uuid4().hex,
            'input_required': ['a', 'b', 'c'],
            'input_optional': ['d', 'e', 'f'],
            'default_value': uuid4().hex,
            'use_text': uuid4().hex,
        })
        
        wsgi_environ = {
            'zato.http.GET': {uuid4().hex:uuid4().hex}, 
            'zato.http.POST': {uuid4().hex:uuid4().hex}, 
            'REQUEST_METHOD': uuid4().hex, 
        }
        
        def _get_params(request_params, *ignored):
            # 'g' is never overridden
            if request_params is io_custom['input_required']:
                return {'a':'a-req', 'b':'b-req', 'c':'c-req', 'g':'g-msg'}
            else:
                return {'d':'d-opt', 'e':'e-opt', 'f':'f-opt', 'g':'g-msg'}
        
        r = Request(None)
        r.payload = None
        r.get_params = _get_params
        
        r.channel_params['a'] = 'channel_param_a'
        r.channel_params['b'] = 'channel_param_b'
        r.channel_params['c'] = 'channel_param_c'
        r.channel_params['d'] = 'channel_param_d'
        r.channel_params['e'] = 'channel_param_e'
        r.channel_params['f'] = 'channel_param_f'
        r.channel_params['h'] = 'channel_param_h' # Never overridden
        
        for io in(io_default, io_custom):
            for params_priority in PARAMS_PRIORITY:
                r.params_priority = params_priority
                r.init(is_sio, cid, io, data_format, transport, wsgi_environ)

                if io is io_default:
                    eq_(sorted(r.input.items()), 
                        sorted({'a': 'channel_param_a', 'b': 'channel_param_b', 'c': 'channel_param_c',
                         'd': 'channel_param_d', 'e': 'channel_param_e', 'f': 'channel_param_f',
                         'h':'channel_param_h'}.items()))
                else:
                    if params_priority == PARAMS_PRIORITY.CHANNEL_PARAMS_OVER_MSG:
                        eq_(sorted(r.input.items()), 
                            sorted({'a': 'channel_param_a', 'b': 'channel_param_b', 'c': 'channel_param_c',
                             'd': 'channel_param_d', 'e': 'channel_param_e', 'f': 'channel_param_f',
                             'g': 'g-msg',
                             'h':'channel_param_h'}.items()))
                    else:
                        eq_(sorted(r.input.items()), 
                            sorted({'a': 'a-req', 'b': 'b-req', 'c': 'c-req',
                             'd': 'd-opt', 'e': 'e-opt', 'f': 'f-opt',
                             'g': 'g-msg',
                             'h':'channel_param_h'}.items()))
Пример #6
0
    def test_init_sio(self):

        is_sio = True
        cid = uuid4().hex
        data_format = uuid4().hex
        transport = uuid4().hex
        
        io_default = {}
        io_custom = Bunch({
            'request_elem': uuid4().hex,
            'input_required': ['a', 'b', 'c'],
            'input_optional': ['d', 'e', 'f'],
            'default_value': uuid4().hex,
            'use_text': uuid4().hex,
        })
        
        wsgi_environ = {
            'zato.http.GET': {uuid4().hex:uuid4().hex}, 
            'zato.http.POST': {uuid4().hex:uuid4().hex}, 
            'REQUEST_METHOD': uuid4().hex, 
        }
        
        def _get_params(request_params, *ignored):
            # 'g' is never overridden
            if request_params is io_custom['input_required']:
                return {'a':'a-req', 'b':'b-req', 'c':'c-req', 'g':'g-msg'}
            else:
                return {'d':'d-opt', 'e':'e-opt', 'f':'f-opt', 'g':'g-msg'}
        
        r = Request(None)
        r.payload = None
        r.get_params = _get_params
        
        r.channel_params['a'] = 'channel_param_a'
        r.channel_params['b'] = 'channel_param_b'
        r.channel_params['c'] = 'channel_param_c'
        r.channel_params['d'] = 'channel_param_d'
        r.channel_params['e'] = 'channel_param_e'
        r.channel_params['f'] = 'channel_param_f'
        r.channel_params['h'] = 'channel_param_h' # Never overridden
        
        for io in(io_default, io_custom):
            for params_priority in PARAMS_PRIORITY:
                r.params_priority = params_priority
                r.init(is_sio, cid, io, data_format, transport, wsgi_environ)

                if io is io_default:
                    eq_(sorted(r.input.items()), 
                        sorted({'a': 'channel_param_a', 'b': 'channel_param_b', 'c': 'channel_param_c',
                         'd': 'channel_param_d', 'e': 'channel_param_e', 'f': 'channel_param_f',
                         'h':'channel_param_h'}.items()))
                else:
                    if params_priority == PARAMS_PRIORITY.CHANNEL_PARAMS_OVER_MSG:
                        eq_(sorted(r.input.items()), 
                            sorted({'a': 'channel_param_a', 'b': 'channel_param_b', 'c': 'channel_param_c',
                             'd': 'channel_param_d', 'e': 'channel_param_e', 'f': 'channel_param_f',
                             'g': 'g-msg',
                             'h':'channel_param_h'}.items()))
                    else:
                        eq_(sorted(r.input.items()), 
                            sorted({'a': 'a-req', 'b': 'b-req', 'c': 'c-req',
                             'd': 'd-opt', 'e': 'e-opt', 'f': 'f-opt',
                             'g': 'g-msg',
                             'h':'channel_param_h'}.items()))