Marc Cataford
0242b2d5ff
* build(backend): set up Django 4.2 scaffolding * feat: porting files API feat: file ownership basics feat: gaps in test compatibility * test: port files API tests * fix(tests): test database port 5432>5431 to avoid conflict with application database * feat(auth): LoginView, middleware to handle JWT bearer tokens * refactor: clean up old FastAPI logic, temporary utils * refactor: resolve LoginView linting * feat: user creation + test coverage * test: session creation coverage * refactor: hoist secrets, replace placeholders * chore: clear linting errors+warns
48 lines
1.1 KiB
Bash
48 lines
1.1 KiB
Bash
#!/bin/bash
|
|
|
|
# Test runner script
|
|
#
|
|
# This sets up an ephemeral database for test purposes, runs migrations on it
|
|
# and triggers pytest. Regardless of outcome, the database container is cleaned
|
|
# up after the fact.
|
|
#
|
|
# This will return 0 or 1 as exit code, depending on outcome.
|
|
|
|
TEST_DB_CONTAINER="rotini-test-ephemeral-$(date +%s)"
|
|
|
|
VENV_PYTHON=.venv/bin/python
|
|
VENV_PYTEST=.venv/bin/pytest
|
|
|
|
HEALTHCHECK_SLEEP=0.5
|
|
|
|
# Log & exit.
|
|
function fail {
|
|
echo $1
|
|
exit 1
|
|
}
|
|
|
|
# Cleanup before exit (success/failure)
|
|
function cleanup {
|
|
docker rm $TEST_DB_CONTAINER -f > /dev/null || echo "Failed to clean up test database container."
|
|
}
|
|
|
|
trap cleanup EXIT
|
|
|
|
docker run \
|
|
--name $TEST_DB_CONTAINER \
|
|
-e POSTGRES_PASSWORD=test \
|
|
-p 5431:5432 \
|
|
-d \
|
|
postgres:15.4
|
|
|
|
until [ -n "$(docker exec $TEST_DB_CONTAINER pg_isready | grep accepting)" ]; do
|
|
echo "Waiting for DB to come alive..."
|
|
sleep $HEALTHCHECK_SLEEP
|
|
done;
|
|
|
|
sleep $HEALTHCHECK_SLEEP
|
|
|
|
#ROTINI_TEST=1 PYTHONPATH=rotini $VENV_PYTHON rotini/migrations/migrate.py up || fail "Migrations failed."
|
|
$VENV_PYTEST . -vv -s || fail "Test run failed."
|
|
|
|
cleanup
|