def test_request_getting_values(self): test_request_config = { "url": "/last", "httpMethod": "GET", "deviceNameJsonExpression": "${$.sensor}", "deviceTypeJsonExpression": "default", "httpHeaders": { "ACCEPT": "application/json" }, "allowRedirects": True, "timeout": 0.5, "scanPeriod": 5, "converter": { "deviceNameJsonExpression": "${$.sensor}", "deviceTypeJsonExpression": "default", "type": "json", "attributes": [], "telemetry": [{ "key": "${$.name}", "type": "int", "value": "${$.value}" }] } } test_request_body_to_convert = { "name": "Humidity", "sensor": "aranet:358151000412:100886", "time": "2020-03-17T16:16:03Z", "unit": "%RH", "value": "66" } test_request_convert_config = "127.0.0.1:5000/last" test_request_result = { "deviceName": "aranet:358151000412:100886", "deviceType": "default", "attributes": [], "telemetry": [{ "Humidity": '66' }] } converter = JsonRequestUplinkConverter(test_request_config) result = converter.convert(test_request_config, test_request_body_to_convert) self.assertDictEqual(result, test_request_result)
def __fill_requests(self): log.debug(self.__config["mapping"]) for endpoint in self.__config["mapping"]: try: log.debug(endpoint) converter = None if endpoint["converter"]["type"] == "custom": module = TBUtility.check_and_import( self.__connector_type, endpoint["converter"]["extension"]) if module is not None: log.debug('Custom converter for url %s - found!', endpoint["url"]) converter = module(endpoint) else: log.error( "\n\nCannot find extension module for %s url.\nPlease check your configuration.\n", endpoint["url"]) else: converter = JsonRequestUplinkConverter(endpoint) self.__requests_in_progress.append({ "config": endpoint, "converter": converter, "next_time": time(), "request": request }) except Exception as e: log.exception(e)