test_hook_rabbitmq.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # This file is part of Radicale - CalDAV and CardDAV server
  2. # Copyright © 2025-2025 Peter Bieringer <pb@bieringer.de>
  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. Radicale tests related to hook 'rabbitmq'
  18. """
  19. import logging
  20. import os
  21. from radicale.tests import BaseTest
  22. from radicale.tests.helpers import get_file_content
  23. class TestHooks(BaseTest):
  24. """Tests with hooks."""
  25. def setup_method(self) -> None:
  26. BaseTest.setup_method(self)
  27. rights_file_path = os.path.join(self.colpath, "rights")
  28. with open(rights_file_path, "w") as f:
  29. f.write("""\
  30. [permit delete collection]
  31. user: .*
  32. collection: test-permit-delete
  33. permissions: RrWwD
  34. [forbid delete collection]
  35. user: .*
  36. collection: test-forbid-delete
  37. permissions: RrWwd
  38. [permit overwrite collection]
  39. user: .*
  40. collection: test-permit-overwrite
  41. permissions: RrWwO
  42. [forbid overwrite collection]
  43. user: .*
  44. collection: test-forbid-overwrite
  45. permissions: RrWwo
  46. [allow all]
  47. user: .*
  48. collection: .*
  49. permissions: RrWw""")
  50. self.configure({"rights": {"file": rights_file_path,
  51. "type": "from_file"}})
  52. self.configure({"hook": {"type": "rabbitmq",
  53. "dryrun": "True"}})
  54. def test_add_event(self, caplog) -> None:
  55. caplog.set_level(logging.WARNING)
  56. """Add an event."""
  57. self.mkcalendar("/calendar.ics/")
  58. event = get_file_content("event1.ics")
  59. path = "/calendar.ics/event1.ics"
  60. self.put(path, event)
  61. _, headers, answer = self.request("GET", path, check=200)
  62. assert "ETag" in headers
  63. assert headers["Content-Type"] == "text/calendar; charset=utf-8"
  64. assert "VEVENT" in answer
  65. assert "Event" in answer
  66. assert "UID:event" in answer
  67. found = False
  68. for line in caplog.messages:
  69. if line.find("notification_item: {'type': 'upsert'") != -1:
  70. found = True
  71. if (found is False):
  72. raise ValueError("Logging misses expected log line")
  73. def test_delete_event(self, caplog) -> None:
  74. caplog.set_level(logging.WARNING)
  75. """Delete an event."""
  76. self.mkcalendar("/calendar.ics/")
  77. event = get_file_content("event1.ics")
  78. path = "/calendar.ics/event1.ics"
  79. self.put(path, event)
  80. _, responses = self.delete(path)
  81. assert responses[path] == 200
  82. _, answer = self.get("/calendar.ics/")
  83. assert "VEVENT" not in answer
  84. found = False
  85. for line in caplog.messages:
  86. if line.find("notification_item: {'type': 'delete'") != -1:
  87. found = True
  88. if (found is False):
  89. raise ValueError("Logging misses expected log line")