MonScoDocEssai/tools/test_api.sh

60 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
# Lance les tests unitaires de l'API
# Ce script lance un serveur scodoc sur le port 5555
# attend qu'il soit initialisé puis lance les tests client API.
#
# E. Viennet, Fev 2023
cd /opt/scodoc
# suppose que le virtual env est bien configuré
# Utilise un port spécifique pour pouvoir lancer ce test sans couper
# le serveur de dev
PORT=5555
SERVER_LOG=/tmp/test_api_server.log
export SCODOC_URL="http://localhost:${PORT}"
# ------- Check pas de serveur déjà lancé
if nc -z localhost "$PORT"
then
fuser -v "$PORT"/tcp
echo Server already running on port "$PORT"
echo You may want to try: fuser -k "$PORT"/tcp
echo aborting tests
exit 1
fi
tests/api/start_api_server.sh -p "$PORT" &> "$SERVER_LOG" &
pid=$!
echo "ScoDoc test server logs are in $SERVER_LOG"
# Wait for server setup
echo -n "Waiting for server"
while ! nc -z localhost "$PORT"; do
echo -n .
sleep 1
done
echo
echo Server PID "$pid" running on port "$PORT"
# ------------------
if [ "$#" -eq 0 ]
then
echo "Starting pytest tests/api"
pytest tests/api
else
echo "Starting pytest $@"
pytest "$@"
fi
# ------------------
echo "Killing server"
kill "$pid"
fuser -k "$PORT"/tcp