Skip to content

Commit

Permalink
fix: handle empty jobs response and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alperenkose committed Apr 4, 2024
1 parent d9557de commit a8d46a7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion panos_upgrade_assurance/firewall_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1393,7 +1393,7 @@ def get_jobs(self) -> dict:
jobs = self.op_parser(cmd="show jobs all")
results = dict()

job_results = jobs.get("job")
job_results = jobs.get("job") if isinstance(jobs, dict) else None
if isinstance(job_results, list):
for job in job_results:
jid = job["id"]
Expand Down
50 changes: 50 additions & 0 deletions tests/test_firewall_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,56 @@ def test_get_jobs(self, fw_proxy_mock):
},
}

def test_get_jobs_single_job(self, fw_proxy_mock):
xml_text = """
<response status="success">
<result>
<job>
<tenq>2023/08/07 03:59:57</tenq>
<tdeq>03:59:57</tdeq>
<id>1</id>
<user/>
<type>AutoCom</type>
<status>FIN</status>
<queued>NO</queued>
<stoppable>no</stoppable>
<result>OK</result>
<tfin>2023/08/07 04:00:28</tfin>
<description/>
<positionInQ>0</positionInQ>
<progress>100</progress>
<details>
<line>Configuration committed successfully</line>
<line>Successfully committed last configuration</line>
</details>
<warnings/>
</job>
</result>
</response>
"""

raw_response = ET.fromstring(xml_text)
fw_proxy_mock.op.return_value = raw_response

assert fw_proxy_mock.get_jobs() == {
"1": {
"tenq": "2023/08/07 03:59:57",
"tdeq": "03:59:57",
"user": None,
"type": "AutoCom",
"status": "FIN",
"queued": "NO",
"stoppable": "no",
"result": "OK",
"tfin": "2023/08/07 04:00:28",
"description": None,
"positionInQ": "0",
"progress": "100",
"details": {"line": ["Configuration committed successfully", "Successfully committed last configuration"]},
"warnings": None,
},
}

def test_get_jobs_no_jobs(self, fw_proxy_mock):
xml_text = """
<response status="success">
Expand Down

0 comments on commit a8d46a7

Please sign in to comment.