Simplified tests structure
This commit is contained in:
parent
3b0328ca1e
commit
017df0ddcf
@ -22,23 +22,15 @@ Tests for Radicale.
|
||||
"""
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
from dulwich.repo import Repo
|
||||
from io import BytesIO
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
|
||||
|
||||
import radicale
|
||||
|
||||
os.environ["RADICALE_CONFIG"] = os.path.join(os.path.dirname(
|
||||
os.path.dirname(__file__)), "config")
|
||||
|
||||
from radicale import config
|
||||
from .helpers import get_file_content
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from sqlalchemy import create_engine
|
||||
|
||||
|
||||
class BaseTest(object):
|
||||
@ -70,83 +62,3 @@ class BaseTest(object):
|
||||
"""Put the response values into the current application."""
|
||||
self.application._status = status
|
||||
self.application._headers = headers
|
||||
|
||||
|
||||
class FileSystem(BaseTest):
|
||||
"""Base class for filesystem tests."""
|
||||
storage_type = "filesystem"
|
||||
|
||||
def setup(self):
|
||||
"""Setup function for each test."""
|
||||
self.colpath = tempfile.mkdtemp()
|
||||
config.set("storage", "type", self.storage_type)
|
||||
from radicale.storage import filesystem
|
||||
filesystem.FOLDER = self.colpath
|
||||
filesystem.GIT_REPOSITORY = None
|
||||
self.application = radicale.Application()
|
||||
|
||||
def teardown(self):
|
||||
"""Teardown function for each test."""
|
||||
shutil.rmtree(self.colpath)
|
||||
|
||||
|
||||
class MultiFileSystem(FileSystem):
|
||||
"""Base class for multifilesystem tests."""
|
||||
storage_type = "multifilesystem"
|
||||
|
||||
|
||||
class DataBaseSystem(BaseTest):
|
||||
"""Base class for database tests"""
|
||||
def setup(self):
|
||||
config.set("storage", "type", "database")
|
||||
config.set("storage", "database_url", "sqlite://")
|
||||
from radicale.storage import database
|
||||
database.Session = sessionmaker()
|
||||
database.Session.configure(bind=create_engine("sqlite://"))
|
||||
session = database.Session()
|
||||
for st in get_file_content("schema.sql").split(";"):
|
||||
session.execute(st)
|
||||
session.commit()
|
||||
self.application = radicale.Application()
|
||||
|
||||
|
||||
class GitFileSystem(FileSystem):
|
||||
"""Base class for filesystem tests using Git"""
|
||||
def setup(self):
|
||||
super(GitFileSystem, self).setup()
|
||||
Repo.init(self.colpath)
|
||||
from radicale.storage import filesystem
|
||||
filesystem.GIT_REPOSITORY = Repo(self.colpath)
|
||||
|
||||
|
||||
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):
|
||||
self.userpass = "dG1wOmJlcG8="
|
||||
|
||||
def teardown(self):
|
||||
config.set("auth", "type", "None")
|
||||
radicale.auth.is_authenticated = lambda *_: True
|
||||
|
@ -27,18 +27,25 @@ import hashlib
|
||||
import os
|
||||
import radicale
|
||||
import tempfile
|
||||
from tests import AuthSystem
|
||||
from radicale import config
|
||||
from radicale.auth import htpasswd
|
||||
from tests import BaseTest
|
||||
|
||||
|
||||
class TestBaseAuthRequests(AuthSystem):
|
||||
class TestBaseAuthRequests(BaseTest):
|
||||
"""
|
||||
Tests basic requests with auth.
|
||||
|
||||
We should setup auth for each type before create Application object
|
||||
"""
|
||||
|
||||
def setup(self):
|
||||
self.userpass = "dG1wOmJlcG8="
|
||||
|
||||
def teardown(self):
|
||||
config.set("auth", "type", "None")
|
||||
radicale.auth.is_authenticated = lambda *_: True
|
||||
|
||||
def test_root(self):
|
||||
self.colpath = tempfile.mkdtemp()
|
||||
htpasswd_file_path = os.path.join(self.colpath, ".htpasswd")
|
||||
|
@ -21,11 +21,15 @@ Radicale tests with simple requests.
|
||||
|
||||
"""
|
||||
|
||||
from . import (FileSystem, MultiFileSystem, DataBaseSystem,
|
||||
GitFileSystem, GitMultiFileSystem)
|
||||
from .helpers import get_file_content
|
||||
import sys
|
||||
from tests import CustomStorageSystem
|
||||
import radicale
|
||||
import shutil
|
||||
import tempfile
|
||||
from dulwich.repo import Repo
|
||||
from radicale import config
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from sqlalchemy import create_engine
|
||||
from tests import BaseTest
|
||||
|
||||
|
||||
class BaseRequests(object):
|
||||
@ -82,10 +86,72 @@ class BaseRequests(object):
|
||||
status, headers, answer = self.request("GET", "/calendar.ics/")
|
||||
assert "VEVENT" not in answer
|
||||
|
||||
# Generate classes with different configs
|
||||
cl_list = [FileSystem, MultiFileSystem, DataBaseSystem,
|
||||
GitFileSystem, GitMultiFileSystem, CustomStorageSystem]
|
||||
for cl in cl_list:
|
||||
classname = "Test%s" % cl.__name__
|
||||
setattr(sys.modules[__name__],
|
||||
classname, type(classname, (BaseRequests, cl), {}))
|
||||
|
||||
class TestFileSystem(BaseRequests, BaseTest):
|
||||
"""Base class for filesystem tests."""
|
||||
storage_type = "filesystem"
|
||||
|
||||
def setup(self):
|
||||
"""Setup function for each test."""
|
||||
self.colpath = tempfile.mkdtemp()
|
||||
config.set("storage", "type", self.storage_type)
|
||||
from radicale.storage import filesystem
|
||||
filesystem.FOLDER = self.colpath
|
||||
filesystem.GIT_REPOSITORY = None
|
||||
self.application = radicale.Application()
|
||||
|
||||
def teardown(self):
|
||||
"""Teardown function for each test."""
|
||||
shutil.rmtree(self.colpath)
|
||||
|
||||
|
||||
class TestMultiFileSystem(TestFileSystem):
|
||||
"""Base class for multifilesystem tests."""
|
||||
storage_type = "multifilesystem"
|
||||
|
||||
|
||||
class TestDataBaseSystem(BaseRequests, BaseTest):
|
||||
"""Base class for database tests"""
|
||||
def setup(self):
|
||||
config.set("storage", "type", "database")
|
||||
config.set("storage", "database_url", "sqlite://")
|
||||
from radicale.storage import database
|
||||
database.Session = sessionmaker()
|
||||
database.Session.configure(bind=create_engine("sqlite://"))
|
||||
session = database.Session()
|
||||
for st in get_file_content("schema.sql").split(";"):
|
||||
session.execute(st)
|
||||
session.commit()
|
||||
self.application = radicale.Application()
|
||||
|
||||
|
||||
class TestGitFileSystem(TestFileSystem):
|
||||
"""Base class for filesystem tests using Git"""
|
||||
def setup(self):
|
||||
super(TestGitFileSystem, self).setup()
|
||||
Repo.init(self.colpath)
|
||||
from radicale.storage import filesystem
|
||||
filesystem.GIT_REPOSITORY = Repo(self.colpath)
|
||||
|
||||
|
||||
class TestGitMultiFileSystem(TestGitFileSystem, TestMultiFileSystem):
|
||||
"""Base class for multifilesystem tests using Git"""
|
||||
|
||||
|
||||
class TestCustomStorageSystem(BaseRequests, 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)
|
Loading…
Reference in New Issue
Block a user