test_web.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. def test_none(self):
  43. self.configuration.update({"web": {"type": "none"}}, "test")
  44. self.application = Application(self.configuration)
  45. _, answer = self.get("/.web")
  46. assert answer
  47. self.get("/.web/", check=404)
  48. def test_custom(self):
  49. """Custom web plugin."""
  50. self.configuration.update({
  51. "web": {"type": "radicale.tests.custom.web"}}, "test")
  52. self.application = Application(self.configuration)
  53. _, answer = self.get("/.web")
  54. assert answer == "custom"