#!/usr/share/ucs-test/runner bash
# shellcheck shell=bash
## desc: Test for compatibility with python-udm-rest-api-client
## tags: [udm,apptest,openapi,skip_admember]
## roles: [domaincontroller_master]
## exposure: careful
## packages:
##   - univention-directory-manager-rest
## external-junit: /tmp/04_python_udm_api_client_compatibility.xml

# shellcheck source=../../lib/base.sh
. "$TESTLIBPATH/base.sh" || exit 137
. /usr/share/univention-lib/ldap.sh || exit 137

set -ex

[ -e ucs-test-udm-rest-api/bin/activate ] || python3 -m venv ucs-test-udm-rest-api
. ucs-test-udm-rest-api/bin/activate

DIR="$PWD/ucs-test-udm-rest-api"

cleanup() {
	deactivate
	rm -rf "$DIR"
}
trap cleanup INT TERM EXIT

cd ucs-test-udm-rest-api

[ -e python-udm-rest-api-client ] || git clone https://github.com/univention/python-udm-rest-api-client
cd python-udm-rest-api-client/
python3 -m pip install -U pip
python3 -m pip install udm-rest-client
#python3 -m pip install -r requirements.txt

python3 ./update_openapi_client --generator docker $(hostname -f) --username="$(ucs_convertDN2UID ${tests_domainadmin_account})" --password="${tests_domainadmin_pwd}" --insecure || fail_fast 1

cat > tests/test_server.yaml <<EOF
host: $(hostname -f)
username: $(ucs_convertDN2UID ${tests_domainadmin_account})
user_dn: ${tests_domainadmin_account}
password: ${tests_domainadmin_pwd}
EOF

python3 -m pip install -r requirements_test.txt
python3 -m pytest --tb=native -s -l -vv --junit-xml=/tmp/04_python_udm_api_client_compatibility.xml --junit-prefix=73_udm-rest tests
