# -*- coding: utf-8 -*-
# $Id$
"""
Test Manager - Failure Categories.
"""
__copyright__ = \
"""
Copyright (C) 2012-2014 Oracle Corporation
This file is part of VirtualBox Open Source Edition (OSE), as
available from http://www.virtualbox.org. This file is free software;
General Public License (GPL) as published by the Free Software
Foundation, in version 2 as it comes in the "COPYING" file of the
VirtualBox OSE distribution. VirtualBox OSE is distributed in the
hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
The contents of this file may alternatively be used under the terms
of the Common Development and Distribution License Version 1.0
(CDDL) only, as it comes in the "COPYING.CDDL" file of the
VirtualBox OSE distribution, in which case the provisions of the
CDDL are applicable instead of those of the GPL.
You may elect to license modified versions of this file under the
terms and conditions of either the GPL or the CDDL or both.
"""
# Validation Kit imports.
"""
Failure Category Data.
"""
#
# Initialize with defaults.
# See the database for explanations of each of these fields.
#
self.idFailureCategory = None
self.tsEffective = None
"""
Re-initializes the data with a row from a SELECT * FROM FailureCategoryes.
Returns self. Raises exception if the row is None or otherwise invalid.
"""
if aoRow is None:
raise TMExceptionBase('Failure Category not found.');
return self
"""
Failure Category logic.
"""
"""
Fetches Failure Category records.
Returns an array (list) of FailureCategoryData items, empty list if none.
Raises exception on error.
"""
if tsNow is None:
'FROM FailureCategories\n'
'WHERE tsExpire = \'infinity\'::TIMESTAMP\n'
'ORDER BY idFailureCategory ASC\n'
'LIMIT %s OFFSET %s\n'
else:
'FROM FailureCategories\n'
'WHERE tsExpire > %s\n'
' AND tsEffective <= %s\n'
'ORDER BY idFailureCategory ASC\n'
'LIMIT %s OFFSET %s\n'
aoRows = []
return aoRows
"""
Gets the list of Failure Categories for a combo box.
Returns an array of (value [idFailureCategory], drop-down-name [sShort],
hover-text [sFull]) tuples.
"""
if tsEffective is None:
'FROM FailureCategories\n'
'WHERE tsExpire = \'infinity\'::TIMESTAMP\n'
'ORDER BY sShort')
else:
'FROM FailureCategories\n'
'WHERE tsExpire > %s\n'
' AND tsEffective <= %s\n'
'ORDER BY sShort'
, (tsEffective, tsEffective))
"""Get Failure Category data by idFailureCategory"""
'FROM FailureCategories\n'
'WHERE tsExpire = \'infinity\'::timestamp\n'
' AND idFailureCategory = %s;', (idFailureCategory,))
'Found more than one failure categories with the same credentials. Database structure is corrupted.')
try:
except IndexError:
return None
"""
Add Failure Category record
"""
# Check if record with the same sShort fiels is already exists
'FROM FailureCategories\n'
'WHERE tsExpire = \'infinity\'::TIMESTAMP\n'
' AND sShort = %s\n',
raise Exception('Record already exist')
# Add record
' uidAuthor, sShort, sFull'
')\n'
'VALUES (%s, %s, %s)',
if fCommit:
return True
"""
Historize record
"""
# Historize Failure Reasons records first
'FROM FailureReasons\n'
'WHERE idFailureCategory = %s\n'
' AND tsExpire = \'infinity\'::TIMESTAMP\n',
'SET tsExpire = CURRENT_TIMESTAMP,\n'
' uidAuthor = %s\n'
'WHERE idFailureCategory = %s\n'
' AND tsExpire = \'infinity\'::TIMESTAMP\n',
if fNeedCommit:
return True
"""Modify database record"""
# Check if record exists
if oFailureCategoryDataOld is None:
raise TMExceptionBase(
'Failure Category (id: %d) does not exist'
# Check if anything has been changed
return True
# Historize record
' idFailureCategory, uidAuthor, sShort, sFull'
')\n'
'VALUES (%s, %s, %s, %s)',
if fCommit:
return True