forked from karlosss/simple_api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_tests.sh
executable file
·59 lines (49 loc) · 1.39 KB
/
run_tests.sh
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
#!/usr/bin/env bash
shopt -s nullglob
TEST_DIRS=(
tests/graphql/actions
tests/graphql/django_objects
tests/graphql/objects
tests/graphql/stack_overflow
tests/graphql/readme_forum
tests/graphql/library_system
)
cd "${0%/*}"
# testcases filtering by regex
if [[ -n "$1" ]]
then
filter=$1
else
filter="*"
fi
# activate virtualenv if exists
if [[ -d venv ]]
then
. venv/bin/activate
fi
for dir in "${TEST_DIRS[@]}"
do
for tc in "$dir"/[!_]*
do
# ignore if the testcase does not match the filter
if ! grep -E "$filter" <<< "$tc" &>/dev/null
then
continue
fi
echo "Running $dir/$tc"
# cleanup possible old runs
find test_project/simple_api_test/testcases ! \( -name '__init__.py' -o -name 'admin.py' -o -name 'apps.py' -o -name 'utils.py' -o -name 'views.py' \) -type f -exec rm -rf {} \;
rm -f test_project/simple_api_test/db.sqlite3
# copy sources into test project
cp "$tc"/[!_]* test_project/simple_api_test/testcases
# migrate database
test_project/simple_api_test/manage.py makemigrations testcases &>/dev/null
test_project/simple_api_test/manage.py migrate &>/dev/null
# run tests
if ! test_project/simple_api_test/manage.py test testcases.tests
then
echo "$tc failed!" >&2
exit 1
fi
done
done