Allow attach custom storage backend

This commit is contained in:
Sergey Fursov 2013-12-28 14:15:35 +04:00
parent a91a7790c5
commit 3b0328ca1e
6 changed files with 66 additions and 6 deletions

6
config
View File

@ -104,6 +104,7 @@ committer = Firstname Lastname <Radicale@Radicale.org>
[rights]
# Rights backend
# Value: regex
backend = "regex"
# Rights management method
@ -116,9 +117,12 @@ file = ~/.config/radicale/rights
[storage]
# Storage backend
# Value: filesystem | multifilesystem | database
# Value: filesystem | multifilesystem | database | custom
type = filesystem
# Custom storage handler
custom_handler =
# Folder for storing local collections, created if not present
filesystem_folder = ~/.config/radicale/collections

View File

@ -81,6 +81,7 @@ INITIAL_CONFIG = {
"file": "~/.config/radicale/rights"},
"storage": {
"type": "filesystem",
"custom_handler": "",
"filesystem_folder": os.path.expanduser(
"~/.config/radicale/collections"),
"database_url": ""},

View File

@ -23,15 +23,20 @@ This module loads the storage backend, according to the storage
configuration.
"""
import sys
from .. import config, ical
def load():
"""Load list of available storage managers."""
storage_type = config.get("storage", "type")
root_module = __import__(
"storage.%s" % storage_type, globals=globals(), level=2)
module = getattr(root_module, storage_type)
if storage_type == "custom":
storage_module = config.get("storage", "custom_handler")
__import__(storage_module)
module = sys.modules[storage_module]
else:
root_module = __import__(
"storage.%s" % storage_type, globals=globals(), level=2)
module = getattr(root_module, storage_type)
ical.Collection = module.Collection
return module

View File

@ -123,6 +123,25 @@ class GitMultiFileSystem(GitFileSystem, MultiFileSystem):
"""Base class for multifilesystem tests using Git"""
class CustomStorageSystem(BaseTest):
"""Base class for custom backend tests."""
storage_type = "custom"
def setup(self):
"""Setup function for each test."""
self.colpath = tempfile.mkdtemp()
config.set("storage", "type", self.storage_type)
config.set("storage", "custom_handler", "tests.custom.storage")
from tests.custom import storage
storage.FOLDER = self.colpath
storage.GIT_REPOSITORY = None
self.application = radicale.Application()
def teardown(self):
"""Teardown function for each test."""
shutil.rmtree(self.colpath)
class AuthSystem(BaseTest):
"""Base class to test Radicale with Htpasswd authentication"""
def setup(self):

30
tests/custom/storage.py Normal file
View File

@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
#
# This file is part of Radicale Server - Calendar Server
# Copyright © 2012-2013 Guillaume Ayoub
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Radicale. If not, see <http://www.gnu.org/licenses/>.
"""
Custom storage backend.
Copy of filesystem storage backend for testing
"""
from radicale.storage import filesystem
class Collection(filesystem.Collection):
"""Collection stored in a flat ical file."""

View File

@ -25,6 +25,7 @@ from . import (FileSystem, MultiFileSystem, DataBaseSystem,
GitFileSystem, GitMultiFileSystem)
from .helpers import get_file_content
import sys
from tests import CustomStorageSystem
class BaseRequests(object):
@ -83,7 +84,7 @@ class BaseRequests(object):
# Generate classes with different configs
cl_list = [FileSystem, MultiFileSystem, DataBaseSystem,
GitFileSystem, GitMultiFileSystem]
GitFileSystem, GitMultiFileSystem, CustomStorageSystem]
for cl in cl_list:
classname = "Test%s" % cl.__name__
setattr(sys.modules[__name__],