-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_tests.sh
executable file
·80 lines (70 loc) · 2.7 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
###############################################################################
# Bash script file to create and populate test database for unit tests.
# And for running all unit tests. It is recommended to use this script for
# testing.
###############################################################################
#!/bin/bash
# File and folder names
DB_FOLDER="database/"
DB_SCHEMA_FILE_NAME="tellus_schema_dump.sql"
DB_DATA_FILE_NAME="tellus_data_dump.sql"
DB_TEST_FILE_NAME="test_tellus.db"
TEST_FOLDER="tests"
declare -a test_files=("tests_database_api_users" "tests_database_api_rooms" "tests_database_api_bookings"
"tests_resource_api_room" "tests_resource_api_bookings_of_room" "tests_resource_api_booking_of_user"
"tests_resource_api_bookings_of_user" "tests_resource_api_history_bookings" "func_tests_database_api_users"
"func_tests_database_api_rooms" "func_tests_database_api_bookings")
function create_test_db {
## Check database folder exists
if [ ! -d "$DB_FOLDER" ]; then
echo "$DB_FOLDER does not exist. Please control your setup."
exit 0
fi
## Check database schema dump exists
if [ ! -f "$DB_FOLDER$DB_SCHEMA_FILE_NAME" ]; then
echo "$DB_SCHEMA_FILE_NAME does not exist. Please control your setup."
exit 0
fi
## Check database data dump exists
if [ ! -f "$DB_FOLDER$DB_DATA_FILE_NAME" ]; then
echo "$DB_DATA_FILE_NAME does not exist. Please control your setup."
exit 0
fi
## Remove old test database
if [ -f "$DB_FOLDER$DB_TEST_FILE_NAME" ]; then
echo "Removing old test database."
echo ".........................."
rm $DB_FOLDER$DB_TEST_FILE_NAME
echo "Old test database is removed."
echo ".........................."
fi
## Create and populate new test database
echo "Tables are creating."
echo ".........................."
cat $DB_FOLDER$DB_SCHEMA_FILE_NAME | sqlite3 $DB_FOLDER$DB_TEST_FILE_NAME
echo "Database is populating."
echo ".........................."
cat $DB_FOLDER$DB_DATA_FILE_NAME | sqlite3 $DB_FOLDER$DB_TEST_FILE_NAME
}
# Run tests
for i in "${test_files[@]}"
do
# First create test db
create_test_db
if [ ! -f "$TEST_FOLDER/$i" ]; then
echo "Test file $i is running."
echo ".........................."
python -m $TEST_FOLDER.$i
fi
## Remove the test_tellus.db when run the final model
if [ -f "$DB_FOLDER$DB_TEST_FILE_NAME" ]; then
echo "Removing old test database."
echo ".........................."
rm $DB_FOLDER$DB_TEST_FILE_NAME
echo "Old test database is removed."
echo ".........................."
fi
done
echo "Everything is done."
echo "Bye"
exit 0