Allow attach custom storage backend
This commit is contained in:
parent
a91a7790c5
commit
3b0328ca1e
6
config
6
config
@ -104,6 +104,7 @@ committer = Firstname Lastname <Radicale@Radicale.org>
|
|||||||
|
|
||||||
[rights]
|
[rights]
|
||||||
# Rights backend
|
# Rights backend
|
||||||
|
# Value: regex
|
||||||
backend = "regex"
|
backend = "regex"
|
||||||
|
|
||||||
# Rights management method
|
# Rights management method
|
||||||
@ -116,9 +117,12 @@ file = ~/.config/radicale/rights
|
|||||||
|
|
||||||
[storage]
|
[storage]
|
||||||
# Storage backend
|
# Storage backend
|
||||||
# Value: filesystem | multifilesystem | database
|
# Value: filesystem | multifilesystem | database | custom
|
||||||
type = filesystem
|
type = filesystem
|
||||||
|
|
||||||
|
# Custom storage handler
|
||||||
|
custom_handler =
|
||||||
|
|
||||||
# Folder for storing local collections, created if not present
|
# Folder for storing local collections, created if not present
|
||||||
filesystem_folder = ~/.config/radicale/collections
|
filesystem_folder = ~/.config/radicale/collections
|
||||||
|
|
||||||
|
@ -81,6 +81,7 @@ INITIAL_CONFIG = {
|
|||||||
"file": "~/.config/radicale/rights"},
|
"file": "~/.config/radicale/rights"},
|
||||||
"storage": {
|
"storage": {
|
||||||
"type": "filesystem",
|
"type": "filesystem",
|
||||||
|
"custom_handler": "",
|
||||||
"filesystem_folder": os.path.expanduser(
|
"filesystem_folder": os.path.expanduser(
|
||||||
"~/.config/radicale/collections"),
|
"~/.config/radicale/collections"),
|
||||||
"database_url": ""},
|
"database_url": ""},
|
||||||
|
@ -23,15 +23,20 @@ This module loads the storage backend, according to the storage
|
|||||||
configuration.
|
configuration.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
import sys
|
||||||
from .. import config, ical
|
from .. import config, ical
|
||||||
|
|
||||||
|
|
||||||
def load():
|
def load():
|
||||||
"""Load list of available storage managers."""
|
"""Load list of available storage managers."""
|
||||||
storage_type = config.get("storage", "type")
|
storage_type = config.get("storage", "type")
|
||||||
root_module = __import__(
|
if storage_type == "custom":
|
||||||
"storage.%s" % storage_type, globals=globals(), level=2)
|
storage_module = config.get("storage", "custom_handler")
|
||||||
module = getattr(root_module, storage_type)
|
__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
|
ical.Collection = module.Collection
|
||||||
return module
|
return module
|
||||||
|
@ -123,6 +123,25 @@ class GitMultiFileSystem(GitFileSystem, MultiFileSystem):
|
|||||||
"""Base class for multifilesystem tests using Git"""
|
"""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):
|
class AuthSystem(BaseTest):
|
||||||
"""Base class to test Radicale with Htpasswd authentication"""
|
"""Base class to test Radicale with Htpasswd authentication"""
|
||||||
def setup(self):
|
def setup(self):
|
||||||
|
30
tests/custom/storage.py
Normal file
30
tests/custom/storage.py
Normal 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."""
|
@ -25,6 +25,7 @@ from . import (FileSystem, MultiFileSystem, DataBaseSystem,
|
|||||||
GitFileSystem, GitMultiFileSystem)
|
GitFileSystem, GitMultiFileSystem)
|
||||||
from .helpers import get_file_content
|
from .helpers import get_file_content
|
||||||
import sys
|
import sys
|
||||||
|
from tests import CustomStorageSystem
|
||||||
|
|
||||||
|
|
||||||
class BaseRequests(object):
|
class BaseRequests(object):
|
||||||
@ -83,7 +84,7 @@ class BaseRequests(object):
|
|||||||
|
|
||||||
# Generate classes with different configs
|
# Generate classes with different configs
|
||||||
cl_list = [FileSystem, MultiFileSystem, DataBaseSystem,
|
cl_list = [FileSystem, MultiFileSystem, DataBaseSystem,
|
||||||
GitFileSystem, GitMultiFileSystem]
|
GitFileSystem, GitMultiFileSystem, CustomStorageSystem]
|
||||||
for cl in cl_list:
|
for cl in cl_list:
|
||||||
classname = "Test%s" % cl.__name__
|
classname = "Test%s" % cl.__name__
|
||||||
setattr(sys.modules[__name__],
|
setattr(sys.modules[__name__],
|
||||||
|
Loading…
Reference in New Issue
Block a user