def test_validate_against_bad_template_should_not_throw(self): # setup device_template = "an_unparseable_template" properties = MessageProperties(content_encoding=self.encoding, content_type=self.content_type) message = Message( body=json.dumps(self.bad_dcm_payload).encode(), properties=properties, annotations={ common_parser.DEVICE_ID_IDENTIFIER: self.device_id.encode() }, application_properties=_encode_app_props(self.app_properties), ) args = CommonParserArguments(properties=["all"]) parser = self._create_parser(device_template=device_template, message=message, args=args) # haven't found a better way to force the error to occur within parser parser._central_template_provider.get_device_template = lambda x: Template( device_template) # act parsed_msg = parser.parse_message() # verify assert parsed_msg["event"]["payload"] == self.bad_dcm_payload assert parsed_msg["event"]["origin"] == self.device_id expected_details = strings.device_template_not_found( "Could not parse iot central device template.") _validate_issues(parser, Severity.error, 1, 1, [expected_details])
def _get_device_template(self): try: return self._central_device_provider.get_device_template_by_device_id( self.device_id) except Exception as e: details = strings.device_template_not_found(e) self._add_central_issue(severity=Severity.error, details=details)
def _get_template(self): try: device = self._central_device_provider.get_device(self.device_id) template = self._central_template_provider.get_device_template( device.instance_of) self._template_id = template.id return template except Exception as e: details = strings.device_template_not_found(e) self._add_central_issue(severity=Severity.error, details=details)