#!/bin/bash

set -e -u

cp -a docs tests "${AUTOPKGTEST_TMP}"

export DJANGO_SETTINGS_MODULE=tests.django.django_settings

PYTEST_OPTIONS="\
 --ignore=${AUTOPKGTEST_TMP}/tests//channels/test_layers.py \
 --ignore=${AUTOPKGTEST_TMP}/tests//channels/test_testing.py \
 --ignore=${AUTOPKGTEST_TMP}/tests//extensions/test_custom_objects_for_setting_attribute.py \
 --ignore=${AUTOPKGTEST_TMP}/tests//extensions/test_pyinstrument.py \
 --ignore=${AUTOPKGTEST_TMP}/tests//extensions/tracing/test_opentelemetry.py \
 --ignore=${AUTOPKGTEST_TMP}/tests//http/test_graphql_ide.py \
 --ignore=${AUTOPKGTEST_TMP}/tests//http/test_query.py \
 --ignore=${AUTOPKGTEST_TMP}/tests//http/test_query_via_get.py \
 --ignore=${AUTOPKGTEST_TMP}/tests//http/test_upload.py \
 --ignore=${AUTOPKGTEST_TMP}/tests//litestar/test_context.py \
 --ignore=${AUTOPKGTEST_TMP}/tests//litestar/test_response_headers.py \
 --ignore=${AUTOPKGTEST_TMP}/tests//litestar/test_response_status.py \
 --ignore=${AUTOPKGTEST_TMP}/tests//sanic/test_file_upload.py \
 --ignore=${AUTOPKGTEST_TMP}/tests//schema/extensions/test_opentelemetry.py \
 --ignore=${AUTOPKGTEST_TMP}/tests//websockets/test_graphql_transport_ws.py \
 --ignore=${AUTOPKGTEST_TMP}/tests//websockets/test_graphql_ws.py \
 --ignore=${AUTOPKGTEST_TMP}/tests/http/test_graphql_over_http_spec.py \
"

for py3vers in $(py3versions -s); do
    echo
    echo "***************************"
    echo "*** Testing with ${py3vers}"
    echo "***************************"
    echo
    cd "${AUTOPKGTEST_TMP}" && \
        echo -e "Content of current working folder:\n" && \
        ls -la && \
        echo -e "Running tests...\n" && \
        PYTHONPATH=. "${py3vers}" -m pytest $PYTEST_OPTIONS -k \
                "not test_does_only_allow_get_and_post \
             and not test_clients_can_prefer_subprotocols \
             and not test_custom_process_result \
             and not test_extensions \
             and not test_fetch_data_from_db \
             and not test_generally_unsupported_subprotocols_are_rejected \
             and not test_handlers_use_the_views_decode_json_method \
             and not test_handlers_use_the_views_encode_json_method \
             and not test_lazy_types_loaded_from_same_module \
             and not test_multipart_subscription \
             and not test_mutation \
             and not test_query_asserts_errors_option_is_deprecated \
             and not test_query_with_assert_no_errors_option \
             and not test_the_http_handler_uses_the_views_decode_json_method \
             and not test_turning_off_all_subprotocols \
             and not test_turning_off_graphql_transport_ws \
             and not test_turning_off_graphql_ws" tests && \
        rm -rf .pytest_cache || exit 1
done

echo

exit 0

