From 7e71ce5012da348c2d5c002ffcef80edda0c57b2 Mon Sep 17 00:00:00 2001 From: Benoit Orihuela Date: Thu, 28 Sep 2023 17:58:52 +0200 Subject: [PATCH] feat: add body and headers of notifications received in the logs --- libraries/logUtils.py | 18 ++++++++++++++++++ resources/NotificationUtils.resource | 5 ++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/libraries/logUtils.py b/libraries/logUtils.py index 9254bc59..c796a189 100644 --- a/libraries/logUtils.py +++ b/libraries/logUtils.py @@ -39,3 +39,21 @@ def output(response, description, console=True): logger.info(pretty_request_json, also_console=True) logger.info("Response ->", also_console=True) logger.info(pretty_response_json, also_console=True) + + +@keyword(name="Output Notification", tags=("I/O",)) +def output_notification(body, headers, description, console=True): + """*Body and headers of the notification are output to terminal and file (in JSON).* + :param body: body of the notification received + :param headers: headers of the notification received + :param description: explains what request is being made + :param console: If false, the JSON is not written to terminal. Default is true. + """ + + request_json = {'headers': dict(headers), 'body': body} + + pretty_request_json = dumps(request_json, indent=4, sort_keys=False, separators=(",", ": ")) + + logger.info("\n" + description, also_console=True) + logger.info("Notification ->", also_console=True) + logger.info(pretty_request_json, also_console=True) diff --git a/resources/NotificationUtils.resource b/resources/NotificationUtils.resource index ac978eba..f17cc402 100644 --- a/resources/NotificationUtils.resource +++ b/resources/NotificationUtils.resource @@ -31,7 +31,9 @@ Wait for notification Reply By 200 ${notification_payload}= Get Request Body + ${notification_headers}= Get Request Headers ${notification}= Evaluate json.loads('''${notification_payload}''') json + Output Notification ${notification} ${notification_headers} Wait for notification RETURN ${notification} Wait for notification and validate it @@ -49,12 +51,13 @@ Wait for notification and validate it Reply By 200 ${notification_payload}= Get Request Body + ${notification_headers}= Get Request Headers ${notification}= Evaluate json.loads('''${notification_payload}''') json ${notification_data_length}= Get length ${notification}[data] ${expected_notification_data_entities_length}= Get length ${expected_notification_data_entities} ${expected_notification_data_length}= Get length ${expected_context_source_registration_ids} - log ${notification} + Output Notification ${notification} ${notification_headers} Wait for notification Should Be Equal ${notification}[type] ${notification_type} Should Be Equal ${notification}[subscriptionId] ${expected_subscription_id} ${is_date}= Is Date ${notification}[notifiedAt] ${date_format} -- GitLab