#!/bin/sh

set -e

ensure_files_exist() {
    for f in "$@"; do
	if [ ! -e $f ]; then
	    echo "ERROR: $f does not exist" >&2
	    exit 1
	else
	    echo "OK: $f is there"
	fi
    done
}

run() {
    echo "Running “$@”"
    $@
}

# Test startproject
cd $ADTTMP
run django-admin startproject testproject

ensure_files_exist testproject/manage.py testproject/testproject/settings.py

# Test startapp
cd testproject
run django-admin startapp testapp

ensure_files_exist testapp/models.py testapp/tests.py testapp/views.py

# Test manage.py
#./manage.py check

# Needed because upstream doesn't want to rewrite shebang of ./manage.py
# see https://code.djangoproject.com/ticket/20027
if [ -e /usr/bin/python ]; then
    ./manage.py check
else
    python3 ./manage.py check
fi
