test_base.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # -*- coding: utf-8 -*-
  2. #
  3. # This file is part of Radicale Server - Calendar Server
  4. # Copyright © 2012-2013 Guillaume Ayoub
  5. #
  6. # This library is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This library is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Radicale. If not, see <http://www.gnu.org/licenses/>.
  18. """
  19. Radicale tests with simple requests.
  20. """
  21. from . import (FileSystem, MultiFileSystem, DataBaseSystem,
  22. GitFileSystem, GitMultiFileSystem)
  23. from .helpers import get_file_content
  24. import sys
  25. class BaseRequests(object):
  26. """Tests with simple requests."""
  27. def test_root(self):
  28. """Test a GET request at "/"."""
  29. status, headers, answer = self.request("GET", "/")
  30. assert status == 200
  31. assert "Radicale works!" in answer
  32. # Test the creation of the collection
  33. status, headers, answer = self.request("GET", "/calendar.ics/")
  34. assert "BEGIN:VCALENDAR" in answer
  35. assert "VERSION:2.0" in answer
  36. assert "END:VCALENDAR" in answer
  37. assert "PRODID:-//Radicale//NONSGML Radicale Server//EN" in answer
  38. def test_add_event_todo(self):
  39. """Tests the add of an event and todo."""
  40. self.request("GET", "/calendar.ics/")
  41. #VEVENT test
  42. event = get_file_content("put.ics")
  43. path = "/calendar.ics/02805f81-4cc2-4d68-8d39-72768ffa02d9.ics"
  44. status, headers, answer = self.request("PUT", path, event)
  45. assert status == 201
  46. assert "ETag" in headers.keys()
  47. status, headers, answer = self.request("GET", path)
  48. assert status == 200
  49. assert "VEVENT" in answer
  50. assert b"Nouvel \xc3\xa9v\xc3\xa8nement".decode("utf-8") in answer
  51. assert "UID:02805f81-4cc2-4d68-8d39-72768ffa02d9" in answer
  52. # VTODO test
  53. todo = get_file_content("putvtodo.ics")
  54. path = "/calendar.ics/40f8cf9b-0e62-4624-89a2-24c5e68850f5.ics"
  55. status, headers, answer = self.request("PUT", path, todo)
  56. assert status == 201
  57. assert "ETag" in headers.keys()
  58. status, headers, answer = self.request("GET", path)
  59. assert "VTODO" in answer
  60. assert b"Nouvelle t\xc3\xa2che".decode("utf-8") in answer
  61. assert "UID:40f8cf9b-0e62-4624-89a2-24c5e68850f5" in answer
  62. def test_delete(self):
  63. """Tests the deletion of an event"""
  64. self.request("GET", "/calendar.ics/")
  65. # Adds a VEVENT to be deleted
  66. event = get_file_content("put.ics")
  67. path = "/calendar.ics/02805f81-4cc2-4d68-8d39-72768ffa02d9.ics"
  68. status, headers, answer = self.request("PUT", path, event)
  69. # Then we send a DELETE request
  70. status, headers, answer = self.request("DELETE", path)
  71. assert status == 200
  72. assert "<href>%s</href>" % path in answer
  73. status, headers, answer = self.request("GET", "/calendar.ics/")
  74. assert "VEVENT" not in answer
  75. # Generate classes with different configs
  76. cl_list = [FileSystem, MultiFileSystem, DataBaseSystem,
  77. GitFileSystem, GitMultiFileSystem]
  78. for cl in cl_list:
  79. classname = "Test%s" % cl.__name__
  80. setattr(sys.modules[__name__],
  81. classname, type(classname, (BaseRequests, cl), {}))