def load_micro_services(plugin_path, plugins, internal_attributes): """ Loads micro services :type plugin_path: list[str] :type plugins: list[str] :type internal_attributes: dict[string, dict[str, str | list[str]]] :rtype (satosa.micro_service.service_base.RequestMicroService, satosa.micro_service.service_base.ResponseMicroService) :param plugin_path: Path to the plugin directory :param plugins: A list with the name of the plugin files :return: (Request micro service, response micro service) """ request_services = _load_plugins(plugin_path, plugins, _request_micro_service_filter, RequestMicroService.__name__, "") response_services = _load_plugins(plugin_path, plugins, _response_micro_service_filter, ResponseMicroService.__name__, "", internal_attributes=internal_attributes) LOGGER.info( "Loaded request micro services: %s" % [k.__class__.__name__ for k in request_services]) LOGGER.info( "Loaded response micro services: %s" % [k.__class__.__name__ for k in response_services]) return ( build_micro_service_queue(request_services), build_micro_service_queue(response_services))
def test_micro_service(): """ Test the micro service flow """ data_list = ["1", "2", "3"] service_list = [] for d in data_list: service = MicroService() service.process = create_process_func(d) service_list.append(service) service_queue = build_micro_service_queue(service_list) test_data = "test_data" context = Context() context.state = State() data = service_queue.process_service_queue(context, test_data) for d in data_list: test_data = "{}{}".format(test_data, d) assert data == test_data
def test_mirco_service_error(): """ Test that the process_service_queue raises a SATOSAAuthenticationError if anything goes wrong with a micro service """ data_list = ["1", "2", "3"] service_list = [] fail_service = MicroService() fail_service.process = create_process_fail_func("4") service_list.append(fail_service) for d in data_list: service = MicroService() service.process = create_process_func(d) service_list.append(service) service_queue = build_micro_service_queue(service_list) test_data = "test_data" context = Context() context.state = State() with pytest.raises(SATOSAAuthenticationError): service_queue.process_service_queue(context, test_data)