mirror of
https://github.com/Kozea/Radicale.git
synced 2025-09-15 20:36:55 +00:00
Rework configuration
This commit is contained in:
parent
63e6d091b9
commit
b7590f8c84
19 changed files with 609 additions and 220 deletions
|
@ -1,5 +1,5 @@
|
|||
# This file is part of Radicale Server - Calendar Server
|
||||
# Copyright © 2018 Unrud <unrud@outlook.com>
|
||||
# Copyright © 2018-2019 Unrud <unrud@outlook.com>
|
||||
#
|
||||
# This library is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
@ -28,7 +28,7 @@ import sys
|
|||
import tempfile
|
||||
import threading
|
||||
import time
|
||||
from configparser import ConfigParser
|
||||
from configparser import RawConfigParser
|
||||
from urllib import request
|
||||
from urllib.error import HTTPError, URLError
|
||||
|
||||
|
@ -36,7 +36,7 @@ import pytest
|
|||
|
||||
from radicale import config, server
|
||||
|
||||
from .helpers import get_file_path
|
||||
from .helpers import configuration_to_dict, get_file_path
|
||||
|
||||
try:
|
||||
import gunicorn
|
||||
|
@ -57,17 +57,18 @@ class TestBaseServerRequests:
|
|||
def setup(self):
|
||||
self.configuration = config.load()
|
||||
self.colpath = tempfile.mkdtemp()
|
||||
self.configuration["storage"]["filesystem_folder"] = self.colpath
|
||||
# Enable debugging for new processes
|
||||
self.configuration["logging"]["level"] = "debug"
|
||||
# Disable syncing to disk for better performance
|
||||
self.configuration["internal"]["filesystem_fsync"] = "False"
|
||||
self.shutdown_socket, shutdown_socket_out = socket.socketpair()
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
||||
# Find available port
|
||||
sock.bind(("127.0.0.1", 0))
|
||||
self.sockname = sock.getsockname()
|
||||
self.configuration["server"]["hosts"] = "[%s]:%d" % self.sockname
|
||||
self.configuration.update({
|
||||
"storage": {"filesystem_folder": self.colpath},
|
||||
"server": {"hosts": "[%s]:%d" % self.sockname},
|
||||
# Enable debugging for new processes
|
||||
"logging": {"level": "debug"},
|
||||
# Disable syncing to disk for better performance
|
||||
"internal": {"filesystem_fsync": "False"}}, "test")
|
||||
self.thread = threading.Thread(target=server.serve, args=(
|
||||
self.configuration, shutdown_socket_out))
|
||||
ssl_context = ssl.create_default_context()
|
||||
|
@ -89,8 +90,8 @@ class TestBaseServerRequests:
|
|||
"""Send a request."""
|
||||
if is_alive_fn is None:
|
||||
is_alive_fn = self.thread.is_alive
|
||||
scheme = ("https" if self.configuration.getboolean("server", "ssl")
|
||||
else "http")
|
||||
scheme = ("https" if self.configuration.get("server", "ssl") else
|
||||
"http")
|
||||
req = request.Request(
|
||||
"%s://[%s]:%d%s" % (scheme, *self.sockname, path),
|
||||
data=data, headers=headers, method=method)
|
||||
|
@ -112,9 +113,10 @@ class TestBaseServerRequests:
|
|||
assert status == 302
|
||||
|
||||
def test_ssl(self):
|
||||
self.configuration["server"]["ssl"] = "True"
|
||||
self.configuration["server"]["certificate"] = get_file_path("cert.pem")
|
||||
self.configuration["server"]["key"] = get_file_path("key.pem")
|
||||
self.configuration.update({
|
||||
"server": {"ssl": "True",
|
||||
"certificate": get_file_path("cert.pem"),
|
||||
"key": get_file_path("key.pem")}}, "test")
|
||||
self.thread.start()
|
||||
status, _, _ = self.request("GET", "/")
|
||||
assert status == 302
|
||||
|
@ -129,7 +131,8 @@ class TestBaseServerRequests:
|
|||
except OSError:
|
||||
pytest.skip("IPv6 not supported")
|
||||
self.sockname = sock.getsockname()[:2]
|
||||
self.configuration["server"]["hosts"] = "[%s]:%d" % self.sockname
|
||||
self.configuration.update({
|
||||
"server": {"hosts": "[%s]:%d" % self.sockname}}, "test")
|
||||
savedEaiAddrfamily = server.EAI_ADDRFAMILY
|
||||
if os.name == "nt" and server.EAI_ADDRFAMILY is None:
|
||||
# HACK: incomplete errno conversion in WINE
|
||||
|
@ -143,17 +146,22 @@ class TestBaseServerRequests:
|
|||
|
||||
def test_command_line_interface(self):
|
||||
config_args = []
|
||||
for section, values in config.INITIAL_CONFIG.items():
|
||||
for section, values in config.DEFAULT_CONFIG_SCHEMA.items():
|
||||
if values.get("_internal", False):
|
||||
continue
|
||||
for option, data in values.items():
|
||||
if option.startswith("_"):
|
||||
continue
|
||||
long_name = "--{0}-{1}".format(
|
||||
section, option.replace("_", "-"))
|
||||
if data["type"] == bool:
|
||||
if not self.configuration.getboolean(section, option):
|
||||
if not self.configuration.get(section, option):
|
||||
long_name = "--no{0}".format(long_name[1:])
|
||||
config_args.append(long_name)
|
||||
else:
|
||||
config_args.append(long_name)
|
||||
config_args.append(self.configuration.get(section, option))
|
||||
config_args.append(
|
||||
self.configuration.get_raw(section, option))
|
||||
env = os.environ.copy()
|
||||
env["PYTHONPATH"] = os.pathsep.join(sys.path)
|
||||
p = subprocess.Popen(
|
||||
|
@ -170,18 +178,17 @@ class TestBaseServerRequests:
|
|||
|
||||
@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")
|
||||
parser = RawConfigParser()
|
||||
parser.read_dict(configuration_to_dict(self.configuration))
|
||||
with open(config_path, "w") as f:
|
||||
config.write(f)
|
||||
parser.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"],
|
||||
"--bind", self.configuration.get_raw("server", "hosts"),
|
||||
"--env", "RADICALE_CONFIG=%s" % config_path, "radicale"], env=env)
|
||||
try:
|
||||
status, _, _ = self.request(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue