Skip to content

Commit

Permalink
Fix Attribute Errors (#980)
Browse files Browse the repository at this point in the history
* Fixed silent non-fatal attribute error in InteractiveReport. Fixed fatal attribute error thrown by the backend on filtered runtime status.
  • Loading branch information
M6AI authored Aug 15, 2023
1 parent d98ac72 commit 0a875ed
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 9 deletions.
1 change: 1 addition & 0 deletions doc/newsfragments/2630_changed.fix_attribute_error.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed both a silent exception and an `AttributeError` raised by running a single testcase on interactive UI with an active filter.
16 changes: 16 additions & 0 deletions testplan/report/testing/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,22 @@ def runtime_status(self, new_status):
if new_status == RuntimeStatus.FINISHED:
self._status = Status.PASSED # passed if case report has no entry

# NOTE: this is only for compatibility with the API for filtering.
def set_runtime_status_filtered(
self,
new_status: str,
entries: Dict,
) -> None:
"""
Alternative setter for the runtime status of an entry, here it is
equivalent to simply setting the runtime status.
:param new_status: new runtime status to be set
:param entries: tree-like structure of entries names, unused, but
needed for current API compatibility
"""
self.runtime_status = new_status

def _assertions_status(self):
for entry in self:
if entry.get(Status.PASSED) is False:
Expand Down
11 changes: 5 additions & 6 deletions testplan/runnable/interactive/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,12 +919,11 @@ def _extract_entries(entry: Dict) -> Dict:
"""
entries = {}

# NOTE: we assume "entries" is present, see application of the function
for child in entry["entries"]:
if child["category"] == ReportCategories.TESTCASE:
entries[child["name"]] = {}
else:
entries[child["name"]] = _extract_entries(child)
if entry["category"] == ReportCategories.TESTCASE:
return entries

for child in entry.get("entries", []):
entries[child["name"]] = _extract_entries(child)

return entries

Expand Down
10 changes: 7 additions & 3 deletions testplan/web_ui/testing/src/Report/InteractiveReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,16 +471,20 @@ class InteractiveReportComponent extends BaseReport {
category: category,
};

if (entries.length !== 0 && category !== "testcase") {
pruneEntry.entries = entries.map((entry) => this.pruneReportEntry(entry));
if (entries) {
if (entries.length && category !== "testcase") {
pruneEntry.entries = entries.map(
(entry) => this.pruneReportEntry(entry)
);
}
}

return pruneEntry;
}

/**
* Shallow copy of a report entry, by replacing the "entries" attribute
* with an array of entry UIDs if not filter is present.
* with an array of entry UIDs if no filter is present.
* In case there is a non-empty filter text, the entries attribute is pruned.
*/
shallowReportEntry(reportEntry) {
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/testplan/runnable/interactive/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,26 @@ def test_put(self, api_env, testcase_uid):

def test_put_filtered(self, api_env):
"""Test updating the SingleTestcase resource via PUT."""
client, ihandler = api_env
report_entry = ihandler.report["MTest1"]["MT1Suite1"]["MT1S1TC1"]

testcase_json = report_entry.serialize()
testcase_json["runtime_status"] = report.RuntimeStatus.RUNNING
rsp = client.put(
"/api/v1/interactive/report/tests/MTest1/suites/MT1Suite1/"
"testcases/{}".format("MT1S1TC1"),
json=testcase_json,
)
assert rsp.status_code == 200
ihandler.run_test_case.assert_called_once_with(
"MTest1",
"MT1Suite1",
"MT1S1TC1",
shallow_report=testcase_json,
await_results=False,
)

def test_put_filtered_parametrized(self, api_env):
client, ihandler = api_env
report_entry = ihandler.report["MTest1"]["MT1Suite1"]["MT1S1TC2"]

Expand Down

0 comments on commit 0a875ed

Please sign in to comment.