Passed
Push — master ( b3d581...f9508c )
by Guangyu
06:53 queued 11s
created

test_mysql.test_connect()   A

Complexity

Conditions 4

Size

Total Lines 20
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
cc 4
nop 0
1
import mysql.connector
2
import config
3
4
5
def test_connect():
6
    cursor = None
7
    cnx = None
8
    try:
9
        cnx = mysql.connector.connect(**config.myems_user_db)
10
        cursor = cnx.cursor()
11
12
        query = (" SELECT id, name, display_name, email "
13
                 " FROM tbl_users  "
14
                 " ORDER BY id ")
15
        cursor.execute(query)
16
        rows = cursor.fetchall()
17
        print("The config of database is right:", rows)
18
    except Exception as e:
19
        print("The config of database is wrong:", str(e))
20
    finally:
21
        if cursor:
22
            cursor.close()
23
        if cnx:
24
            cnx.disconnect()
25
26
27
if __name__ == "__main__":
28
    test_connect()
29