You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
2.4 KiB
65 lines
2.4 KiB
import unittest
|
|
from DBConnection import DBConnection
|
|
import logging
|
|
|
|
logging.basicConfig( format='%(asctime)-15s [%(levelname)s] %(funcName)s: %(message)s', level=logging.DEBUG)
|
|
|
|
class TestDBConnection(unittest.TestCase):
|
|
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
logging.debug(f'setUpClass() {cls}')
|
|
|
|
cls.db_connection = DBConnection()
|
|
cls.db_connection.connect('database','piuser','SW_Ep.6:ROTJ','pidb')
|
|
logging.debug('erzeuge Table fib...')
|
|
cls.db_connection.execute_query('create table if not exists fib (id int auto_increment primary key, wert int)')
|
|
cls.db_connection.execute_query('create table if not exists schueler (id int auto_increment primary key, vorname varchar(20),name varchar(20))')
|
|
logging.debug('setup() fertig')
|
|
|
|
@classmethod
|
|
def tearDownClass(cls):
|
|
logging.debug(f'tearDownClass() {cls}')
|
|
|
|
logging.debug('Räume Tables auf')
|
|
cls.db_connection.execute_query('drop table if exists fib')
|
|
cls.db_connection.execute_query('drop table if exists schueler')
|
|
logging.debug('schliesse Datenbankverbindung.')
|
|
cls.db_connection.disconnect()
|
|
cls.db_connection = None
|
|
|
|
|
|
def test_insert(self):
|
|
logging.debug(f'connected= {self.db_connection.isConnected()}')
|
|
self.assertTrue(self.db_connection.isConnected())
|
|
self.db_connection.execute_query("insert into schueler (name,vorname) values('Simpson','Bart')")
|
|
self.db_connection.execute_query("insert into schueler (name,vorname) values('Simpson','Lisa')")
|
|
self.db_connection.execute_query("insert into schueler (name,vorname) values('van Houten','Milhouse')")
|
|
self.db_connection.execute_query("insert into schueler (name,vorname) values('Wiggum','Ralph')")
|
|
# input('Press Any Key')
|
|
|
|
def test_select(self):
|
|
# self.test_insert()
|
|
self.assertTrue(self.db_connection.isConnected())
|
|
result = self.db_connection.execute_query("select * from schueler where name='Simpson'")
|
|
self.assertEqual(2,len(result))
|
|
result = self.db_connection.execute_query("select * from schueler")
|
|
self.assertEqual(4,len(result))
|
|
|
|
def test_connected(self):
|
|
self.assertTrue(self.db_connection.isConnected())
|
|
|
|
def test_disconnect(self):
|
|
self.db_connection.disconnect()
|
|
self.assertFalse(self.db_connection.isConnected())
|
|
|
|
def test_create_table(self):
|
|
self.assertTrue(self.db_connection.isConnected())
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ =='__main__':
|
|
unittest.main()
|
|
|
|
|