From d1fbaa2c170eb6927f836579b9f5a43e154f674c Mon Sep 17 00:00:00 2001 From: cerdmann Date: Tue, 10 Sep 2024 18:43:52 -0500 Subject: [PATCH] Got the tables to work, now just need the error blocks next --- postman_cli_transformer/processor.py | 54 ++++++++++++ tests/blah.txt | 0 tests/test_processor.py | 124 ++++++++++++++++++++++++++- 3 files changed, 175 insertions(+), 3 deletions(-) delete mode 100644 tests/blah.txt diff --git a/postman_cli_transformer/processor.py b/postman_cli_transformer/processor.py index f297420..a3e9fd1 100644 --- a/postman_cli_transformer/processor.py +++ b/postman_cli_transformer/processor.py @@ -94,6 +94,59 @@ def _process_rest_of_lines(self): self.parsed["folders"][self.processing_helper.current_folder][ "requests" ][self.processing_helper.current_request]["tests"].append(test_json) + case LINE_TYPES.SUMMARY_LINE: + if not self.processing_helper.started_table: + self.processing_helper.started_table = True + self.parsed["summary"] = { + "iterations": {}, + "requests": {}, + "test-scripts": {}, + "prerequest-scripts": {}, + "assertions": {}, + "totals": { + "totalRunDuration": "", + "totalDataReceived": "", + "responseTimes": { + "average": "", + "min": "", + "max": "", + "s.d.": "", + }, + }, + } + else: + summary_parts = line.split() + if "iterations" in line: + self._add_summary("iterations", summary_parts) + elif "requests" in line: + self._add_summary("requests", summary_parts) + elif "test-scripts" in line: + self._add_summary("test-scripts", summary_parts) + elif "prerequest-scripts" in line: + self._add_summary("prerequest-scripts", summary_parts) + elif "assertions" in line: + self._add_summary("assertions", summary_parts) + elif "run" in line: + self.parsed["summary"]["totals"]["totalRunDuration"] = ( + summary_parts[4] + ) + elif "data" in line: + self.parsed["summary"]["totals"]["totalDataReceived"] = ( + "%s %s" % (summary_parts[4], summary_parts[5]) + ) + elif "response" in line: + self.parsed["summary"]["totals"]["responseTimes"] = { + "average": summary_parts[4], + "min": summary_parts[6].rstrip(","), + "max": summary_parts[8].rstrip(","), + "s.d.": summary_parts[10].rstrip("]"), + } + + def _add_summary(self, title, parts): + self.parsed["summary"][title] = { + "executed": parts[3], + "failed": parts[5], + } class ProcessingHelper: @@ -102,6 +155,7 @@ class ProcessingHelper: current_folder = -1 current_request = -1 root_request_folder = -1 + started_table = False def update_current_line_type(self, new_line_type): self.previous_line_type = self.current_line_type diff --git a/tests/blah.txt b/tests/blah.txt deleted file mode 100644 index e69de29..0000000 diff --git a/tests/test_processor.py b/tests/test_processor.py index 6282c22..85f18fe 100644 --- a/tests/test_processor.py +++ b/tests/test_processor.py @@ -352,9 +352,6 @@ def test_should_be_able_to_process_root_level_requests(): processor = Processor(lines) results = processor.parsed - print(results) - - folders_node = results["folders"] expected_results = { "collectionName": "Pinball Map Collection", @@ -531,3 +528,124 @@ def test_should_be_able_to_process_root_level_requests(): } assert json.dumps(results) == json.dumps(expected_results) + + +def test_should_be_able_to_process_the_summary_table(): + lines = create_array_from_text("""postman + +Deactivate User Accounts + +→ Deactivate a user + + GET https://api.getpostman.com/scim/v2/Users?count=10000 [401 Unauthorized, 485B, 261ms] + PATCH https://api.getpostman.com/scim/v2/Users/{{userId}} [401 Unauthorized, 485B, 64ms] + +→ Change a user + + GET https://api.getpostman.com/scim/v2/Users?count=10000 [401 Unauthorized, 485B, 261ms] + PATCH https://api.getpostman.com/scim/v2/Users/{{userId}} [401 Unauthorized, 485B, 64ms] + +┌─────────────────────────┬────────────────────┬───────────────────┐ +│ │ executed │ failed │ +├─────────────────────────┼────────────────────┼───────────────────┤ +│ iterations │ 1 │ 0 │ +├─────────────────────────┼────────────────────┼───────────────────┤ +│ requests │ 4 │ 0 │ +├─────────────────────────┼────────────────────┼───────────────────┤ +│ test-scripts │ 2 │ 0 │ +├─────────────────────────┼────────────────────┼───────────────────┤ +│ prerequest-scripts │ 4 │ 0 │ +├─────────────────────────┼────────────────────┼───────────────────┤ +│ assertions │ 0 │ 0 │ +├─────────────────────────┴────────────────────┴───────────────────┤ +│ total run duration: 487ms │ +├──────────────────────────────────────────────────────────────────┤ +│ total data received: 604B (approx) │ +├──────────────────────────────────────────────────────────────────┤ +│ average response time: 103ms [min: 51ms, max: 253ms, s.d.: 86ms] │ +└──────────────────────────────────────────────────────────────────┘ + +Postman CLI run data uploaded to Postman Cloud successfully. +You can view the run data in Postman at: https://go.postman.co/workspace/71a6b37b-a01d-43b4-bcf2-4cc75f1d3d7b/run/33123329-986f44d8-9cda-4445-9179-137678aa1303 +""") + + processor = Processor(lines) + results = processor.parsed + + expected_results = { + "collectionName": "Deactivate User Accounts", + "folders": [ + { + "name": "", + "requests": [ + { + "name": "Deactivate a user", + "urls": [ + { + "url": "https://api.getpostman.com/scim/v2/Users?count=10000", + "httpVerb": "GET", + "response": { + "code": "401 Unauthorized", + "size": "485B", + "time": "261ms", + }, + }, + { + "url": "https://api.getpostman.com/scim/v2/Users/{{userId}}", + "httpVerb": "PATCH", + "response": { + "code": "401 Unauthorized", + "size": "485B", + "time": "64ms", + }, + }, + ], + "tests": [], + }, + { + "name": "Change a user", + "urls": [ + { + "url": "https://api.getpostman.com/scim/v2/Users?count=10000", + "httpVerb": "GET", + "response": { + "code": "401 Unauthorized", + "size": "485B", + "time": "261ms", + }, + }, + { + "url": "https://api.getpostman.com/scim/v2/Users/{{userId}}", + "httpVerb": "PATCH", + "response": { + "code": "401 Unauthorized", + "size": "485B", + "time": "64ms", + }, + }, + ], + "tests": [], + }, + ], + }, + ], + "summary": { + "iterations": {"executed": "1", "failed": "0"}, + "requests": {"executed": "4", "failed": "0"}, + "test-scripts": {"executed": "2", "failed": "0"}, + "prerequest-scripts": {"executed": "4", "failed": "0"}, + "assertions": {"executed": "0", "failed": "0"}, + "totals": { + "totalRunDuration": "487ms", + "totalDataReceived": "604B (approx)", + "responseTimes": { + "average": "103ms", + "min": "51ms", + "max": "253ms", + "s.d.": "86ms", + }, + }, + }, + } + + assert json.dumps(results) == json.dumps(expected_results)