Skip to content
Open
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
15 changes: 12 additions & 3 deletions mod_test/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from flask import (Blueprint, Response, abort, g, jsonify, redirect, request,
url_for)
from sqlalchemy import and_, select
from sqlalchemy.orm import joinedload, selectinload

from decorators import template_renderer
from exceptions import TestNotFoundException
Expand Down Expand Up @@ -61,13 +62,21 @@ def get_test_results(test) -> List[Dict[str, Any]]:
:type test: Test
"""
populated_categories = select(regressionTestLinkTable.c.category_id)
categories = Category.query.filter(Category.id.in_(populated_categories)).order_by(Category.name.asc()).all()
categories = Category.query.options(
selectinload(Category.regression_tests)
).filter(
Category.id.in_(populated_categories)
).order_by(Category.name.asc()).all()
results = [{
'category': category,
'tests': [{
'test': rt,
'result': next((r for r in test.results if r.regression_test_id == rt.id), None),
'files': TestResultFile.query.filter(
'files': TestResultFile.query.options(
joinedload(TestResultFile.regression_test_output).selectinload(
RegressionTestOutput.multiple_files
)
).filter(
and_(TestResultFile.test_id == test.id, TestResultFile.regression_test_id == rt.id)
).all()
} for rt in category.regression_tests if rt.id in test.get_customized_regressiontests()]
Expand All @@ -88,7 +97,7 @@ def get_test_results(test) -> List[Dict[str, Any]]:
test_error = True
if len(category_test['files']) > 0:
for result_file in category_test['files']:
if result_file.got is not None and result.exit_code == 0:
if result_file.got is not None and (result is None or result.exit_code == result.expected_rc):
file_error = True
for file in result_file.regression_test_output.multiple_files:
if file.file_hashes == result_file.got:
Expand Down
5 changes: 3 additions & 2 deletions tests/test_test/test_controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,10 @@ def test_ccextractor_version_not_found(self):
self.assertEqual(response.status_code, 404)
self.assert_template_used('test/test_not_found.html')

@mock.patch('mod_test.controllers.selectinload')
@mock.patch('mod_test.controllers.GeneralData')
@mock.patch('mod_test.controllers.Category')
def test_data_for_test(self, mock_category, mock_gen_data):
def test_data_for_test(self, mock_category, mock_gen_data, mock_selectinload):
"""Test get_data_for_test method."""
from mod_test.controllers import get_data_for_test

Expand All @@ -144,7 +145,7 @@ def test_data_for_test(self, mock_category, mock_gen_data):
self.assertIsInstance(result, dict)
self.assertIn('avg_minutes', result)
self.assertEqual(result['avg_minutes'], 6) # (300 + 60) / 60 = 6 minutes
mock_category.query.filter.assert_called_once()
mock_category.query.options.assert_called_once()
self.assertEqual(mock_gen_data.query.filter.call_count, 2)

@mock.patch('mod_test.controllers.Test')
Expand Down
Loading