From 17127d97a6d80defe16c9cecbb1f69b87330abca Mon Sep 17 00:00:00 2001 From: Unrud Date: Tue, 4 Sep 2018 03:33:42 +0200 Subject: [PATCH] Test web plugin --- radicale/tests/custom/web.py | 29 ++++++++++++++++ radicale/tests/test_web.py | 67 ++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 radicale/tests/custom/web.py create mode 100644 radicale/tests/test_web.py diff --git a/radicale/tests/custom/web.py b/radicale/tests/custom/web.py new file mode 100644 index 0000000..ff45feb --- /dev/null +++ b/radicale/tests/custom/web.py @@ -0,0 +1,29 @@ +# This file is part of Radicale Server - Calendar Server +# Copyright © 2017-2018 Unrud +# +# 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Radicale. If not, see . + +""" +Custom web plugin. + +""" + +from http import client + +from radicale import web + + +class Web(web.BaseWeb): + def get(self, environ, base_prefix, path, user): + return client.OK, {"Content-Type": "text/plain"}, "custom" diff --git a/radicale/tests/test_web.py b/radicale/tests/test_web.py new file mode 100644 index 0000000..d53ba13 --- /dev/null +++ b/radicale/tests/test_web.py @@ -0,0 +1,67 @@ +# This file is part of Radicale Server - Calendar Server +# Copyright © 2018 Unrud +# +# 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Radicale. If not, see . + +""" +Test web plugin. + +""" + +import shutil +import tempfile + +from radicale import Application, config + +from .test_base import BaseTest + + +class TestBaseWebRequests(BaseTest): + """Test web plugin.""" + + def setup(self): + self.configuration = config.load() + self.colpath = tempfile.mkdtemp() + self.configuration["storage"]["filesystem_folder"] = self.colpath + # Disable syncing to disk for better performance + self.configuration["internal"]["filesystem_fsync"] = "False" + self.application = Application(self.configuration) + + def teardown(self): + shutil.rmtree(self.colpath) + + def test_internal(self): + status, headers, _ = self.request("GET", "/.web") + assert status == 302 + assert headers.get("Location") == ".web/" + status, _, answer = self.request("GET", "/.web/") + assert status == 200 + assert answer + + def test_none(self): + self.configuration["web"]["type"] = "none" + self.application = Application(self.configuration) + status, _, answer = self.request("GET", "/.web") + assert status == 200 + assert answer + status, _, answer = self.request("GET", "/.web/") + assert status == 404 + + def test_custom(self): + """Custom web plugin.""" + self.configuration["web"]["type"] = "tests.custom.web" + self.application = Application(self.configuration) + status, _, answer = self.request("GET", "/.web") + assert status == 200 + assert answer == "custom"