Skip to content
Snippets Groups Projects
do_tests 2.71 KiB
Newer Older
Vincent Hatakeyama's avatar
Vincent Hatakeyama committed
#!/bin/zsh
# vim: set shiftwidth=4 softtabstop=4:
#
# This script will create a database, install some modules and run tests on it
#
# Arguments:
#
# - db host if any (will use socket if nothing is provided)
# - db user
# - other arguments are ignored
#
# Required:
#
# - access to pg database
#
# Version 1.2
Vincent Hatakeyama's avatar
Vincent Hatakeyama committed
here=$(dirname $0)
project_home=$here/..
dbname=$(basename $(readlink -f $project_home))_test
# this is the same value as conf/dev/odoo.conf
dbowner=$(python -B -c "import ConfigParser ; c = ConfigParser.ConfigParser() ; c.read('${project_home}/conf/dev/odoo.conf') ; print c.get('options', 'db_user')")
modules_to_install=$(paste -d, -s $project_home/module_list)

# color stuff
autoload colors
if [[ "$terminfo[colors]" -gt 7 ]];
then
    colors
fi
for COLOR in RED GREEN YELLOW BLUE MAGENTA CYAN BLACK WHITE; do
    eval $COLOR='$fg_no_bold[${(L)COLOR}]'
    eval BOLD_$COLOR='$fg_bold[${(L)COLOR}]'
done
eval RESET='$reset_color'

# argument handling
if [[ $# -gt 0 ]];
then
    echo ${YELLOW}INFO ${RESET} - Using database host $1
    PG_HOST=-h$1
    ODOO_HOST=--db_host=$1
    shift
    if [[ $# -gt 0 ]];
    then
	echo ${YELLOW}INFO ${RESET} - Using database user $1
	PG_USER=-U$1
	ODOO_USER=--db_user=$1
	dbowner=$1
	shift
    else
	PG_USER=""
	ODOO_USER=""
    fi
else
    PG_HOST=""
    ODOO_HOST=""
    PG_USER=""
    ODOO_USER=""
fi

echo ${YELLOW}INFO ${RESET} - Drop any existing database "$dbname"
dropdb $PG_HOST $PG_USER --if-exists $dbname
echo ${YELLOW}INFO ${RESET} - Create database "$dbname" with owner $dbowner
createdb $PG_HOST $PG_USER -O $dbowner $dbname || { echo ${RED}FATAL${RESET} - Cannot create test database ; exit 1; }
unaccent=$(python -B -c "import ConfigParser ; c = ConfigParser.ConfigParser() ; c.read('${project_home}/conf/dev/odoo.conf') ; print c.get('options', 'unaccent', False)")
if [[ "$unaccent" == "True" ]];
then
    psql $PG_HOST $PG_USER $dbname -c "CREATE EXTENSION unaccent;"
fi
echo ${YELLOW}INFO ${RESET} - Modules to install: $modules_to_install
echo ${YELLOW}INFO ${RESET} - Install those modules
$here/start -i $modules_to_install -d $dbname --log-level=warn --max-cron=0 --stop-after-init $ODOO_HOST $ODOO_USER || { echo ${RED}FATAL${RESET} - Cannot install modules ; exit 1; }
logfile=$(tempfile --suffix=.log)
echo ${YELLOW}INFO ${RESET} - Run tests on $dbname
$here/run_tests $dbname $ODOO_HOST $ODOO_USER | tee $logfile
ok=$(grep ' OK' $logfile -c)
failed=$(grep ' FAILED' $logfile -c)
echo ''
echo '***** Test results *****'
echo "$ok modules passing, $failed modules failing"
echo ''
if [[ $ok -gt 0 ]];
then
    echo '\tOK:'
    grep ' OK' $logfile || true
fi
if [[ $failed -gt 0 ]];
then
    echo '\tFAILED:'
    grep FAILED $logfile
fi
echo ''
rm $logfile
if [[ $failed -gt 0 ]];
then
    exit 1
fi