Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 15 additions & 37 deletions framework/python/src/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,21 +460,13 @@ async def get_reports(self):

async def delete_report(self, response: Response, report_name: str):

mac = report_name.split("_")[0]
device = self._session.get_device_by_mac_addr(mac)

# If the device not found
if device is None:
LOGGER.info("Device not found, returning 404")
response.status_code = 404
return self._generate_msg(False, "Device not found")

report = device.get_report_by_folder_name(report_name)
LOGGER.debug(f"Looking for report with name {report_name}")
if not report:
device_with_report = self._session.get_report(report_name)
if device_with_report.device is None or device_with_report.report is None:
LOGGER.info("Report could not be found, returning 404")
response.status_code = 404
return self._generate_msg(False, "Report not found")
return self._generate_msg(False, "Report not found from list")
device = device_with_report.device
report = device_with_report.report

if self._testrun.delete_report(device, report):
return self._generate_msg(True, "Deleted report")
Expand Down Expand Up @@ -680,22 +672,13 @@ async def edit_device(self, request: Request, response: Response):

async def get_report(self, response: Response, report_name):
"""Serve report pdf file for a given report name"""
mac = report_name.split("_")[0]
device = self._session.get_device_by_mac_addr(mac)

# If the device not found
if device is None:
LOGGER.info("Device not found, returning 404")
response.status_code = 404
return self._generate_msg(False, "Device not found")

report = device.get_report_by_folder_name(report_name)
LOGGER.debug(f"Looking for report with name {report_name}")
if not report:
device_with_report = self._session.get_report(report_name)
if device_with_report.device is None or device_with_report.report is None:
LOGGER.info("Report could not be found, returning 404")
response.status_code = 404
return self._generate_msg(False, "Report could not be found")

return self._generate_msg(False, "Report not found from list")
device = device_with_report.device
report = device_with_report.report

# Regenerate the pdf if the device profile has been updated
test_orc = self._get_testrun().get_test_orc()
Expand Down Expand Up @@ -738,18 +721,13 @@ async def get_results(
pass

# Check if device exists
mac = report_name.split("_")[0]
device = self._session.get_device_by_mac_addr(mac)
if device is None:
response.status_code = status.HTTP_404_NOT_FOUND
return self._generate_msg(False,
"Device not found")
report = device.get_report_by_folder_name(report_name)
LOGGER.debug(f"Looking for report with name {report_name}")
if not report:
device_with_report = self._session.get_report(report_name)
if device_with_report.device is None or device_with_report.report is None:
LOGGER.info("Report could not be found, returning 404")
response.status_code = 404
return self._generate_msg(False, "Report could not be found")
return self._generate_msg(False, "Report not found from list")
device = device_with_report.device
report = device_with_report.report

zip_file_path = self._get_testrun().get_test_orc().zip_results(
device, report, profile)
Expand Down
6 changes: 6 additions & 0 deletions framework/python/src/common/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,9 @@ def __setattr__(self, name: str, value: any) -> None:
# Update the last_updated timestamp
super().__setattr__('modified_at', datetime.now())
super().__setattr__(name, value)


@dataclass
class DeviceWithReport():
device: Device | None = None
report: TestReport | None = None
12 changes: 11 additions & 1 deletion framework/python/src/core/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from common import util, logger, mqtt
from common.risk_profile import RiskProfile
from common.statuses import TestrunStatus, TestResult, TestrunResult
from common.device import Device
from common.device import Device, DeviceWithReport
from net_orc.ip_control import IPControl

# Certificate dependencies
Expand Down Expand Up @@ -393,6 +393,16 @@ def get_device_by_mac_addr(self, mac_addr_simmplified: str) -> Device | None:
def get_device_repository(self):
return self._device_repository

def get_report(self, folder_name: str) -> DeviceWithReport:
device_with_report = DeviceWithReport()
for device in self._device_repository:
device_reports = device.get_reports()
for report in device_reports:
if report.get_folder_name() == folder_name:
device_with_report.device = device
device_with_report.report = report
return device_with_report

def add_device(self, device):
self._device_repository.append(device)

Expand Down
11 changes: 4 additions & 7 deletions framework/python/src/test_orc/test_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,18 +396,19 @@ def regenerate_pdf(self, device: Device, report: TestReport) -> str:
return self._regenerate_report_files(device, report)

def _regenerate_report_files(self, device: Device, report: TestReport) -> str:
'''Regenerate the report if the device profile has been updated'''
"""Regenerate the report if the device profile has been updated"""
# Report files path
report_dir = os.path.join(self._root_path, REPORTS_FOLDER)
report_dir = os.path.join(report_dir, report.get_folder_name())
test_folder_name = report.get_folder_name().split("_")[0]
test_path = os.path.join(
report_dir,
f'test/{device.mac_addr.replace(":", "")}'
f"test/{test_folder_name}"
)
try:
# Copy the original report for comparison
report_copy = copy.deepcopy(report)
# Update the report with 'additional_info' field
# Update the report with additional_info field
report.update_device_info(device)
device.export_config_json()
# Overwrite report only if additional_info has been changed
Expand Down Expand Up @@ -486,17 +487,13 @@ def _update_html_report(self, report: TestReport, html: str):
if value_div:
if "Manufacturer" in h4.string:
value_div.string = manufacturer
LOGGER.debug(f"Updated manufacturer to '{value_div.string}'")
elif "Model" in h4.string:
value_div.string = model
LOGGER.debug(f"Updated model to '{value_div.string}'")
all_header_info_divs = bs.find_all("div", class_="header-info")
for header_info_div in all_header_info_divs:
header_span = header_info_div.find_next_sibling("span")
if header_span:
header_span.string = title
LOGGER.debug(f"Updated sibling span to '{header_span.string}'")

return str(bs)

def test_in_progress(self):
Expand Down
12 changes: 6 additions & 6 deletions testing/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ def test_delete_report_no_device(empty_devices_dir, testrun): # pylint: disable=
assert "error" in response

# Check if the correct error message returned
assert "Device not found" in response["error"]
assert "Report not found" in response["error"]

@pytest.mark.parametrize("add_devices", [
["device_1"]
Expand Down Expand Up @@ -1167,13 +1167,13 @@ def test_get_report_not_found(empty_devices_dir, add_devices, testrun): # pylint
assert "error" in response

# Check if the correct error message is returned
assert "Report could not be found" in response["error"]
assert "Report not found from list" in response["error"]

# Check if "error" in response
assert "error" in response

# Check if the correct error message returned
assert "Report could not be found" in response["error"]
assert "Report not found from list" in response["error"]

def test_get_report_device_not_found(empty_devices_dir, testrun): # pylint: disable=W0613
"""Test getting a report when the device is not found (404)"""
Expand All @@ -1194,7 +1194,7 @@ def test_get_report_device_not_found(empty_devices_dir, testrun): # pylint: disa
assert "error" in response

# Check if the correct error message is returned
assert "Device not found" in response["error"]
assert "Report not found from list" in response["error"]

def test_export_report_device_not_found(empty_devices_dir, create_report_folder, # pylint: disable=W0613
testrun): # pylint: disable=W0613
Expand All @@ -1219,7 +1219,7 @@ def test_export_report_device_not_found(empty_devices_dir, create_report_folder,
assert "error" in response

# Check if the correct error message is returned
assert "Device not found" in response["error"]
assert "Report not found from list" in response["error"]

@pytest.mark.parametrize("add_devices", [
["device_1"]
Expand Down Expand Up @@ -1288,7 +1288,7 @@ def test_export_report_not_found(empty_devices_dir, add_devices, testrun): # pyl
assert "error" in response

# Check if the correct error message is returned
assert "Report could not be found" in response["error"]
assert "Report not found from list" in response["error"]

# Tests for device endpoints
@pytest.fixture()
Expand Down
Loading