Skip to content

Commit

Permalink
Got the tables to work, now just need the error blocks next
Browse files Browse the repository at this point in the history
  • Loading branch information
cerdmann committed Sep 10, 2024
1 parent 80c4666 commit d1fbaa2
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 3 deletions.
54 changes: 54 additions & 0 deletions postman_cli_transformer/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
Empty file removed tests/blah.txt
Empty file.
124 changes: 121 additions & 3 deletions tests/test_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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_WITHOUT_FOLDER>",
"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)

0 comments on commit d1fbaa2

Please sign in to comment.