cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# -*- coding: utf-8 -*-
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# $Id$
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# pylint: disable=C0302
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncTest Manager - Test Case.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync__copyright__ = \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncCopyright (C) 2012-2014 Oracle Corporation
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncThis file is part of VirtualBox Open Source Edition (OSE), as
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncavailable from http://www.virtualbox.org. This file is free software;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncyou can redistribute it and/or modify it under the terms of the GNU
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncGeneral Public License (GPL) as published by the Free Software
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncFoundation, in version 2 as it comes in the "COPYING" file of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncVirtualBox OSE distribution. VirtualBox OSE is distributed in the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsynchope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncThe contents of this file may alternatively be used under the terms
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncof the Common Development and Distribution License Version 1.0
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync(CDDL) only, as it comes in the "COPYING.CDDL" file of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncVirtualBox OSE distribution, in which case the provisions of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncCDDL are applicable instead of those of the GPL.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncYou may elect to license modified versions of this file under the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncterms and conditions of either the GPL or the CDDL or both.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync__version__ = "$Revision$"
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# Standard python imports.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncimport copy;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncimport unittest;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# Validation Kit imports.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncfrom common import utils;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncfrom testmanager.core.base import ModelDataBase, ModelDataBaseTestCase, ModelLogicBase, TMExceptionBase, \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ChangeLogEntry, AttributeChangeEntry;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncfrom testmanager.core.globalresource import GlobalResourceData;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncfrom testmanager.core.useraccount import UserAccountLogic;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass TestCaseGlobalRsrcDepData(ModelDataBase):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Test case dependency on a global resource - data.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_idTestCase = 'TestCaseDependency_idTestCase';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_idGlobalRsrc = 'TestCaseDependency_idGlobalRsrc';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_tsEffective = 'TestCaseDependency_tsEffective';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_tsExpire = 'TestCaseDependency_tsExpire';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_uidAuthor = 'TestCaseDependency_uidAuthor';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync kasAllowNullAttributes = ['idTestSet', ];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def __init__(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ModelDataBase.__init__(self);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Initialize with defaults.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # See the database for explanations of each of these fields.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idTestCase = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idGlobalRsrc = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.tsEffective = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.tsExpire = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.uidAuthor = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def initFromDbRow(self, aoRow):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Reinitialize from a SELECT * FROM TestCaseDeps row.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if aoRow is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise TMExceptionBase('Test case not found.');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idTestCase = aoRow[0];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idGlobalRsrc = aoRow[1];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.tsEffective = aoRow[2];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.tsExpire = aoRow[3];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.uidAuthor = aoRow[4];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass TestCaseGlobalRsrcDepLogic(ModelLogicBase):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Test case dependency on a global resources - logic.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getTestCaseDeps(self, idTestCase, tsNow = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns an array of (TestCaseGlobalRsrcDepData, GlobalResourceData)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync with the global resources required by idTestCase.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns empty array if none found. Raises exception on database error.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Note! Maybe a bit overkill...
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ## @todo This code isn't entirely kosher... Should use a DataEx with a oGlobalRsrc = GlobalResourceData().
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if tsNow is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT *\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestCaseGlobalRsrcDeps, GlobalResources\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE TestCaseGlobalRsrcDeps.idTestCase = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND TestCaseGlobalRsrcDeps.tsExpire > %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND TestCaseGlobalRsrcDeps.tsEffective <= %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND GlobalResources.idGlobalRsrc = TestCaseGlobalRsrcDeps.idGlobalRsrc\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND GlobalResources.tsExpire > %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND GlobalResources.tsEffective <= %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (idTestCase, tsNow, tsNow, tsNow, tsNow) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT *\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestCaseGlobalRsrcDeps, GlobalResources\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE TestCaseGlobalRsrcDeps.idTestCase = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND GlobalResources.idGlobalRsrc = TestCaseGlobalRsrcDeps.idGlobalRsrc\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND TestCaseGlobalRsrcDeps.tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND GlobalResources.tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (idTestCase,))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aaoRows = self._oDb.fetchAll();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRet = []
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for aoRow in aaoRows:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oItem = [TestCaseDependencyData().initFromDbRow(aoRow),
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync GlobalResourceData().initFromDbRow(aoRow[5:])];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRet.append(oItem);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return aoRet
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getTestCaseDepsIds(self, idTestCase, tsNow = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns an array of global resources that idTestCase require.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns empty array if none found. Raises exception on database error.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if tsNow is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT idGlobalRsrc\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestCaseGlobalRsrcDeps\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE TestCaseGlobalRsrcDeps.idTestCase = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND TestCaseGlobalRsrcDeps.tsExpire > %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND TestCaseGlobalRsrcDeps.tsEffective <= %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (idTestCase, tsNow, tsNow, ) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT idGlobalRsrc\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestCaseGlobalRsrcDeps\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE TestCaseGlobalRsrcDeps.idTestCase = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND TestCaseGlobalRsrcDeps.tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (idTestCase,))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aidGlobalRsrcs = []
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for aoRow in self._oDb.fetchAll():
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aidGlobalRsrcs.append(aoRow[0]);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return aidGlobalRsrcs;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getDepGlobalResourceData(self, idTestCase, tsNow = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns an array of objects of type GlobalResourceData on which the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync specified test case depends on.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if tsNow is None :
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT GlobalResources.*\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestCaseGlobalRsrcDeps, GlobalResources\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE TestCaseGlobalRsrcDeps.idTestCase = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND GlobalResources.idGlobalRsrc = TestCaseGlobalRsrcDeps.idGlobalRsrc\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND TestCaseGlobalRsrcDeps.tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND GlobalResources.tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY GlobalResources.idGlobalRsrc\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (idTestCase,))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT GlobalResources.*\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestCaseGlobalRsrcDeps, GlobalResources\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE TestCaseGlobalRsrcDeps.idTestCase = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND GlobalResources.idGlobalRsrc = TestCaseGlobalRsrcDeps.idGlobalRsrc\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND TestCaseGlobalRsrcDeps.tsExpire > %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND TestCaseGlobalRsrcDeps.tsExpire <= %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND GlobalResources.tsExpire > %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND GlobalResources.tsEffective <= %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY GlobalResources.idGlobalRsrc\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (idTestCase, tsNow, tsNow, tsNow, tsNow));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aaoRows = self._oDb.fetchAll()
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRet = []
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for aoRow in aaoRows:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRet.append(GlobalResourceData().initFromDbRow(aoRow));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return aoRet
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass TestCaseDependencyData(ModelDataBase):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Test case dependency data
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_idTestCase = 'TestCaseDependency_idTestCase';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_idTestCasePreReq = 'TestCaseDependency_idTestCasePreReq';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_tsEffective = 'TestCaseDependency_tsEffective';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_tsExpire = 'TestCaseDependency_tsExpire';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_uidAuthor = 'TestCaseDependency_uidAuthor';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def __init__(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ModelDataBase.__init__(self);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Initialize with defaults.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # See the database for explanations of each of these fields.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idTestCase = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idTestCasePreReq = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.tsEffective = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.tsExpire = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.uidAuthor = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def initFromDbRow(self, aoRow):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Reinitialize from a SELECT * FROM TestCaseDeps row.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if aoRow is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise TMExceptionBase('Test case not found.');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idTestCase = aoRow[0];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idTestCasePreReq = aoRow[1];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.tsEffective = aoRow[2];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.tsExpire = aoRow[3];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.uidAuthor = aoRow[4];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def initFromParams(self, oDisp, fStrict=True):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Initialize the object from parameters.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync The input is not validated at all, except that all parameters must be
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync present when fStrict is True.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Note! Returns parameter NULL values, not database ones.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.convertToParamNull();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fn = oDisp.getStringParam; # Shorter...
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idTestCase = fn(self.ksParam_idTestCase, None, None if fStrict else self.idTestCase);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idTestCasePreReq = fn(self.ksParam_idTestCasePreReq, None, None if fStrict else self.idTestCasePreReq);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.tsEffective = fn(self.ksParam_tsEffective, None, None if fStrict else self.tsEffective);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.tsExpire = fn(self.ksParam_tsExpire, None, None if fStrict else self.tsExpire);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.uidAuthor = fn(self.ksParam_uidAuthor, None, None if fStrict else self.uidAuthor);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def validateAndConvert(self, oDb = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Validates the input and converts valid fields to their right type.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns a dictionary with per field reports, only invalid fields will
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync be returned, so an empty dictionary means that the data is valid.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync The dictionary keys are ksParam_*.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync dErrors = dict()
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idTestCase = self._validateInt( dErrors, self.ksParam_idTestCase, self.idTestCase);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idTestCasePreReq = self._validateInt( dErrors, self.ksParam_idTestCasePreReq, self.idTestCasePreReq);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.tsEffective = self._validateTs( dErrors, self.ksParam_tsEffective, self.tsEffective);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.tsExpire = self._validateTs( dErrors, self.ksParam_tsExpire, self.tsExpire);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.uidAuthor = self._validateInt( dErrors, self.ksParam_uidAuthor, self.uidAuthor);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync _ = oDb;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return dErrors
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def convertFromParamNull(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Converts from parameter NULL values to database NULL values (None).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.idTestCase in [-1, '']: self.idTestCase = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.idTestCasePreReq in [-1, '']: self.idTestCasePreReq = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.tsEffective == '': self.tsEffective = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.tsExpire == '': self.tsExpire = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.uidAuthor in [-1, '']: self.uidAuthor = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def convertToParamNull(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Converts from database NULL values (None) to special values we can
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync pass thru parameters list.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.idTestCase is None: self.idTestCase = -1;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.idTestCasePreReq is None: self.idTestCasePreReq = -1;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.tsEffective is None: self.tsEffective = '';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.tsExpire is None: self.tsExpire = '';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.uidAuthor is None: self.uidAuthor = -1;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def isEqual(self, oOther):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """ Compares two instances. """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self.idTestCase == oOther.idTestCase \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and self.idTestCasePreReq == oOther.idTestCasePreReq \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and self.tsEffective == oOther.tsEffective \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and self.tsExpire == oOther.tsExpire \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and self.uidAuthor == oOther.uidAuthor;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getTestCasePreReqIds(self, aTestCaseDependencyData):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Get list of Test Case IDs which current
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Test Case depends on
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if len(aTestCaseDependencyData) == 0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return []
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRet = []
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for oTestCaseDependencyData in aTestCaseDependencyData:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRet.append(oTestCaseDependencyData.idTestCasePreReq)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return aoRet
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass TestCaseDependencyLogic(ModelLogicBase):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """Test case dependency management logic"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getTestCaseDeps(self, idTestCase, tsEffective = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns an array of TestCaseDependencyData with the prerequisites of
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync idTestCase.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns empty array if none found. Raises exception on database error.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if tsEffective is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT *\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestCaseDeps\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idTestCase = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsExpire > %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsEffective <= %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (idTestCase, tsEffective, tsEffective, ) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT *\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestCaseDeps\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idTestCase = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (idTestCase, ) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aaoRows = self._oDb.fetchAll();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRet = [];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for aoRow in aaoRows:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRet.append(TestCaseDependencyData().initFromDbRow(aoRow));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return aoRet
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getTestCaseDepsIds(self, idTestCase, tsNow = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns an array of test case IDs of the prerequisites of idTestCase.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns empty array if none found. Raises exception on database error.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if tsNow is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT idTestCase\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestCaseDeps\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idTestCase = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsExpire > %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsEffective <= %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (idTestCase, tsNow, tsNow, ) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT idTestCase\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestCaseDeps\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idTestCase = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (idTestCase, ) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aidPreReqs = [];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for aoRow in self._oDb.fetchAll():
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aidPreReqs.append(aoRow[0]);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return aidPreReqs;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getDepTestCaseData(self, idTestCase, tsNow = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns an array of objects of type TestCaseData2 on which
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync specified test case depends on
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if tsNow is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT TestCases.*\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestCases, TestCaseDeps\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE TestCaseDeps.idTestCase = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND TestCaseDeps.idTestCasePreReq = TestCases.idTestCase\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND TestCaseDeps.tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND TestCases.tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY TestCases.idTestCase\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (idTestCase, ) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT TestCases.*\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestCases, TestCaseDeps\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE TestCaseDeps.idTestCase = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND TestCaseDeps.idTestCasePreReq = TestCases.idTestCase\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND TestCaseDeps.tsExpire > %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND TestCaseDeps.tsEffective <= %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND TestCases.tsExpire > %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND TestCases.tsEffective <= %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY TestCases.idTestCase\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (idTestCase, tsNow, tsNow, tsNow, tsNow, ) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aaoRows = self._oDb.fetchAll()
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRet = []
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for aoRow in aaoRows:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRet.append(TestCaseData().initFromDbRow(aoRow));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return aoRet
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getApplicableDepTestCaseData(self, idTestCase):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns an array of objects of type TestCaseData on which
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync specified test case might depends on (all test
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cases except the specified one and those testcases which are
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync depend on idTestCase)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT *\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestCases\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idTestCase <> %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND idTestCase NOT IN (SELECT idTestCase\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' FROM TestCaseDeps\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' WHERE idTestCasePreReq=%s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsExpire = \'infinity\'::TIMESTAMP)\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (idTestCase, idTestCase) )
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aaoRows = self._oDb.fetchAll()
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRet = []
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for aoRow in aaoRows:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRet.append(TestCaseData().initFromDbRow(aoRow));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return aoRet
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass TestCaseData(ModelDataBase):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Test case data
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksIdAttr = 'idTestCase';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksIdGenAttr = 'idGenTestCase';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_idTestCase = 'TestCase_idTestCase'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_tsEffective = 'TestCase_tsEffective'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_tsExpire = 'TestCase_tsExpire'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_uidAuthor = 'TestCase_uidAuthor'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_idGenTestCase = 'TestCase_idGenTestCase'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_sName = 'TestCase_sName'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_sDescription = 'TestCase_sDescription'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_fEnabled = 'TestCase_fEnabled'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_cSecTimeout = 'TestCase_cSecTimeout'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_sTestBoxReqExpr = 'TestCase_sTestBoxReqExpr';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_sBuildReqExpr = 'TestCase_sBuildReqExpr';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_sBaseCmd = 'TestCase_sBaseCmd'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_sValidationKitZips = 'TestCase_sValidationKitZips'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync kasAllowNullAttributes = [ 'idTestCase', 'tsEffective', 'tsExpire', 'uidAuthor', 'idGenTestCase', 'sDescription',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sTestBoxReqExpr', 'sBuildReqExpr', 'sValidationKitZips', ];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def __init__(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ModelDataBase.__init__(self);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Initialize with defaults.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # See the database for explanations of each of these fields.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idTestCase = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.tsEffective = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.tsExpire = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.uidAuthor = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idGenTestCase = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sName = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sDescription = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.fEnabled = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.cSecTimeout = 10; # Init with minimum timeout value
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sTestBoxReqExpr = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sBuildReqExpr = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sBaseCmd = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sValidationKitZips = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def initFromDbRow(self, aoRow):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Reinitialize from a SELECT * FROM TestCases row.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns self. Raises exception if no row.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if aoRow is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise TMExceptionBase('Test case not found.');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idTestCase = aoRow[0];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.tsEffective = aoRow[1];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.tsExpire = aoRow[2];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.uidAuthor = aoRow[3];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idGenTestCase = aoRow[4];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sName = aoRow[5];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sDescription = aoRow[6];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.fEnabled = aoRow[7];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.cSecTimeout = aoRow[8];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sTestBoxReqExpr = aoRow[9];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sBuildReqExpr = aoRow[10];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sBaseCmd = aoRow[11];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sValidationKitZips = aoRow[12];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def initFromDbWithId(self, oDb, idTestCase, tsNow = None, sPeriodBack = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Initialize the object from the database.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oDb.execute(self.formatSimpleNowAndPeriodQuery(oDb,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'SELECT *\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestCases\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idTestCase = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , ( idTestCase,), tsNow, sPeriodBack));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRow = oDb.fetchOne()
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if aoRow is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise TMExceptionBase('idTestCase=%s not found (tsNow=%s sPeriodBack=%s)' % (idTestCase, tsNow, sPeriodBack,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self.initFromDbRow(aoRow);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def initFromDbWithGenId(self, oDb, idGenTestCase, tsNow = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Initialize the object from the database.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync _ = tsNow; # For relevant for the TestCaseDataEx version only.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oDb.execute('SELECT *\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestCases\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idGenTestCase = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (idGenTestCase, ) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self.initFromDbRow(oDb.fetchOne());
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def _validateAndConvertAttribute(self, sAttr, sParam, oValue, aoNilValues, fAllowNull, oDb):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sAttr == 'cSecTimeout' and oValue not in aoNilValues: # Allow human readable interval formats.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return utils.parseIntervalSeconds(oValue);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync (oValue, sError) = ModelDataBase._validateAndConvertAttribute(self, sAttr, sParam, oValue, aoNilValues, fAllowNull, oDb);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sError is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sAttr == 'sTestBoxReqExpr':
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sError = TestCaseData.validateTestBoxReqExpr(oValue);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif sAttr == 'sBuildReqExpr':
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sError = TestCaseData.validateBuildReqExpr(oValue);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif sAttr == 'sBaseCmd':
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync _, sError = TestCaseData.validateStr(oValue, fAllowUnicodeSymbols=False);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return (oValue, sError);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Misc.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def needValidationKitBit(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Predicate method for checking whether a validation kit build is required.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self.sValidationKitZips is None \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync or self.sValidationKitZips.find('@VALIDATIONKIT_ZIP@') >= 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def matchesTestBoxProps(self, oTestBoxData):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Checks if the all of the testbox related test requirements matches the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync given testbox.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True or False according to the expression, None on exception or
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync non-boolean expression result.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return TestCaseData.matchesTestBoxPropsEx(oTestBoxData, self.sTestBoxReqExpr);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def matchesBuildProps(self, oBuildDataEx):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Checks if the all of the build related test requirements matches the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync given build.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True or False according to the expression, None on exception or
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync non-boolean expression result.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return TestCaseData.matchesBuildPropsEx(oBuildDataEx, self.sBuildReqExpr);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Expression validation code shared with TestCaseArgsDataEx.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync @staticmethod
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def _safelyEvalExpr(sExpr, dLocals, fMayRaiseXcpt = False):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Safely evaluate requirment expression given a set of locals.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True or False according to the expression. If the expression
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync causes an exception to be raised or does not return a boolean result,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync None will be returned.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sExpr is None or sExpr == '':
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync dGlobals = \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync {
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync '__builtins__': None,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'long': long,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'int': int,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'bool': bool,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'True': True,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'False': False,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'len': len,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'isinstance': isinstance,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'type': type,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'dict': dict,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'dir': dir,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'list': list,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'versionCompare': utils.versionCompare,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync };
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = eval(sExpr, dGlobals, dLocals);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fMayRaiseXcpt:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if not isinstance(fRc, bool):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fMayRaiseXcpt:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise Exception('not a boolean result: "%s" - %s' % (fRc, type(fRc)) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync @staticmethod
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def _safelyValidateReqExpr(sExpr, adLocals):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Validates a requirement expression using the given sets of locals,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync returning None on success and an error string on failure.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for dLocals in adLocals:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync TestCaseData._safelyEvalExpr(sExpr, dLocals, True);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except Exception as oXcpt:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return str(oXcpt);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync @staticmethod
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def validateTestBoxReqExpr(sExpr):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Validates a testbox expression, returning None on success and an error
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync string on failure.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync adTestBoxes = \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync [
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync {
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sOs': 'win',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sOsVersion': '3.1',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sCpuVendor': 'VirtualBox',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sCpuArch': 'x86',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'cCpus': 1,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'fCpuHwVirt': False,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'fCpuNestedPaging': False,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'fCpu64BitGuest': False,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'fChipsetIoMmu': False,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'cMbMemory': 985034,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'cMbScratch': 1234089,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'iTestBoxScriptRev': 1,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sName': 'emanon',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'uuidSystem': '8FF81BE5-3901-4AB1-8A65-B48D511C0321',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync },
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync {
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sOs': 'linux',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sOsVersion': '3.1',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sCpuVendor': 'VirtualBox',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sCpuArch': 'amd64',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'cCpus': 8191,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'fCpuHwVirt': True,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'fCpuNestedPaging': True,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'fCpu64BitGuest': True,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'fChipsetIoMmu': True,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'cMbMemory': 9999999999,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'cMbScratch': 9999999999999,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'iTestBoxScriptRev': 9999999,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sName': 'emanon',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'uuidSystem': '00000000-0000-0000-0000-000000000000',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync },
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return TestCaseData._safelyValidateReqExpr(sExpr, adTestBoxes);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync @staticmethod
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def matchesTestBoxPropsEx(oTestBoxData, sExpr):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """ Worker for TestCaseData.matchesTestBoxProps and TestCaseArgsDataEx.matchesTestBoxProps. """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sExpr is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync dLocals = \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync {
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sOs': oTestBoxData.sOs,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sOsVersion': oTestBoxData.sOsVersion,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sCpuVendor': oTestBoxData.sCpuVendor,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sCpuArch': oTestBoxData.sCpuArch,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'cCpus': oTestBoxData.cCpus,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'fCpuHwVirt': oTestBoxData.fCpuHwVirt,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'fCpuNestedPaging': oTestBoxData.fCpuNestedPaging,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'fCpu64BitGuest': oTestBoxData.fCpu64BitGuest,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'fChipsetIoMmu': oTestBoxData.fChipsetIoMmu,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'cMbMemory': oTestBoxData.cMbMemory,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'cMbScratch': oTestBoxData.cMbScratch,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'iTestBoxScriptRev': oTestBoxData.iTestBoxScriptRev,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'iPythonHexVersion': oTestBoxData.iPythonHexVersion,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sName': oTestBoxData.sName,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'uuidSystem': oTestBoxData.uuidSystem,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync };
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return TestCaseData._safelyEvalExpr(sExpr, dLocals);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync @staticmethod
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def validateBuildReqExpr(sExpr):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Validates a testbox expression, returning None on success and an error
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync string on failure.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync adBuilds = \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync [
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync {
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sProduct': 'VirtualBox',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sBranch': 'trunk',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sType': 'release',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'asOsArches': ['win.amd64', 'win.x86'],
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sVersion': '1.0',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'iRevision': 1234,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'uidAuthor': None,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'idBuild': 953,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync },
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync {
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sProduct': 'VirtualBox',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sBranch': 'VBox-4.1',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sType': 'release',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'asOsArches': ['linux.x86',],
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sVersion': '4.2.15',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'iRevision': 89876,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'uidAuthor': None,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'idBuild': 945689,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync },
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync {
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sProduct': 'VirtualBox',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sBranch': 'VBox-4.1',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sType': 'strict',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'asOsArches': ['solaris.x86', 'solaris.amd64',],
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sVersion': '4.3.0_RC3',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'iRevision': 97939,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'uidAuthor': 33,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'idBuild': 9456893,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync },
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return TestCaseData._safelyValidateReqExpr(sExpr, adBuilds);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync @staticmethod
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def matchesBuildPropsEx(oBuildDataEx, sExpr):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Checks if the all of the build related test requirements matches the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync given build.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sExpr is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync dLocals = \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync {
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sProduct': oBuildDataEx.oCat.sProduct,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sBranch': oBuildDataEx.oCat.sBranch,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sType': oBuildDataEx.oCat.sType,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'asOsArches': oBuildDataEx.oCat.asOsArches,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'sVersion': oBuildDataEx.sVersion,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'iRevision': oBuildDataEx.iRevision,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'uidAuthor': oBuildDataEx.uidAuthor,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'idBuild': oBuildDataEx.idBuild,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync };
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return TestCaseData._safelyEvalExpr(sExpr, dLocals);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass TestCaseDataEx(TestCaseData):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Test case data.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_aoTestCaseArgs = 'TestCase_aoTestCaseArgs';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_aoDepTestCases = 'TestCase_aoDepTestCases';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_aoDepGlobalResources = 'TestCase_aoDepGlobalResources';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Use [] instead of None.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync kasAltArrayNull = [ 'aoTestCaseArgs', 'aoDepTestCases', 'aoDepGlobalResources' ];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def __init__(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync TestCaseData.__init__(self);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # List of objects of type TestCaseData (or TestCaseDataEx, we don't
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # care) on which current Test Case depends.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.aoDepTestCases = [];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # List of objects of type GlobalResourceData on which current Test Case depends.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.aoDepGlobalResources = [];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # List of objects of type TestCaseArgsData.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.aoTestCaseArgs = [];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def _initExtraMembersFromDb(self, oDb, tsNow = None, sPeriodBack = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Worker shared by the initFromDb* methods.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns self. Raises exception if no row or database error.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync _ = sPeriodBack; ## @todo sPeriodBack
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync from testmanager.core.testcaseargs import TestCaseArgsLogic;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.aoDepTestCases = TestCaseDependencyLogic(oDb).getDepTestCaseData(self.idTestCase, tsNow);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.aoDepGlobalResources = TestCaseGlobalRsrcDepLogic(oDb).getDepGlobalResourceData(self.idTestCase, tsNow);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.aoTestCaseArgs = TestCaseArgsLogic(oDb).getTestCaseArgs(self.idTestCase, tsNow);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Note! The above arrays are sorted by their relvant IDs for fetchForChangeLog's sake.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def initFromDbRowEx(self, aoRow, oDb, tsNow = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Reinitialize from a SELECT * FROM TestCases row. Will query the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync necessary additional data from oDb using tsNow.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns self. Raises exception if no row or database error.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync TestCaseData.initFromDbRow(self, aoRow);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self._initExtraMembersFromDb(oDb, tsNow);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def initFromDbWithId(self, oDb, idTestCase, tsNow = None, sPeriodBack = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Initialize the object from the database.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync TestCaseData.initFromDbWithId(self, oDb, idTestCase, tsNow, sPeriodBack);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self._initExtraMembersFromDb(oDb, tsNow, sPeriodBack);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def initFromDbWithGenId(self, oDb, idGenTestCase, tsNow = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Initialize the object from the database.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync TestCaseData.initFromDbWithGenId(self, oDb, idGenTestCase);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if tsNow == None and not oDb.isTsInfinity(self.tsExpire):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync tsNow = self.tsEffective;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self._initExtraMembersFromDb(oDb, tsNow);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getAttributeParamNullValues(self, sAttr):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sAttr in ['aoDepTestCases', 'aoDepGlobalResources', 'aoTestCaseArgs']:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return [[], ''];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return TestCaseData.getAttributeParamNullValues(self, sAttr);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def convertParamToAttribute(self, sAttr, sParam, oValue, oDisp, fStrict):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """For dealing with the arrays."""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sAttr not in ['aoDepTestCases', 'aoDepGlobalResources', 'aoTestCaseArgs']:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return TestCaseData.convertParamToAttribute(self, sAttr, sParam, oValue, oDisp, fStrict);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoNewValues = [];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sAttr == 'aoDepTestCases':
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for idTestCase in oDisp.getListOfIntParams(sParam, 1, 0x7ffffffe, []):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oDep = TestCaseData();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oDep.idTestCase = str(idTestCase);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoNewValues.append(oDep);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif sAttr == 'aoDepGlobalResources':
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for idGlobalRsrc in oDisp.getListOfIntParams(sParam, 1, 0x7ffffffe, []):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oGlobalRsrc = GlobalResourceData();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oGlobalRsrc.idGlobalRsrc = str(idGlobalRsrc);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoNewValues.append(oGlobalRsrc);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif sAttr == 'aoTestCaseArgs':
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync from testmanager.core.testcaseargs import TestCaseArgsData;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for sArgKey in oDisp.getStringParam(TestCaseDataEx.ksParam_aoTestCaseArgs, sDefault = '').split(','):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oDispWrapper = self.DispWrapper(oDisp, '%s[%s][%%s]' % (TestCaseDataEx.ksParam_aoTestCaseArgs, sArgKey,))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoNewValues.append(TestCaseArgsData().initFromParams(oDispWrapper, fStrict = False));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return aoNewValues;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def _validateAndConvertAttribute(self, sAttr, sParam, oValue, aoNilValues, fAllowNull, oDb): # pylint: disable=R0914
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Validate special arrays and requirement expressions.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync For the two dependency arrays we have to supply missing bits by
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync looking them up in the database. In the argument variation case we
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync need to validate each item.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sAttr not in ['aoDepTestCases', 'aoDepGlobalResources', 'aoTestCaseArgs']:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return TestCaseData._validateAndConvertAttribute(self, sAttr, sParam, oValue, aoNilValues, fAllowNull, oDb);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync asErrors = [];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoNewValues = [];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sAttr == 'aoDepTestCases':
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for oTestCase in self.aoDepTestCases:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if utils.isString(oTestCase.idTestCase): # Stored as string convertParamToAttribute.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oTestCase = copy.copy(oTestCase);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oTestCase.idTestCase = int(oTestCase.idTestCase);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oTestCase.initFromDbWithId(oDb, oTestCase.idTestCase);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except Exception, oXcpt:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync asErrors.append('Test case dependency #%s: %s' % (oTestCase.idTestCase, oXcpt));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoNewValues.append(oTestCase);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif sAttr == 'aoDepGlobalResources':
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for oGlobalRsrc in self.aoDepGlobalResources:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if utils.isString(oGlobalRsrc.idGlobalRsrc): # Stored as string convertParamToAttribute.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oGlobalRsrc = copy.copy(oGlobalRsrc);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oGlobalRsrc.idTestCase = int(oGlobalRsrc.idGlobalRsrc);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oGlobalRsrc.initFromDbWithId(oDb, oGlobalRsrc.idGlobalRsrc);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except Exception, oXcpt:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync asErrors.append('Resource dependency #%s: %s' % (oGlobalRsrc.idGlobalRsrc, oXcpt));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoNewValues.append(oGlobalRsrc);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync assert sAttr == 'aoTestCaseArgs';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.aoTestCaseArgs is None or len(self.aoTestCaseArgs) == 0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return (None, 'The testcase requires at least one argument variation to be valid.');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Note! We'll be returning an error dictionary instead of an string here.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync dErrors = {};
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for iVar in range(len(self.aoTestCaseArgs)):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oVar = copy.copy(self.aoTestCaseArgs[iVar]);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oVar.idTestCase = self.idTestCase;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync dCurErrors = oVar.validateAndConvert(oDb);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if len(dCurErrors) == 0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync pass; ## @todo figure out the ID?
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync asErrors = [];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for sKey in dCurErrors:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync asErrors.append('%s: %s' % (sKey[len('TestCaseArgs_'):], dCurErrors[sKey]));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync dErrors[iVar] = '<br>\n'.join(asErrors)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoNewValues.append(oVar);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for iVar in range(len(self.aoTestCaseArgs)):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sArgs = self.aoTestCaseArgs[iVar].sArgs;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for iVar2 in range(iVar + 1, len(self.aoTestCaseArgs)):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.aoTestCaseArgs[iVar2].sArgs == sArgs:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sMsg = 'Duplicate argument variation "%s".' % (sArgs);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if iVar in dErrors: dErrors[iVar] += '<br>\n' + sMsg;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else: dErrors[iVar] = sMsg;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if iVar2 in dErrors: dErrors[iVar2] += '<br>\n' + sMsg;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else: dErrors[iVar2] = sMsg;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync break;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return (aoNewValues, dErrors if len(dErrors) > 0 else None);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return (aoNewValues, None if len(asErrors) == 0 else ' <br>'.join(asErrors));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def _validateAndConvertWorker(self, asAllowNullAttributes, oDb):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync dErrors = TestCaseData._validateAndConvertWorker(self, asAllowNullAttributes, oDb);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Validate dependencies a wee bit for paranoid reasons. The scheduler
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # queue generation code does the real validation here!
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if len(dErrors) == 0 and self.idTestCase is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for oDep in self.aoDepTestCases:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oDep.idTestCase == self.idTestCase:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.ksParam_aoDepTestCases in dErrors:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync dErrors[self.ksParam_aoDepTestCases] += ' Depending on itself!';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync dErrors[self.ksParam_aoDepTestCases] = 'Depending on itself!';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return dErrors;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass TestCaseLogic(ModelLogicBase):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Test case management logic.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getAll(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Fetches all test case records from DB (TestCaseData).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT *\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestCases\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY idTestCase ASC;')
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aaoRows = self._oDb.fetchAll()
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRet = [];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for aoRow in aaoRows:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRet.append(TestCaseData().initFromDbRow(aoRow))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return aoRet
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def fetchForListing(self, iStart, cMaxRows, tsNow):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Fetches test cases.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns an array (list) of TestCaseDataEx items, empty list if none.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Raises exception on error.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if tsNow is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT *\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestCases\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY sName ASC\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'LIMIT %s OFFSET %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (cMaxRows, iStart, ));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT *\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestCases\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE tsExpire > %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsEffective <= %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY sName ASC\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'LIMIT %s OFFSET %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (tsNow, tsNow, cMaxRows, iStart, ));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRows = [];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for aoRow in self._oDb.fetchAll():
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRows.append(TestCaseDataEx().initFromDbRowEx(aoRow, self._oDb, tsNow));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return aoRows;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def fetchForChangeLog(self, idTestCase, iStart, cMaxRows, tsNow): # pylint: disable=R0914
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Fetches change log entries for a testbox.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns an array of ChangeLogEntry instance and an indicator whether
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync there are more entries.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Raises exception on error.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if tsNow is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync tsNow = self._oDb.getCurrentTimestamp();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # 1. Get a list of the relevant change times.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('( SELECT tsEffective, uidAuthor FROM TestCases WHERE idTestCase = %s AND tsEffective <= %s )\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'UNION\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync '( SELECT tsEffective, uidAuthor FROM TestCaseArgs WHERE idTestCase = %s AND tsEffective <= %s )\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'UNION\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync '( SELECT tsEffective, uidAuthor FROM TestCaseDeps WHERE idTestCase = %s AND tsEffective <= %s )\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'UNION\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync '( SELECT tsEffective, uidAuthor FROM TestCaseGlobalRsrcDeps \n' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' WHERE idTestCase = %s AND tsEffective <= %s )\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY tsEffective DESC\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'LIMIT %s OFFSET %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , ( idTestCase, tsNow,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync idTestCase, tsNow,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync idTestCase, tsNow,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync idTestCase, tsNow,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cMaxRows + 1, iStart, ));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aaoChanges = self._oDb.fetchAll();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # 2. Collect data sets for each of those points.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # (Doing it the lazy + inefficient way for now.)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRows = [];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for aoChange in aaoChanges:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRows.append(TestCaseDataEx().initFromDbWithId(self._oDb, idTestCase, aoChange[0]));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # 3. Calculate the changes.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoEntries = [];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for i in range(0, len(aoRows) - 1):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNew = aoRows[i];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oOld = aoRows[i + 1];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync (tsEffective, uidAuthor) = aaoChanges[i];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync (tsExpire, _) = aaoChanges[i - 1] if i > 0 else (oNew.tsExpire, None)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync assert self._oDb.isTsInfinity(tsEffective) != self._oDb.isTsInfinity(tsExpire) or tsEffective < tsExpire, \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync '%s vs %s' % (tsEffective, tsExpire);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoChanges = [];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # The testcase object.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oNew.tsEffective != oOld.tsEffective:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for sAttr in oNew.getDataAttributes():
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sAttr not in [ 'tsEffective', 'tsExpire', 'uidAuthor', \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'aoTestCaseArgs', 'aoDepTestCases', 'aoDepGlobalResources']:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oOldAttr = getattr(oOld, sAttr);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNewAttr = getattr(oNew, sAttr);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oOldAttr != oNewAttr:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoChanges.append(AttributeChangeEntry(sAttr, oNewAttr, oOldAttr, str(oNewAttr), str(oOldAttr)));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # The argument variations.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync iChildOld = 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for oChildNew in oNew.aoTestCaseArgs:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Locate the old entry, emitting removed markers for old items we have to skip.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync while iChildOld < len(oOld.aoTestCaseArgs) \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and oOld.aoTestCaseArgs[iChildOld].idTestCaseArgs < oChildNew.idTestCaseArgs:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oChildOld = oOld.aoTestCaseArgs[iChildOld];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoChanges.append(AttributeChangeEntry('Variation #%s' % (oChildOld.idTestCaseArgs,),
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync None, oChildOld, 'Removed', str(oChildOld)));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync iChildOld += 1;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if iChildOld < len(oOld.aoTestCaseArgs) \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and oOld.aoTestCaseArgs[iChildOld].idTestCaseArgs == oChildNew.idTestCaseArgs:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oChildOld = oOld.aoTestCaseArgs[iChildOld];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oChildNew.tsEffective != oChildOld.tsEffective:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for sAttr in oChildNew.getDataAttributes():
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sAttr not in [ 'tsEffective', 'tsExpire', 'uidAuthor', 'idGenTestCase', ]:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oOldAttr = getattr(oChildOld, sAttr);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNewAttr = getattr(oChildNew, sAttr);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oOldAttr != oNewAttr:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoChanges.append(AttributeChangeEntry('Variation[#%s].%s'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync % (oChildOld.idTestCaseArgs, sAttr,),
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNewAttr, oOldAttr,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync str(oNewAttr), str(oOldAttr)));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync iChildOld += 1;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoChanges.append(AttributeChangeEntry('Variation #%s' % (oChildNew.idTestCaseArgs,),
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oChildNew, None,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync str(oChildNew), 'Did not exist'));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # The testcase dependencies.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync iChildOld = 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for oChildNew in oNew.aoDepTestCases:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Locate the old entry, emitting removed markers for old items we have to skip.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync while iChildOld < len(oOld.aoDepTestCases) \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and oOld.aoDepTestCases[iChildOld].idTestCase < oChildNew.idTestCase:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oChildOld = oOld.aoDepTestCases[iChildOld];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoChanges.append(AttributeChangeEntry('Dependency #%s' % (oChildOld.idTestCase,),
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync None, oChildOld, 'Removed',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync '%s (#%u)' % (oChildOld.sName, oChildOld.idTestCase,)));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync iChildOld += 1;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if iChildOld < len(oOld.aoDepTestCases) \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and oOld.aoDepTestCases[iChildOld].idTestCase == oChildNew.idTestCase:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync iChildOld += 1;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoChanges.append(AttributeChangeEntry('Dependency #%s' % (oChildNew.idTestCase,),
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oChildNew, None,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync '%s (#%u)' % (oChildNew.sName, oChildNew.idTestCase,),
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'Did not exist'));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # The global resource dependencies.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync iChildOld = 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for oChildNew in oNew.aoDepGlobalResources:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Locate the old entry, emitting removed markers for old items we have to skip.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync while iChildOld < len(oOld.aoDepGlobalResources) \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and oOld.aoDepGlobalResources[iChildOld].idGlobalRsrc < oChildNew.idGlobalRsrc:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oChildOld = oOld.aoDepGlobalResources[iChildOld];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoChanges.append(AttributeChangeEntry('Global Resource #%s' % (oChildOld.idGlobalRsrc,),
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync None, oChildOld, 'Removed',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync '%s (#%u)' % (oChildOld.sName, oChildOld.idGlobalRsrc,)));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync iChildOld += 1;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if iChildOld < len(oOld.aoDepGlobalResources) \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and oOld.aoDepGlobalResources[iChildOld].idGlobalRsrc == oChildNew.idGlobalRsrc:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync iChildOld += 1;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoChanges.append(AttributeChangeEntry('Global Resource #%s' % (oChildNew.idGlobalRsrc,),
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oChildNew, None,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync '%s (#%u)' % (oChildNew.sName, oChildNew.idGlobalRsrc,),
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'Did not exist'));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Done.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoEntries.append(ChangeLogEntry(uidAuthor, None, tsEffective, tsExpire, oNew, oOld, aoChanges));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # If we're at the end of the log, add the initial entry.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if len(aoRows) <= cMaxRows and len(aoRows) > 0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNew = aoRows[-1];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoEntries.append(ChangeLogEntry(oNew.uidAuthor, None,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aaoChanges[-1][0], aaoChanges[-2][0] if len(aaoChanges) > 1 else oNew.tsExpire,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNew, None, []));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return (UserAccountLogic(self._oDb).resolveChangeLogAuthors(aoEntries), len(aoRows) > cMaxRows);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def addEntry(self, oData, uidAuthor, fCommit = False):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Add a new testcase to the DB.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Validate the input first.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync assert isinstance(oData, TestCaseDataEx);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync dErrors = oData.validateAndConvert(self._oDb);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if len(dErrors) > 0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise TMExceptionBase('Invalid input data: %s' % (dErrors,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Add the testcase.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.callProc('TestCaseLogic_addEntry',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ( uidAuthor, oData.sName, oData.sDescription, oData.fEnabled, oData.cSecTimeout,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oData.sTestBoxReqExpr, oData.sBuildReqExpr, oData.sBaseCmd, oData.sValidationKitZips ));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oData.idTestCase = self._oDb.fetchOne()[0];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Add testcase dependencies.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for oDep in oData.aoDepTestCases:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('INSERT INTO TestCaseDeps (idTestCase, idTestCasePreReq, uidAuthor) VALUES (%s, %s, %s)'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (oData.idTestCase, oDep.idTestCase, uidAuthor))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Add global resource dependencies.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for oDep in oData.aoDepGlobalResources:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('INSERT INTO TestCaseGlobalRsrcDeps (idTestCase, idGlobalRsrc, uidAuthor) VALUES (%s, %s, %s)'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (oData.idTestCase, oDep.idGlobalRsrc, uidAuthor))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Set Test Case Arguments variations
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for oVar in oData.aoTestCaseArgs:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('INSERT INTO TestCaseArgs (\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' idTestCase, uidAuthor, sArgs, cSecTimeout,\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' sTestBoxReqExpr, sBuildReqExpr, cGangMembers)\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'VALUES (%s, %s, %s, %s, %s, %s, %s)'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , ( oData.idTestCase, uidAuthor, oVar.sArgs, oVar.cSecTimeout,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oVar.sTestBoxReqExpr, oVar.sBuildReqExpr, oVar.cGangMembers,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.maybeCommit(fCommit);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def editEntry(self, oData, uidAuthor, fCommit = False): # pylint: disable=R0914
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Edit a testcase entry (extended).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Caller is expected to rollback the database transactions on exception.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Validate the input.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync assert isinstance(oData, TestCaseDataEx);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync dErrors = oData.validateAndConvert(self._oDb);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if len(dErrors) > 0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise TMExceptionBase('Invalid input data: %s' % (dErrors,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Did anything change? If not return straight away.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oOldDataEx = TestCaseDataEx().initFromDbWithId(self._oDb, oData.idTestCase);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oOldDataEx.isEqual(oData):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.maybeCommit(fCommit);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Make the necessary changes.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # The test case itself.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if not TestCaseData().initFromOther(oOldDataEx).isEqual(oData):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.callProc('TestCaseLogic_editEntry', ( uidAuthor, oData.idTestCase, oData.sName, oData.sDescription,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oData.fEnabled, oData.cSecTimeout, oData.sTestBoxReqExpr,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oData.sBuildReqExpr, oData.sBaseCmd, oData.sValidationKitZips ));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oData.idGenTestCase = self._oDb.fetchOne()[0];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Its dependencies on other testcases.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aidNewDeps = [oDep.idTestCase for oDep in oData.aoDepTestCases];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aidOldDeps = [oDep.idTestCase for oDep in oOldDataEx.aoDepTestCases];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sQuery = self._oDb.formatBindArgs('UPDATE TestCaseDeps\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'SET tsExpire = CURRENT_TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idTestCase = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsExpire = \'infinity\'::timestamp\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (oData.idTestCase,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync asKeepers = [];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for idDep in aidOldDeps:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if idDep in aidNewDeps:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync asKeepers.append(str(idDep));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if len(asKeepers) > 0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sQuery += ' AND idTestCasePreReq NOT IN (' + ', '.join(asKeepers) + ')\n';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute(sQuery);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for idDep in aidNewDeps:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if idDep not in aidOldDeps:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('INSERT INTO TestCaseDeps (idTestCase, idTestCasePreReq, uidAuthor)\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'VALUES (%s, %s, %s)\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (oData.idTestCase, idDep, uidAuthor) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Its dependencies on global resources.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aidNewDeps = [oDep.idGlobalRsrc for oDep in oData.aoDepGlobalResources];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aidOldDeps = [oDep.idGlobalRsrc for oDep in oOldDataEx.aoDepGlobalResources];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sQuery = self._oDb.formatBindArgs('UPDATE TestCaseGlobalRsrcDeps\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'SET tsExpire = CURRENT_TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idTestCase = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsExpire = \'infinity\'::timestamp\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (oData.idTestCase,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync asKeepers = [];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for idDep in aidOldDeps:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if idDep in aidNewDeps:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync asKeepers.append(str(idDep));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if len(asKeepers) > 0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sQuery = ' AND idGlobalRsrc NOT IN (' + ', '.join(asKeepers) + ')\n';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute(sQuery);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for idDep in aidNewDeps:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if idDep not in aidOldDeps:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('INSERT INTO TestCaseGlobalRsrcDeps (idTestCase, idGlobalRsrc, uidAuthor)\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'VALUES (%s, %s, %s)\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (oData.idTestCase, idDep, uidAuthor) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Update Test Case Args
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Note! Primary key is idTestCase, tsExpire, sArgs.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Historize rows that have been removed.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sQuery = self._oDb.formatBindArgs('UPDATE TestCaseArgs\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'SET tsExpire = CURRENT_TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idTestCase = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsExpire = \'infinity\'::TIMESTAMP'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (oData.idTestCase, ));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for oNewVar in oData.aoTestCaseArgs:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync asKeepers.append(self._oDb.formatBindArgs('%s', (oNewVar.sArgs,)));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if len(asKeepers) > 0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sQuery += ' AND sArgs NOT IN (' + ', '.join(asKeepers) + ')\n';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute(sQuery);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Add new TestCaseArgs records if necessary, reusing old IDs when possible.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync from testmanager.core.testcaseargs import TestCaseArgsData;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for oNewVar in oData.aoTestCaseArgs:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT *\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestCaseArgs\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idTestCase = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND sArgs = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY tsExpire DESC\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'LIMIT 1\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (oData.idTestCase, oNewVar.sArgs,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRow = self._oDb.fetchOne();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if aoRow is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # New
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('INSERT INTO TestCaseArgs (\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' idTestCase, uidAuthor, sArgs, cSecTimeout,\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' sTestBoxReqExpr, sBuildReqExpr, cGangMembers)\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'VALUES (%s, %s, %s, %s, %s, %s, %s)'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , ( oData.idTestCase, uidAuthor, oNewVar.sArgs, oNewVar.cSecTimeout,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNewVar.sTestBoxReqExpr, oNewVar.sBuildReqExpr, oNewVar.cGangMembers,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oCurVar = TestCaseArgsData().initFromDbRow(aoRow);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self._oDb.isTsInfinity(oCurVar.tsExpire):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Existing current entry, updated if changed.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oNewVar.cSecTimeout == oCurVar.cSecTimeout \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and oNewVar.sTestBoxReqExpr == oCurVar.sTestBoxReqExpr \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and oNewVar.sBuildReqExpr == oCurVar.sBuildReqExpr \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and oNewVar.cGangMembers == oCurVar.cGangMembers:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNewVar.idTestCaseArgs = oCurVar.idTestCaseArgs;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNewVar.idGenTestCaseArgs = oCurVar.idGenTestCaseArgs;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync continue; # Unchanged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('UPDATE TestCaseArgs SET tsExpire = CURRENT_TIMESTAMP WHERE idGenTestCaseArgs = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (oCurVar.idGenTestCaseArgs, ));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Existing old entry, re-use the ID.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync pass;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('INSERT INTO TestCaseArgs (\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' idTestCaseArgs, idTestCase, uidAuthor, sArgs, cSecTimeout,\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' sTestBoxReqExpr, sBuildReqExpr, cGangMembers)\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'VALUES (%s, %s, %s, %s, %s, %s, %s, %s)\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'RETURNING idGenTestCaseArgs\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , ( oCurVar.idTestCaseArgs, oData.idTestCase, uidAuthor, oNewVar.sArgs, oNewVar.cSecTimeout,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNewVar.sTestBoxReqExpr, oNewVar.sBuildReqExpr, oNewVar.cGangMembers,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNewVar.idGenTestCaseArgs = self._oDb.fetchOne()[0];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.maybeCommit(fCommit);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def removeEntry(self, uidAuthor, idTestCase, fCascade = False, fCommit = False):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """ Deletes the test case if possible. """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.callProc('TestCaseLogic_delEntry', (uidAuthor, idTestCase, fCascade));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.maybeCommit(fCommit);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getTestCasePreReqIds(self, idTestCase, tsEffective = None, cMax = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns an array of prerequisite testcases (IDs) for the given testcase.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync May raise exception on database error or if the result exceeds cMax.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if tsEffective is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT idTestCasePreReq\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestCaseDeps\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idTestCase = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY idTestCasePreReq\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (idTestCase,) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT idTestCasePreReq\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM TestCaseDeps\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idTestCase = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsExpire > %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsEffective <= %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY idTestCasePreReq\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (idTestCase, tsEffective, tsEffective) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if cMax is not None and self._oDb.getRowCount() > cMax:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise TMExceptionBase('Too many prerequisites for testcase %s: %s, max %s'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync % (idTestCase, cMax, self._oDb.getRowCount(),));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aidPreReqs = [];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for aoRow in self._oDb.fetchAll():
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aidPreReqs.append(aoRow[0]);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return aidPreReqs;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync#
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# Unit testing.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync#
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# pylint: disable=C0111
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass TestCaseGlobalRsrcDepDataTestCase(ModelDataBaseTestCase):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setUp(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.aoSamples = [TestCaseGlobalRsrcDepData(),];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass TestCaseDataTestCase(ModelDataBaseTestCase):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setUp(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.aoSamples = [TestCaseData(),];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def testEmptyExpr(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.assertEqual(TestCaseData.validateTestBoxReqExpr(None), None);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.assertEqual(TestCaseData.validateTestBoxReqExpr(''), None);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def testSimpleExpr(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.assertEqual(TestCaseData.validateTestBoxReqExpr('cMbMemory > 10'), None);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.assertEqual(TestCaseData.validateTestBoxReqExpr('cMbScratch < 10'), None);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.assertEqual(TestCaseData.validateTestBoxReqExpr('fChipsetIoMmu'), None);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.assertEqual(TestCaseData.validateTestBoxReqExpr('fChipsetIoMmu is True'), None);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.assertEqual(TestCaseData.validateTestBoxReqExpr('fChipsetIoMmu is False'), None);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.assertEqual(TestCaseData.validateTestBoxReqExpr('fChipsetIoMmu is None'), None);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.assertEqual(TestCaseData.validateTestBoxReqExpr('isinstance(fChipsetIoMmu, bool)'), None);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.assertEqual(TestCaseData.validateTestBoxReqExpr('isinstance(iTestBoxScriptRev, int)'), None);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.assertEqual(TestCaseData.validateTestBoxReqExpr('isinstance(cMbScratch, long)'), None);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def testBadExpr(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.assertNotEqual(TestCaseData.validateTestBoxReqExpr('this is an bad expression, surely it must be'), None);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.assertNotEqual(TestCaseData.validateTestBoxReqExpr('x = 1 + 1'), None);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.assertNotEqual(TestCaseData.validateTestBoxReqExpr('__import__(\'os\').unlink(\'/tmp/no/such/file\')'), None);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.assertNotEqual(TestCaseData.validateTestBoxReqExpr('print "foobar"'), None);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass TestCaseDataExTestCase(ModelDataBaseTestCase):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setUp(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.aoSamples = [TestCaseDataEx(),];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncif __name__ == '__main__':
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync unittest.main();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # not reached.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync