Test that hook gets executed on write accesses

This commit is contained in:
Unrud 2016-08-11 00:26:51 +02:00
parent 893051645e
commit 952609deee

View File

@ -20,6 +20,7 @@ Radicale tests with simple requests.
""" """
import logging import logging
import os
import posixpath import posixpath
import shutil import shutil
import tempfile import tempfile
@ -750,6 +751,26 @@ class BaseRequestsMixIn:
status, headers, answer = self.request("MKCALENDAR", "/calendar.ics/") status, headers, answer = self.request("MKCALENDAR", "/calendar.ics/")
assert status == 201 assert status == 201
def test_hook(self):
"""Run hook."""
self.configuration.set(
"storage", "hook", "mkdir %s" % os.path.join("collection-root",
"created_by_hook"))
status, headers, answer = self.request("MKCOL", "/calendar.ics/")
assert status == 201
status, headers, answer = self.request("GET", "/created_by_hook/")
assert status == 200
def test_hook_read_access(self):
"""Verify that hook is not run for read accesses."""
self.configuration.set(
"storage", "hook", "mkdir %s" % os.path.join("collection-root",
"created_by_hook"))
status, headers, answer = self.request("GET", "/")
assert status == 200
status, headers, answer = self.request("GET", "/created_by_hook/")
assert status == 404
class BaseFileSystemTest(BaseTest): class BaseFileSystemTest(BaseTest):
"""Base class for filesystem backend tests.""" """Base class for filesystem backend tests."""