def get(self, project_id: int): args = self.get_parser.parse_args(strict=False) reports = [] total, res = get(project_id, args, Task) for each in res: reports.append(each.to_json()) return {"total": total, "rows": reports}
def get(self, project_id: int): """ Get existing tests """ args = self.get_parser.parse_args(strict=False) reports = [] total, res = get(project_id, args, SecurityTestsDAST) for each in res: reports.append(each.to_json()) return {"total": total, "rows": reports}
def get(self, task_id, action): task = Task.query.filter_by(task_id=task_id).first() if action in ("suspend", "delete", "activate"): getattr(task, action)() if action == "results": args = self.get_parser.parse_args(strict=False) reports = [] total, res = get(task.project_id, args, Results, additional_filter={"task_id": task_id}) for each in res: reports.append(each.to_json()) return {"total": total, "rows": reports} return {"message": "Done", "code": 200}
def get(self, project_id: int): args = self._parser_get.parse_args(strict=False) total, reports = get(project_id, args, UIReport) res = [] for report in reports: results = UIResult.query.filter_by(report_uid=report.uid).all() totals = list(map(lambda x: x.total, results)) try: avg_page_load = sum(totals) / len(totals) except ZeroDivisionError: avg_page_load = 0 try: thresholds_missed = round( report.thresholds_failed / report.thresholds_total * 100, 2) except ZeroDivisionError: thresholds_missed = 0 data = dict(id=report.id, project_id=project_id, name=report.name, environment=report.environment, browser=report.browser, browser_version=report.browser_version, resolution="1380x749", url=report.base_url, end_time=report.stop_time, start_time=report.start_time, duration=report.duration, failures=thresholds_missed, total=10, thresholds_missed=thresholds_missed, avg_page_load=round(avg_page_load / 1000, 2), avg_step_duration=0.5, build_id=str(uuid4()), release_id=1) res.append(data) for each in res: each["start_time"] = each["start_time"].replace("T", " ").replace( "Z", "") return {"total": total, "rows": res}
def get(self, project_id: int): args = self._parser_get.parse_args(strict=False) if args.get("report_id"): report = APIReport.query.filter_by( project_id=project_id, id=args.get("report_id")).first().to_json() return report reports = [] total, res = get(project_id, args, APIReport) for each in res: each_json = each.to_json() each_json["start_time"] = each_json["start_time"].replace( "T", " ").split(".")[0] each_json["duration"] = int( each_json["duration"] if each_json["duration"] else 0) try: each_json["failure_rate"] = round( (each_json["failures"] / each_json["total"]) * 100, 2) except ZeroDivisionError: each_json["failure_rate"] = 0 reports.append(each_json) return {"total": total, "rows": reports}