celery_test.sh 1.5 KB
#
## To be used for tests using celery (asynchronous)
## BEWARE : This script launches tests on the production database
#

#
## Usage : celery_test.sh app.tests[.ClassTest[.test_name]]
#

USAGE_MSG="Usage : celery_test.sh app.tests[.ClassTest[.test_name]]"
CELERY_WORKER_OFF="You must run scripts/start_celery_workers.sh before running this test"

if [ "$#" -eq 0 ]; then
    echo $USAGE_MSG
    exit
fi

# Checks if the workers are running. Useless now because we run them from the script

# ALERT_WORKER=`ps aux | grep "celery worker" | grep alert_listener`
# if [ "${#ALERT_WORKER}" -eq 0 ]; then
#     echo $CELERY_WORKER_OFF
#     exit
# fi

SCRIPT_PATH=$0
SCRIPT_PATH=${SCRIPT_PATH%/*}

cd $SCRIPT_PATH/..

# Sets the variable CELERY_TEST in settings.py in order to use to good test DB
sed -i -e "s/CELERY_TEST = False/CELERY_TEST = True/g" pyros/settings.py

# Deletes the DB, then re-create it with basic fixtures
rm -f testdb.sqlite3
python manage.py migrate
python manage.py loaddata misc/fixtures/initial_fixture.json

# Starts the simulators
cd ../simulators/scripts 2>&1 /dev/null
./run_all.sh
cd -

# Start celery
./scripts/start_celery_single_worker.sh 2>&1 /dev/null

# Run the tests
python manage.py test "$@" --keepdb --nomigrations

# Reset the variable in settings.py
sed -i -e "s/CELERY_TEST = True/CELERY_TEST = False/g" pyros/settings.py

# Delete the test DB
rm -f testdb.sqlite3

cd scripts/

# Stops celery workers
./kill_celery_workers.sh

# Stops simulators
cd ../../simulators/scripts/
./kill_all.sh
cd -