forked from ScoDoc/ScoDoc
Building script: integrate full unit tests and API tests
This commit is contained in:
parent
fd5fefec71
commit
77723982f5
@ -5,8 +5,24 @@
|
||||
set -e
|
||||
|
||||
# Le répertoire de ce script:
|
||||
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||
|
||||
while getopts "p:" opt; do
|
||||
case "$opt" in
|
||||
p)
|
||||
PORT=${OPTARG}
|
||||
;;
|
||||
\?)
|
||||
echo "Invalid option: -$OPTARG" >&2
|
||||
exit 1
|
||||
;;
|
||||
:)
|
||||
echo "Option -$OPTARG requires an argument." >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# récupère API_USER et API_PASSWORD
|
||||
source "$SCRIPT_DIR"/.env
|
||||
|
||||
@ -22,4 +38,9 @@ flask user-password --password "$API_PASSWORD" "$API_USER"
|
||||
flask edit-role LecteurAPI -a ScoView
|
||||
flask user-role "$API_USER" -a LecteurAPI
|
||||
|
||||
flask run --host 0.0.0.0
|
||||
if [ -z "$PORT" ]
|
||||
then
|
||||
flask run --host 0.0.0.0
|
||||
else
|
||||
flask run --host 0.0.0.0 -p "$PORT"
|
||||
fi
|
||||
|
@ -42,6 +42,7 @@ ARCH="amd64"
|
||||
FACTORY_DIR="/opt/factory"
|
||||
DEST_DIR="$PACKAGE_NAME"_"$VERSION"-"$RELEASE"_"$ARCH"
|
||||
GIT_RELEASE_URL="https://scodoc.org/git/viennet/ScoDoc/archive/${RELEASE_TAG}.tar.gz"
|
||||
UNIT_TESTS_DIR="/opt/scodoc" # on lance les tests dans le rep. de travail, pas idéal
|
||||
|
||||
echo "Le paquet sera $DEST_DIR.deb"
|
||||
echo -n "Est-ce ok ? (y/n) [y] "
|
||||
@ -59,6 +60,14 @@ SCODOC_USER=scodoc
|
||||
[ -z "$FACTORY_DIR" ] && die "empty FACTORY_DIR"
|
||||
[ "$(id -nu)" != "$SCODOC_USER" ] && die "Erreur: le script $0 doit être lancé par l'utilisateur $SCODOC_USER"
|
||||
|
||||
# Tests unitaires lancés dans le répertoire de travail
|
||||
echo "TESTS UNITAIRES"
|
||||
(cd "$UNIT_TESTS_DIR"; pytest tests/unit)
|
||||
|
||||
# Tests API
|
||||
(cd "$UNIT_TESTS_DIR"; tools/test_api.sh)
|
||||
|
||||
|
||||
# Création répertoire du paquet, et de opt
|
||||
slash="$FACTORY_DIR"/"$DEST_DIR"
|
||||
optdir="$slash"/opt
|
||||
|
@ -36,7 +36,7 @@ while getopts "anh" opt; do
|
||||
h)
|
||||
echo "Diagnostic installation ScoDoc"
|
||||
echo "Rassemble informations sur le systeme et l'installation ScoDoc"
|
||||
echo "Usage: $0 [-h] [-n] [-a] [-u] [-d dept]"
|
||||
echo "Usage: $0 [-h] [-n] [-a] [-u]"
|
||||
echo " -h cette aide"
|
||||
echo " -n pas d'envoi par mail"
|
||||
echo " -a enregistre la bases de donnees (prod)"
|
||||
|
52
tools/test_api.sh
Executable file
52
tools/test_api.sh
Executable file
@ -0,0 +1,52 @@
|
||||
#!/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"
|
||||
# ------------------
|
||||
|
||||
pytest tests/api
|
||||
|
||||
# ------------------
|
||||
echo "Killing server"
|
||||
kill "$pid"
|
||||
fuser -k "$PORT"/tcp
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user