diff --git a/mod_test/controllers.py b/mod_test/controllers.py index 82eb98d3..223b70c8 100644 --- a/mod_test/controllers.py +++ b/mod_test/controllers.py @@ -8,6 +8,8 @@ url_for) from sqlalchemy import and_, func from sqlalchemy.sql import label +from sqlalchemy import func + from decorators import template_renderer from exceptions import TestNotFoundException @@ -447,3 +449,44 @@ def stop_test(test_id): g.db.commit() g.log.info(f"test with id: {test_id} stopped") return redirect(url_for('.by_id', test_id=test.id)) + + +@mod_regression.route('/progress', methods=['GET']) +def progress(): + """ + Get regression test progress stats + Optional: filter by run or sample + Default: global progress + """ + run = request.args.get('run') + + total = RegressionTest.query.filter(RegressionTest.active == True).count() + done = 0 + try: + if run: + if hasattr(TestResultFile, 'run_uuid'): + done = TestResultFile.query.filter( + TestResultFile.run_uuid == run, + TestResultFile.got.isnot(None) + ).count() + elif hasattr(TestResultFile, 'run_id'): + done = TestResultFile.query.filter( + TestResultFile.run_id == run, + TestResultFile.got.isnot(None) + ).count() + else: + done = TestResultFile.query.filter( + TestResultFile.got.isnot(None) + ).distinct(TestResultFile.regression_test_id).count() + + except Exception: + done = TestResultFile.query.filter(TestResultFile.got.isnot(None)).count() + + pct = 100 if total == 0 else int((done / total) * 100) + + return jsonify({ + 'status': 'success', + 'total': total, + 'completed': done, + 'percent': pct + }) \ No newline at end of file diff --git a/templates/test/by_id.html b/templates/test/by_id.html index 8a92167d..96116d59 100644 --- a/templates/test/by_id.html +++ b/templates/test/by_id.html @@ -52,6 +52,15 @@