diff --git a/test_archiver/archiver.py b/test_archiver/archiver.py index adad7b0..60b1976 100644 --- a/test_archiver/archiver.py +++ b/test_archiver/archiver.py @@ -517,6 +517,9 @@ def __init__(self, connection, configuration, build_number_cache=None): if self.config.change_engine_url: self.listeners.append( archiver_listeners.ChangeEngineListener(self, self.config.change_engine_url)) + if self.config.link_injection_file: + self.listeners.append( + archiver_listeners.ExternalLinkInjector(self, self.config.link_translation_file)) def current_item(self, expected_type=None): item = self.stack[-1] if self.stack else None @@ -667,11 +670,13 @@ def begin_keyword(self, name, library, kw_type, arguments=None): return keyword def end_keyword(self, attributes=None): + keyword = self.current_item(Keyword) if attributes: - self.current_item(Keyword).update_status(attributes['status'], attributes['starttime'], - attributes['endtime']) - self.current_item(Keyword).finish() + keyword.update_status(attributes['status'], attributes['starttime'], attributes['endtime']) + keyword.finish() self.stack.pop() + for listener in self.listeners: + listener.keyword_result(keyword) def keyword(self, name, library, kw_type, status, arguments=None): keyword = self.begin_keyword(name, library, kw_type, arguments) @@ -703,12 +708,15 @@ def begin_log_message(self, level, timestamp=None): self.stack.append(LogMessage(self, level, timestamp)) def end_log_message(self, content): - self.current_item(LogMessage).insert(content) + log_message = self.current_item(LogMessage) + log_message.insert(content) self.stack.pop() + for listener in self.listeners: + listener.log_message(log_message, content) def report_keyword_statistics(self): - for fingerprint in self.keyword_statistics: - self.db.insert('keyword_statistics', self.keyword_statistics[fingerprint]) + for statistic in self.keyword_statistics.values(): + self.db.insert('keyword_statistics', statistic) def timestamp_to_datetime(timestamp): diff --git a/test_archiver/archiver_listeners.py b/test_archiver/archiver_listeners.py index 233323b..86ae505 100644 --- a/test_archiver/archiver_listeners.py +++ b/test_archiver/archiver_listeners.py @@ -14,6 +14,12 @@ def suite_result(self, suite): def test_result(self, test): self.tests.append(test) + def keyword_result(self, keyword): + pass + + def log_message(self, log_message, content): + pass + def end_run(self): pass @@ -66,3 +72,20 @@ def _format_body(self, tests): "context": self.archiver.execution_context, "execution_id": self.archiver.execution_id, } + + +class ExternalLinkInjector(DefaultListener): + def __init__(self, archiver, translation_file_path): + super().__init__(archiver) + self.translation_file_path = translation_file_path + self.mapping = {} + with open(translation_file_path, 'r', encoding='utf-8') as file: + for line in file.readlines(): + reference, link = line.split() + self.mapping[reference] = link + + def log_message(self, log_message, content): + for reference, link in self.mapping.items(): + if reference in content: + self.archiver.log_message('LINK', link) + return diff --git a/test_archiver/configs.py b/test_archiver/configs.py index 1f33fb4..72a3371 100644 --- a/test_archiver/configs.py +++ b/test_archiver/configs.py @@ -116,6 +116,10 @@ def _resolve_options(self): self.changes = self.resolve_changes() self.execution_id = self.resolve_option('execution_id', default='Not set') + # Link translator + self.link_translation_file = self.resolve_option('link_injection_file') + + def resolve_option(self, name, default=None, cast_as=str): if self._cli_args and name in self._cli_args and self._cli_args.__getattribute__(name) is not None: value = self._cli_args.__getattribute__(name) diff --git a/test_archiver/output_parser.py b/test_archiver/output_parser.py index c56e431..b5132aa 100644 --- a/test_archiver/output_parser.py +++ b/test_archiver/output_parser.py @@ -848,6 +848,10 @@ def argument_parser(): group.add_argument('--execution-id', default='default', help='Identifier or version of the tested application for given execution-context. ' 'Stored in ChangeEngine and returned by "last_update" query.') + + group = parser.add_argument_group('Other builtin Listeners') + group.add_argument('--link-injection-file', default=None, + help="File with reference and links to be inserted separated by space.") return parser