summaryrefslogtreecommitdiff
path: root/unit-test.sh
blob: 4577e0fc9d53558f86c7e81aaf9b2c71df3eb5a9 (plain)
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
#!/bin/sh -ex

HERE=$(dirname $(readlink -f $0))
cd $HERE

VENV_DIR="${VENV_DIR-$HERE/.venv}"

if [ -z $VIRTUAL_ENV ] ; then
	echo "creating venv: $VENV_DIR ..."
	virtualenv --python=`which python2` $VENV_DIR
	. $VENV_DIR/bin/activate
	pip install Django==1.8.10
	pip install djangorestframework==3.5
	pip install django-filter==1.0
	pip install sqlparse==0.2.2
	pip install dulwich
	pip install mock
	pip install flake8
fi

if [ -z $PYTHONPATH ] ; then
	if [ ! -d $VENV_DIR/patchwork ]; then
		git clone https://github.com/getpatchwork/patchwork.git $VENV_DIR/patchwork
		cd $VENV_DIR/patchwork
		git checkout -b production v2.0.1
		cd $HERE
	fi
	export PYTHONPATH=$VENV_DIR/patchwork
fi

echo
echo "== Running flake8 checks..."
echo
FLAKE_EXCLUDE="linaro_metrics/migrations"
if echo $VENV_DIR | grep $HERE ; then
	# make sure we don't run tests on the venv if its in our source tree
	FLAKE_EXCLUDE="$VENV_DIR,$FLAKE_EXCLUDE"
fi
flake8 --ignore=E402 --show-source --exclude=$FLAKE_EXCLUDE ./

echo
echo "== Running test suite..."
echo
if [ ! -f ~/.gitconfig ] ; then
	git config --global user.email "citestbot@example.com"
	git config --global user.name "ci test bot"
fi
export DJANGO_SETTINGS_MODULE=linaro_metrics.settings
export PYTHONPATH=./:./tests:$PYTHONPATH

# find the manage.py script
for x in $(echo $PYTHONPATH | sed -e 's/:/\n/g') ; do
	if [ -f $x/manage.py ] ; then
		MANAGE=$x/manage.py
	fi
done
if [ -z $MANAGE ] ; then
	echo "ERROR: no manage.py found in $PYTHONPATH"
	exit 1
fi
$MANAGE test $*