-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_dbConnect.py
47 lines (38 loc) · 1.25 KB
/
test_dbConnect.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from unittest import TestCase
from connect_db import DbConnect
import ConfigParser
"""Dieser Test tested die Verbindung zur Datenbank"""
config = ConfigParser.ConfigParser(allow_no_value=True)
config.read('config/database.yml')
dbip = config.items('DBHost')
dbport = config.items('DBPort')
dbname = config.items('DBName')
dbuser = config.items('DBUser')
dbpassword = config.items('DBPassword')
user = '$dbuser'
pw = '$dbpassword'
host = '$dbhost'
port = '$dbport'
database = '$dbname'
class TestDbConnect(TestCase):
def test_connectDb(self):
db = DbConnect(user, pw, host, port, database)
db.connectDb()
db.closeDb()
def test_select_user_table(self):
db = DbConnect(user, pw, host, port, database)
cnx = db.connectDb()
cursor = cnx.cursor()
sql = "select * from user"
cursor.execute(sql)
rs = cursor.fetchall()
print("Ergebnis {}".format(rs))
def test_select_user_talbe_names_with_loop(self):
db = DbConnect(user, pw, host, port, database)
cnx = db.connectDb()
cursor = cnx.cursor()
sql = "select * from user"
cursor.execute(sql)
rs = cursor.fetchall()
for row in rs:
print ("Name Tabelle User {}".format(row[1]))