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)
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)
def xtest_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)
def xtest_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)
def test_init_sio(self): is_sio = True cid = uuid4().hex data_format = uuid4().hex transport = uuid4().hex io_default = {'dummy':'dummy'} 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'} request = Request(logger) request.payload = None request.raw_request = io_default request.get_params = _get_params request.channel_params['a'] = 'channel_param_a' request.channel_params['b'] = 'channel_param_b' request.channel_params['c'] = 'channel_param_c' request.channel_params['d'] = 'channel_param_d' request.channel_params['e'] = 'channel_param_e' request.channel_params['f'] = 'channel_param_f' request.channel_params['h'] = 'channel_param_h' # Never overridden for io in(io_default, io_custom): for params_priority in PARAMS_PRIORITY: request.params_priority = params_priority request.http.init(wsgi_environ) request.payload = io request.init(is_sio, cid, io, data_format, transport, wsgi_environ) if io is io_default: eq_(sorted(request.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(request.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(request.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()))
def xtest_init_sio(self): is_sio = True cid = uuid4().hex data_format = uuid4().hex transport = uuid4().hex io_default = {'dummy':'dummy'} 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, } for io in(io_default, io_custom): for params_priority in PARAMS_PRIORITY: request = Request(logger) request.payload = None request.raw_request = io_default request.channel_params['a'] = 'channel_param_a' request.channel_params['b'] = 'channel_param_b' request.channel_params['c'] = 'channel_param_c' request.channel_params['d'] = 'channel_param_d' request.channel_params['e'] = 'channel_param_e' request.channel_params['f'] = 'channel_param_f' request.channel_params['h'] = 'channel_param_h' # Never overridden def _get_params(request_params, *ignored): # Note that 'g' is never overridden if params_priority == PARAMS_PRIORITY.CHANNEL_PARAMS_OVER_MSG: if request_params is io_custom['input_required']: return {'a':request.channel_params['a'], 'b':request.channel_params['b'], 'c':request.channel_params['c'], 'g':'g-msg'} else: return {'d':request.channel_params['d'], 'e':request.channel_params['e'], 'f':request.channel_params['f'], 'g':'g-msg'} else: 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'} request.get_params = _get_params request.params_priority = params_priority request.http.init(wsgi_environ) request.payload = io request.init(is_sio, cid, io, data_format, transport, wsgi_environ) if io is io_default: eq_(sorted(request.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(request.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(request.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()))
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() ), )