VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/testmanager/core/vcsbugreference.py@ 84550

Last change on this file since 84550 was 84550, checked in by vboxsync, 5 years ago

TestManager: Adding new table for correlating commits and bugs (for xTracker).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.1 KB
Line 
1# -*- coding: utf-8 -*-
2# $Id: vcsbugreference.py 84550 2020-05-26 18:50:43Z vboxsync $
3
4"""
5Test Manager - VcsBugReferences
6"""
7
8__copyright__ = \
9"""
10Copyright (C) 2012-2020 Oracle Corporation
11
12This file is part of VirtualBox Open Source Edition (OSE), as
13available from http://www.virtualbox.org. This file is free software;
14you can redistribute it and/or modify it under the terms of the GNU
15General Public License (GPL) as published by the Free Software
16Foundation, in version 2 as it comes in the "COPYING" file of the
17VirtualBox OSE distribution. VirtualBox OSE is distributed in the
18hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
19
20The contents of this file may alternatively be used under the terms
21of the Common Development and Distribution License Version 1.0
22(CDDL) only, as it comes in the "COPYING.CDDL" file of the
23VirtualBox OSE distribution, in which case the provisions of the
24CDDL are applicable instead of those of the GPL.
25
26You may elect to license modified versions of this file under the
27terms and conditions of either the GPL or the CDDL or both.
28"""
29__version__ = "$Revision: 84550 $"
30
31
32# Standard python imports.
33import unittest;
34
35# Validation Kit imports.
36from testmanager.core.base import ModelDataBase, ModelDataBaseTestCase, ModelLogicBase, TMExceptionBase;
37
38
39class VcsBugReferenceData(ModelDataBase):
40 """
41 A version control system (VCS) bug tracker reference (commit message tag).
42 """
43
44 #kasIdAttr = ['sRepository','iRevision', 'sBugTracker', 'iBugNo'];
45
46 ksParam_sRepository = 'VcsBugReference_sRepository';
47 ksParam_iRevision = 'VcsBugReference_iRevision';
48 ksParam_sBugTracker = 'VcsBugReference_sBugTracker';
49 ksParam_lBugNo = 'VcsBugReference_lBugNo';
50
51 kasAllowNullAttributes = [ ];
52
53 def __init__(self):
54 ModelDataBase.__init__(self);
55
56 #
57 # Initialize with defaults.
58 # See the database for explanations of each of these fields.
59 #
60 self.sRepository = None;
61 self.iRevision = None;
62 self.sBugTracker = None;
63 self.lBugNo = None;
64
65 def initFromDbRow(self, aoRow):
66 """
67 Re-initializes the object from a SELECT * FROM VcsBugReferences row.
68 Returns self. Raises exception if aoRow is None.
69 """
70 if aoRow is None:
71 raise TMExceptionBase('VcsBugReference not found.');
72
73 self.sRepository = aoRow[0];
74 self.iRevision = aoRow[1];
75 self.sBugTracker = aoRow[2];
76 self.lBugNo = aoRow[3];
77 return self;
78
79 def initFromValues(self, sRepository, iRevision, sBugTracker, lBugNo):
80 """
81 Reinitializes form a set of values.
82 return self.
83 """
84 self.sRepository = sRepository;
85 self.iRevision = iRevision;
86 self.sBugTracker = sBugTracker;
87 self.lBugNo = lBugNo;
88 return self;
89
90
91class VcsBugReferenceLogic(ModelLogicBase): # pylint: disable=too-few-public-methods
92 """
93 VCS revision <-> bug tracker references database logic.
94 """
95
96 #
97 # Standard methods.
98 #
99
100 def fetchForListing(self, iStart, cMaxRows, tsNow, aiSortColumns = None):
101 """
102 Fetches VCS revisions for listing.
103
104 Returns an array (list) of VcsBugReferenceData items, empty list if none.
105 Raises exception on error.
106 """
107 _ = tsNow; _ = aiSortColumns;
108 self._oDb.execute('''
109SELECT *
110FROM VcsBugReferences
111ORDER BY sRepository, iRevision, sBugTracker, lBugNo
112LIMIT %s OFFSET %s
113''', (cMaxRows, iStart,));
114
115 aoRows = [];
116 for _ in range(self._oDb.getRowCount()):
117 aoRows.append(VcsBugReferenceData().initFromDbRow(self._oDb.fetchOne()));
118 return aoRows;
119
120 def exists(self, oData):
121 """
122 Checks if the data is already present in the DB.
123 Returns True / False.
124 Raises exception on input and database errors.
125 """
126 self._oDb.execute('''
127SELECT COUNT(*)
128FROM VcsBugReferences
129WHERE sRepository = %s
130 AND iRevision = %s
131 AND sBugTracker = %s
132 AND lBugNo = %s
133''', ( oData.sRepository, oData.iRevision, oData.sBugTracker, oData.lBugNo));
134 cRows = self._oDb.fetchOne()[0];
135 if cRows < 0 or cRows > 1:
136 raise TMExceptionBase('VcsBugReferences has a primary key problem: %u duplicates' % (cRows,));
137 return cRows != 0;
138
139
140 #
141 # Other methods.
142 #
143
144 def addVcsBugReference(self, oData, fCommit = False):
145 """
146 Adds (or updates) a tree revision record.
147 Raises exception on input and database errors.
148 """
149
150 # Check VcsBugReferenceData before do anything
151 dDataErrors = oData.validateAndConvert(self._oDb, oData.ksValidateFor_Add);
152 if dDataErrors:
153 raise TMExceptionBase('Invalid data passed to addVcsBugReference(): %s' % (dDataErrors,));
154
155 # Does it already exist?
156 if not self.exists(oData):
157 # New row.
158 self._oDb.execute('INSERT INTO VcsBugReferences (sRepository, iRevision, sBugTracker, lBugNo)\n'
159 'VALUES (%s, %s, %s, %s)\n'
160 , ( oData.sRepository,
161 oData.iRevision,
162 oData.sBugTracker,
163 oData.lBugNo,
164 ));
165
166 self._oDb.maybeCommit(fCommit);
167 return oData;
168
169 def getLastRevision(self, sRepository):
170 """
171 Get the last known revision number for the given repository, returns 0
172 if the repository is not known to us:
173 """
174 self._oDb.execute('''
175SELECT iRevision
176FROM VcsBugReferences
177WHERE sRepository = %s
178ORDER BY iRevision DESC
179LIMIT 1
180''', ( sRepository, ));
181 if self._oDb.getRowCount() == 0:
182 return 0;
183 return self._oDb.fetchOne()[0];
184
185
186#
187# Unit testing.
188#
189
190# pylint: disable=missing-docstring
191class VcsBugReferenceDataTestCase(ModelDataBaseTestCase):
192 def setUp(self):
193 self.aoSamples = [VcsBugReferenceData(),];
194
195if __name__ == '__main__':
196 unittest.main();
197 # not reached.
198
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette