test WSGI server
This commit is contained in:
parent
171651e205
commit
f1de843188
@ -28,6 +28,7 @@ import sys
|
|||||||
import tempfile
|
import tempfile
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
from configparser import ConfigParser
|
||||||
from urllib import request
|
from urllib import request
|
||||||
from urllib.error import HTTPError, URLError
|
from urllib.error import HTTPError, URLError
|
||||||
|
|
||||||
@ -37,6 +38,11 @@ from .helpers import get_file_path
|
|||||||
|
|
||||||
import pytest # isort:skip
|
import pytest # isort:skip
|
||||||
|
|
||||||
|
try:
|
||||||
|
import gunicorn
|
||||||
|
except ImportError:
|
||||||
|
gunicorn = None
|
||||||
|
|
||||||
|
|
||||||
class DisabledRedirectHandler(request.HTTPRedirectHandler):
|
class DisabledRedirectHandler(request.HTTPRedirectHandler):
|
||||||
def http_error_302(self, req, fp, code, msg, headers):
|
def http_error_302(self, req, fp, code, msg, headers):
|
||||||
@ -159,3 +165,27 @@ class TestBaseServerRequests:
|
|||||||
p.wait()
|
p.wait()
|
||||||
if os.name == "posix":
|
if os.name == "posix":
|
||||||
assert p.returncode == 0
|
assert p.returncode == 0
|
||||||
|
|
||||||
|
@pytest.mark.skipif(not gunicorn, reason="gunicorn module not found")
|
||||||
|
def test_wsgi_server(self):
|
||||||
|
config = ConfigParser()
|
||||||
|
config.read_dict(self.configuration)
|
||||||
|
assert config.remove_section("internal")
|
||||||
|
config_path = os.path.join(self.colpath, "config")
|
||||||
|
with open(config_path, "w") as f:
|
||||||
|
config.write(f)
|
||||||
|
env = os.environ.copy()
|
||||||
|
env["PYTHONPATH"] = os.pathsep.join(sys.path)
|
||||||
|
p = subprocess.Popen([
|
||||||
|
sys.executable,
|
||||||
|
"-c", "from gunicorn.app.wsgiapp import run; run()",
|
||||||
|
"--bind", self.configuration["server"]["hosts"],
|
||||||
|
"--env", "RADICALE_CONFIG=%s" % config_path, "radicale"], env=env)
|
||||||
|
try:
|
||||||
|
status, _, _ = self.request(
|
||||||
|
"GET", "/", is_alive_fn=lambda: p.poll() is None)
|
||||||
|
assert status == 302
|
||||||
|
finally:
|
||||||
|
p.terminate()
|
||||||
|
p.wait()
|
||||||
|
assert p.returncode == 0
|
||||||
|
3
setup.py
3
setup.py
@ -36,6 +36,7 @@ For further information, please visit the `Radicale Website
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from setuptools import find_packages, setup
|
from setuptools import find_packages, setup
|
||||||
@ -53,6 +54,8 @@ needs_pytest = {"pytest", "test", "ptr"}.intersection(sys.argv)
|
|||||||
pytest_runner = ["pytest-runner"] if needs_pytest else []
|
pytest_runner = ["pytest-runner"] if needs_pytest else []
|
||||||
tests_require = ["pytest-runner", "pytest", "pytest-cov", "pytest-flake8",
|
tests_require = ["pytest-runner", "pytest", "pytest-cov", "pytest-flake8",
|
||||||
"pytest-isort"]
|
"pytest-isort"]
|
||||||
|
if os.name == "posix":
|
||||||
|
tests_require.append("gunicorn")
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="Radicale",
|
name="Radicale",
|
||||||
|
Loading…
Reference in New Issue
Block a user