celery_test.sh
1.49 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#
## 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_workers.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 -