DbTest.py

Go to the documentation of this file.
00001 #
00002 # Test Environment for VoIP Networks (TestEnv)
00003 #
00004 # Copyright (C) 2008  Enrico Hartung <enrico@iptel.org>
00005 #
00006 # This program is free software: you can redistribute it and/or modify
00007 # it under the terms of the GNU General Public License as published by
00008 # the Free Software Foundation, either version 3 of the License, or
00009 # (at your option) any later version.
00010 #
00011 # This program is distributed in the hope that it will be useful,
00012 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 # GNU General Public License for more details.
00015 #
00016 # You should have received a copy of the GNU General Public License
00017 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018 
00019 from lib.SipDatabase import SipDatabase
00020 from testenv.core.TestModule import TestModule
00021 
00022 ##
00023 # 
00024 #       TestEnv module DbTest
00025 #       
00026 #       This module inserts simple database tests into TestEnv.
00027 #       
00028 #       @author Enrico Hartung <enrico@iptel.org>
00029 #       @version 0.1
00030 #       @license GPL
00031 #       
00032 #       @section db_requirements Requirements
00033 #       - TestEnv >=0.4
00034 #       - libiptel      
00035 #       
00036 #       @ingroup test_module_all
00037 #       
00038 class DbTest(TestModule):
00039         
00040         #database url e.g. mysql://user:pass@mysqldb.com:3306/database
00041         _dbUrl = ""
00042         
00043         #table to check in
00044         _table = ""
00045         
00046         #asserted table values
00047         _assertedValues = []
00048                 
00049         
00050         def initTestModule(self):
00051                 pass
00052         
00053         
00054         ##
00055         # 
00056         #               This method ist called after the start of the thread.
00057         #               
00058         #               If an error occurs a log file including the output of the process is written into the working directory. The name of this log file has follwing structure:
00059         #               <test case description>_<process name>_<unix time stamp>.log
00060         #               
00061         def run(self):
00062                 
00063                 dbase = SipDatabase(dburl=self._dbUrl)
00064                 dbase.createDbConnection()
00065 
00066                 #build sql query
00067                 query = "SELECT * FROM " + self._table + " WHERE "
00068                 first = 1
00069                 for key in self._assertedValues:
00070                         if first != 1:
00071                                 query += " and "
00072                         query += key + " = '" + self._assertedValues[key] + "'"
00073                         first = 0
00074                 query += ";"
00075                 
00076                 cursor = dbase.executeQuery(query)
00077                 
00078                 result = 0
00079                 if cursor.fetchone() == None:
00080                         result = 1
00081                 
00082                 #store result of this test
00083                 self._storeResult(self._name, result, "terminated")
00084 
00085                 dbase.shutDown()
00086 
00087 

Generated on Mon Aug 11 17:28:17 2008 for TestEnv by  doxygen 1.5.5