#!/bin/sh

set -o errexit

# The schema of this database is created from the models without running the migrations, see
# config/settings/unittests.py. It is needed while the test runner collects the test modules,
# some of them read the settings from the database when they are imported.
rm -f /var/lib/sqlite/secobserve.db
python manage.py migrate --run-syncdb

if [ $# -eq 0 ]; then
    # All unit tests, with coverage measurement for SonarQube
    coverage run /app/manage.py test unittests
    coverage report
    coverage xml -o /home/coverage.xml
else
    # Only the given tests, without coverage measurement to get the results faster
    python /app/manage.py test "$@"
fi
