# -*- coding: utf-8 -*-
# $Id: wuitestresult.py 92306 2021-11-09 23:57:32Z vboxsync $
"""
Test Manager WUI - Test Results.
"""
__copyright__ = \
"""
Copyright (C) 2012-2020 Oracle Corporation
This file is part of VirtualBox Open Source Edition (OSE), as
available from http://www.virtualbox.org. This file is free software;
you can redistribute it and/or modify it under the terms of the GNU
General Public License (GPL) as published by the Free Software
Foundation, in version 2 as it comes in the "COPYING" file of the
VirtualBox OSE distribution. VirtualBox OSE is distributed in the
hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
The contents of this file may alternatively be used under the terms
of the Common Development and Distribution License Version 1.0
(CDDL) only, as it comes in the "COPYING.CDDL" file of the
VirtualBox OSE distribution, in which case the provisions of the
CDDL are applicable instead of those of the GPL.
You may elect to license modified versions of this file under the
terms and conditions of either the GPL or the CDDL or both.
"""
__version__ = "$Revision: 92306 $"
# Python imports.
import datetime;
# Validation Kit imports.
from testmanager.webui.wuicontentbase import WuiContentBase, WuiListContentBase, WuiHtmlBase, WuiTmLink, WuiLinkBase, \
WuiSvnLink, WuiSvnLinkWithTooltip, WuiBuildLogLink, WuiRawHtml, \
WuiHtmlKeeper;
from testmanager.webui.wuimain import WuiMain;
from testmanager.webui.wuihlpform import WuiHlpForm;
from testmanager.webui.wuiadminfailurereason import WuiFailureReasonAddLink, WuiFailureReasonDetailsLink;
from testmanager.webui.wuitestresultfailure import WuiTestResultFailureDetailsLink;
from testmanager.core.failurereason import FailureReasonData, FailureReasonLogic;
from testmanager.core.report import ReportGraphModel, ReportModelBase;
from testmanager.core.testbox import TestBoxData;
from testmanager.core.testcase import TestCaseData;
from testmanager.core.testset import TestSetData;
from testmanager.core.testgroup import TestGroupData;
from testmanager.core.testresultfailures import TestResultFailureData;
from testmanager.core.build import BuildData;
from testmanager.core import db;
from testmanager import config;
from common import webutils, utils;
class WuiTestSetLink(WuiTmLink):
""" Test set link. """
def __init__(self, idTestSet, sName = WuiContentBase.ksShortDetailsLink, fBracketed = False):
WuiTmLink.__init__(self, sName, WuiMain.ksScriptName,
{ WuiMain.ksParamAction: WuiMain.ksActionTestResultDetails,
TestSetData.ksParam_idTestSet: idTestSet, }, fBracketed = fBracketed);
self.idTestSet = idTestSet;
class WuiTestResultsForSomethingLink(WuiTmLink):
""" Test results link for a grouping. """
def __init__(self, sGroupedBy, idGroupMember, sName = WuiContentBase.ksShortTestResultsLink,
dExtraParams = None, fBracketed = False):
dParams = dict(dExtraParams) if dExtraParams else dict();
dParams[WuiMain.ksParamAction] = sGroupedBy;
dParams[WuiMain.ksParamGroupMemberId] = idGroupMember;
WuiTmLink.__init__(self, sName, WuiMain.ksScriptName, dParams, fBracketed = fBracketed);
class WuiTestResultsForTestBoxLink(WuiTestResultsForSomethingLink):
""" Test results link for a given testbox. """
def __init__(self, idTestBox, sName = WuiContentBase.ksShortTestResultsLink, dExtraParams = None, fBracketed = False):
WuiTestResultsForSomethingLink.__init__(self, WuiMain.ksActionResultsGroupedByTestBox, idTestBox,
sName = sName, dExtraParams = dExtraParams, fBracketed = fBracketed);
class WuiTestResultsForTestCaseLink(WuiTestResultsForSomethingLink):
""" Test results link for a given testcase. """
def __init__(self, idTestCase, sName = WuiContentBase.ksShortTestResultsLink, dExtraParams = None, fBracketed = False):
WuiTestResultsForSomethingLink.__init__(self, WuiMain.ksActionResultsGroupedByTestCase, idTestCase,
sName = sName, dExtraParams = dExtraParams, fBracketed = fBracketed);
class WuiTestResultsForBuildRevLink(WuiTestResultsForSomethingLink):
""" Test results link for a given build revision. """
def __init__(self, iRevision, sName = WuiContentBase.ksShortTestResultsLink, dExtraParams = None, fBracketed = False):
WuiTestResultsForSomethingLink.__init__(self, WuiMain.ksActionResultsGroupedByBuildRev, iRevision,
sName = sName, dExtraParams = dExtraParams, fBracketed = fBracketed);
class WuiTestResult(WuiContentBase):
"""Display test case result"""
def __init__(self, fnDPrint = None, oDisp = None):
WuiContentBase.__init__(self, fnDPrint = fnDPrint, oDisp = oDisp);
# Cyclic import hacks.
from testmanager.webui.wuiadmin import WuiAdmin;
self.oWuiAdmin = WuiAdmin;
def _toHtml(self, oObject):
"""Translate some object to HTML."""
if isinstance(oObject, WuiHtmlBase):
return oObject.toHtml();
if db.isDbTimestamp(oObject):
return webutils.escapeElem(self.formatTsShort(oObject));
if db.isDbInterval(oObject):
return webutils.escapeElem(self.formatIntervalShort(oObject));
if utils.isString(oObject):
return webutils.escapeElem(oObject);
return webutils.escapeElem(str(oObject));
def _htmlTable(self, aoTableContent):
"""Generate HTML code for table"""
sHtml = u'
\n';
for aoSubRows in aoTableContent:
if not aoSubRows:
continue; # Can happen if there is no testsuit.
oCaption = aoSubRows[0];
sHtml += u' \n' \
u'
\n' \
u'
%s
\n' \
u'
\n' \
% (self._toHtml(oCaption),);
iRow = 0;
for aoRow in aoSubRows[1:]:
iRow += 1;
sHtml += u'
\n' % ('tmodd' if iRow & 1 else 'tmeven',);
if len(aoRow) == 1:
sHtml += u'
\n' \
% ( 'tmodd' if iRow & 1 else 'tmeven', iDepth,
self._formatEventTimestampHtml(oFile.tsCreated, oFile.tsCreated, oFile.idTestResultFile, oTestSet),
'\n'.join(oLink.toHtml() for oLink in aoLinks),);
iRow += 1;
# Done?
if oTestResult.tsElapsed is not None:
tsEvent = oTestResult.tsCreated + oTestResult.tsElapsed;
sHtml += '
\n' \
'
%s
\n' \
'
%s
\n' \
'
%s
\n' \
'
%s
\n' \
'
%s%s%s
\n' \
'
%s
\n' \
'
\n' \
% ( 'tmodd' if iRow & 1 else 'tmeven', iDepth, oTestResult.enmStatus, oTestResult.idTestResult,
self._formatEventTimestampHtml(tsEvent, tsEvent, oTestResult.idTestResult, oTestSet),
sElapsedGraph,
webutils.escapeElem(self.formatIntervalShort(oTestResult.tsElapsed)),
sDisplayName,
' id="failure-%u"' % (iFailure,) if oTestResult.isFailure() else '',
webutils.escapeElem(oTestResult.enmStatus), webutils.escapeElem(sErrCnt),
sChangeReason if cErrorsBelow < oTestResult.cErrors and oTestResult.oReason is None else '',
sResultGraph);
iRow += 1;
# Failure reason.
if oTestResult.oReason is not None:
sReasonText = '%s / %s' % ( oTestResult.oReason.oFailureReason.oCategory.sShort,
oTestResult.oReason.oFailureReason.sShort, );
sCommentHtml = '';
if oTestResult.oReason.sComment and oTestResult.oReason.sComment.strip():
sCommentHtml = ' ' + webutils.escapeElem(oTestResult.oReason.sComment.strip());
sCommentHtml = sCommentHtml.replace('\n', ' ');
sDetailedReason = ' %s' \
% ( webutils.encodeUrlParams({ self._oDisp.ksParamAction:
self._oDisp.ksActionTestResultFailureDetails,
TestResultFailureData.ksParam_idTestResult:
oTestResult.idTestResult,}),
WuiContentBase.ksShortDetailsLinkHtml,);
sHtml += '
\n' \
'
%s
\n' \
'
%s
\n' \
'
%s%s%s%s
\n' \
'
%s
\n' \
'
\n' \
% ( 'tmodd' if iRow & 1 else 'tmeven', iDepth,
webutils.escapeElem(self.formatTsShort(oTestResult.oReason.tsEffective)),
oTestResult.oReason.oAuthor.sUsername,
webutils.escapeElem(sReasonText), sDetailedReason, sChangeReason,
sCommentHtml,
'todo');
iRow += 1;
if oTestResult.isFailure():
iFailure += 1;
return (sHtml, iRow, iFailure);
def _generateMainReason(self, oTestResultTree, oTestSet):
"""
Generates the form for displaying and updating the main failure reason.
oTestResultTree is an instance TestResultDataEx.
oTestSet is an instance of TestSetData.
"""
_ = oTestSet;
sHtml = ' ';
if oTestResultTree.isFailure() or oTestResultTree.cErrors > 0:
sHtml += '
Failure Reason:
\n';
oData = oTestResultTree.oReason;
# We need the failure reasons for the combobox.
aoFailureReasons = FailureReasonLogic(self._oDisp.getDb()).fetchForCombo('Test Sheriff, you figure out why!');
assert aoFailureReasons;
# For now we'll use the standard form helper.
sFormActionUrl = '%s?%s=%s' % ( self._oDisp.ksScriptName, self._oDisp.ksParamAction,
WuiMain.ksActionTestResultFailureAddPost if oData is None else
WuiMain.ksActionTestResultFailureEditPost )
fReadOnly = not self._oDisp or self._oDisp.isReadOnlyUser();
oForm = WuiHlpForm('failure-reason', sFormActionUrl,
sOnSubmit = WuiHlpForm.ksOnSubmit_AddReturnToFieldWithCurrentUrl, fReadOnly = fReadOnly);
oForm.addTextHidden(TestResultFailureData.ksParam_idTestResult, oTestResultTree.idTestResult);
oForm.addTextHidden(TestResultFailureData.ksParam_idTestSet, oTestSet.idTestSet);
if oData is not None:
oForm.addComboBox(TestResultFailureData.ksParam_idFailureReason, oData.idFailureReason, 'Reason',
aoFailureReasons,
sPostHtml = u' ' + WuiFailureReasonDetailsLink(oData.idFailureReason).toHtml()
+ (u' ' + WuiFailureReasonAddLink('New', fBracketed = False).toHtml()
if not fReadOnly else u''));
oForm.addMultilineText(TestResultFailureData.ksParam_sComment, oData.sComment, 'Comment')
oForm.addNonText(u'%s (%s), %s'
% ( oData.oAuthor.sUsername, oData.oAuthor.sUsername,
self.formatTsShort(oData.tsEffective),),
'Sheriff',
sPostHtml = ' ' + WuiTestResultFailureDetailsLink(oData.idTestResult, "Show Details").toHtml() )
oForm.addTextHidden(TestResultFailureData.ksParam_tsEffective, oData.tsEffective);
oForm.addTextHidden(TestResultFailureData.ksParam_tsExpire, oData.tsExpire);
oForm.addTextHidden(TestResultFailureData.ksParam_uidAuthor, oData.uidAuthor);
oForm.addSubmit('Change Reason');
else:
oForm.addComboBox(TestResultFailureData.ksParam_idFailureReason, -1, 'Reason', aoFailureReasons,
sPostHtml = ' ' + WuiFailureReasonAddLink('New').toHtml() if not fReadOnly else '');
oForm.addMultilineText(TestResultFailureData.ksParam_sComment, '', 'Comment');
oForm.addTextHidden(TestResultFailureData.ksParam_tsEffective, '');
oForm.addTextHidden(TestResultFailureData.ksParam_tsExpire, '');
oForm.addTextHidden(TestResultFailureData.ksParam_uidAuthor, '');
oForm.addSubmit('Add Reason');
sHtml += oForm.finalize();
return sHtml;
def showTestCaseResultDetails(self, # pylint: disable=too-many-locals,too-many-statements
oTestResultTree,
oTestSet,
oBuildEx,
oValidationKitEx,
oTestBox,
oTestGroup,
oTestCaseEx,
oTestVarEx):
"""Show detailed result"""
def getTcDepsHtmlList(aoTestCaseData):
"""Get HTML
list of Test Case name items"""
if aoTestCaseData:
sTmp = '