test_web.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # This file is part of Radicale Server - Calendar Server
  2. # Copyright © 2018 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 .test_base 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["storage"]["filesystem_folder"] = self.colpath
  29. # Disable syncing to disk for better performance
  30. self.configuration["internal"]["filesystem_fsync"] = "False"
  31. self.application = Application(self.configuration)
  32. def teardown(self):
  33. shutil.rmtree(self.colpath)
  34. def test_internal(self):
  35. status, headers, _ = self.request("GET", "/.web")
  36. assert status == 302
  37. assert headers.get("Location") == ".web/"
  38. status, _, answer = self.request("GET", "/.web/")
  39. assert status == 200
  40. assert answer
  41. def test_none(self):
  42. self.configuration["web"]["type"] = "none"
  43. self.application = Application(self.configuration)
  44. status, _, answer = self.request("GET", "/.web")
  45. assert status == 200
  46. assert answer
  47. status, _, answer = self.request("GET", "/.web/")
  48. assert status == 404
  49. def test_custom(self):
  50. """Custom web plugin."""
  51. self.configuration["web"]["type"] = "tests.custom.web"
  52. self.application = Application(self.configuration)
  53. status, _, answer = self.request("GET", "/.web")
  54. assert status == 200
  55. assert answer == "custom"