def _on_dpi(self, data): parsed_data = data_protocol.read_init(data) try: if self._params: init_params = self._params.copy() parsed_data.update(init_params) self._adapter.initialize(parsed_data, self._config_file) self._adapter.set_listener(self) except Exception as err: res = data_protocol.write_init(err) else: res = data_protocol.write_init() return res
def test_dpi_metaproviderexception(self): """Tests the response to a DPI request in the case of a DataProviderError. """ error = DataProviderError("DataProvider Error") res = data_protocol.write_init(exception=error) self.assertEqual("DPI|ED|DataProvider+Error", res)
def test_dpi_generic_exception(self): """Tests the response to a DPI request in the case of a generic exception. """ res = data_protocol.write_init(exception=RuntimeError("Generic Error")) self.assertEqual("DPI|E|Generic+Error", res)
def test_dpi_with_parameters(self): """Tests the response to a DPI request with a list of parameters.""" parameters = {'param1': 'value1', 'param2': 'value2'} res = data_protocol.write_init(parameters) self.assertEqual("DPI|S|param1|S|value1|S|param2|S|value2", res)
def test_dpi(self): """Tests the response to a DPI request.""" res = data_protocol.write_init() self.assertEqual("DPI|V", res)