1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
#!/bin/sh
set -e
copy_logs_and_config()
{
echo "INFO: copy apache2 logs"
mkdir -p "${AUTOPKGTEST_ARTIFACTS}/var/log"
cp -r /var/log/apache2 "${AUTOPKGTEST_ARTIFACTS}/var/log"
echo "INFO: copy apache2 config"
mkdir -p "${AUTOPKGTEST_ARTIFACTS}/etc"
cp -r /etc/apache2 "${AUTOPKGTEST_ARTIFACTS}/etc"
}
trap copy_logs_and_config EXIT
output="Hello, world!"
echo "INFO: setup configuration"
cat >> /etc/apache2/apache2.conf <<EOT
<Directory /var/www/html/python/publisher/>
SetHandler mod_python
PythonHandler mod_python.publisher
</Directory>
<Directory /var/www/html/python/cgi/>
SetHandler mod_python
PythonHandler mod_python.cgihandler
</Directory>
EOT
# Publisher Test Script
mkdir -p /var/www/html/python/publisher
cat > /var/www/html/python/publisher/hello.py <<EOT
#!/usr/bin/python3
def index():
return "${output}\n"
EOT
# CGI Test Script
mkdir -p /var/www/html/python/cgi
cat > /var/www/html/python/cgi/hello.py <<EOT
#!/usr/bin/python3
print("Content-Type: text/plain")
print()
print("${output}")
EOT
echo "INFO: enable apache2 python module"
a2enmod python
echo "INFO: reloading apache2 service"
service apache2 reload
test_WHEN_mod_python_handler_is_called_SHOULD_return_output()
{
handler="$1"
echo "INFO: testing handler ${handler}"
url="http://localhost/python/${handler}/hello.py"
if ! actualOutput="$(curl --silent --show-error "${url}")"; then
echo "ERROR: curl failed while calling hello script (${handler})!"
echo "$actualOutput"
exit 1
fi
if test "$actualOutput" != "$output"; then
echo "ERROR: The output of the hello script (${handler}) does not match the expected value!"
echo "- expected: '$output'"
echo "- received: '$actualOutput'"
exit 1
fi
}
test_WHEN_mod_python_handler_is_called_SHOULD_return_output "publisher"
test_WHEN_mod_python_handler_is_called_SHOULD_return_output "cgi"
|