Blame tests/p_python/20-python-mysql-test.sh

Christoph Galuschka 518959
#!/bin/sh
Christoph Galuschka 518959
# Author: Athmane Madjoudj <athmanem@gmail.com>
Christoph Galuschka 518959
# Author: Christoph Galuschka <christoph.galuschka@chello.at>
Christoph Galuschka 518959
Christoph Galuschka 518959
t_Log "Running $0 - python can retrieve mysql-server version information."
Christoph Galuschka 518959
Christoph Galuschka 518959
# we need a working and running mysql server
Christoph Galuschka 518959
t_InstallPackage mysql-server
Christoph Galuschka 518959
t_ServiceControl mysqld start >/dev/null 2>&1
Christoph Galuschka 518959
Christoph Galuschka 518959
# Installing additional python/mysql module
Christoph Galuschka 518959
t_InstallPackage MySQL-python
Christoph Galuschka 518959
Christoph Galuschka 518959
# create python Scrip
Christoph Galuschka 518959
SCRIPT='/var/tmp/test.py'
Christoph Galuschka 518959
Christoph Galuschka 518959
cat >$SCRIPT <
Christoph Galuschka 518959
import MySQLdb
Christoph Galuschka 518959
Christoph Galuschka 518959
conn = MySQLdb.connect (host = "localhost",
Christoph Galuschka 518959
                           user = "",
Christoph Galuschka 518959
                           passwd = "",
Christoph Galuschka 518959
                           db = "test")
Christoph Galuschka 518959
cursor = conn.cursor ()
Christoph Galuschka 518959
cursor.execute ("SELECT VERSION()")
Christoph Galuschka 518959
row = cursor.fetchone ()
Christoph Galuschka 518959
print "server version:", row[0]
Christoph Galuschka 518959
cursor.close ()
Christoph Galuschka 518959
conn.close ()
Christoph Galuschka 518959
EOF
Christoph Galuschka 518959
Christoph Galuschka 518959
# If we execute the script and get the version it works
Christoph Galuschka 518959
python $SCRIPT |grep -q 'server version'
Christoph Galuschka 518959
Christoph Galuschka 518959
t_CheckExitStatus $?
Christoph Galuschka 518959
Christoph Galuschka 518959
# cleaning up
Christoph Galuschka 518959
/bin/rm $SCRIPT