test_web.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # This file is part of Radicale Server - Calendar Server
  2. # Copyright © 2018-2019 Unrud <unrud@outlook.com>
  3. #
  4. # This library is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This library is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with Radicale. If not, see <http://www.gnu.org/licenses/>.
  16. """
  17. Test web plugin.
  18. """
  19. import shutil
  20. import tempfile
  21. from radicale import Application, config
  22. from radicale.tests import BaseTest
  23. class TestBaseWebRequests(BaseTest):
  24. """Test web plugin."""
  25. def setup(self):
  26. self.configuration = config.load()
  27. self.colpath = tempfile.mkdtemp()
  28. self.configuration.update({
  29. "storage": {"filesystem_folder": self.colpath,
  30. # Disable syncing to disk for better performance
  31. "_filesystem_fsync": "False"}},
  32. "test", privileged=True)
  33. self.application = Application(self.configuration)
  34. def teardown(self):
  35. shutil.rmtree(self.colpath)
  36. def test_internal(self):
  37. status, headers, _ = self.request("GET", "/.web")
  38. assert status == 302
  39. assert headers.get("Location") == ".web/"
  40. _, answer = self.get("/.web/")
  41. assert answer
  42. self.post("/.web", check=405)
  43. def test_none(self):
  44. self.configuration.update({"web": {"type": "none"}}, "test")
  45. self.application = Application(self.configuration)
  46. _, answer = self.get("/.web")
  47. assert answer
  48. self.get("/.web/", check=404)
  49. self.post("/.web", check=405)
  50. def test_custom(self):
  51. """Custom web plugin."""
  52. self.configuration.update({
  53. "web": {"type": "radicale.tests.custom.web"}}, "test")
  54. self.application = Application(self.configuration)
  55. _, answer = self.get("/.web")
  56. assert answer == "custom"
  57. _, answer = self.post("/.web", "body content")
  58. assert answer == "echo:body content"