Clean tests

This commit is contained in:
Guillaume Ayoub
2016-04-07 19:25:10 +02:00
parent 595e2329ea
commit 54dee0c7c4
6 changed files with 25 additions and 76 deletions

View File

@ -21,8 +21,8 @@ Copy of filesystem storage backend for testing
"""
from radicale.storage import filesystem
from radicale import storage
class Collection(filesystem.Collection):
"""Collection stored in a flat ical file."""
class Collection(storage.Collection):
"""Collection stored in a folder."""

View File

@ -26,8 +26,7 @@ import os
import radicale
import tempfile
from radicale import config
from radicale.auth import htpasswd
from radicale import config, auth
from . import BaseTest
@ -55,8 +54,8 @@ class TestBaseAuthRequests(BaseTest):
hashlib.sha1(b"bepo").digest()))
config.set("auth", "type", "htpasswd")
htpasswd.FILENAME = htpasswd_file_path
htpasswd.ENCRYPTION = "sha1"
auth.FILENAME = htpasswd_file_path
auth.ENCRYPTION = "sha1"
self.application = radicale.Application()
@ -67,8 +66,7 @@ class TestBaseAuthRequests(BaseTest):
def test_custom(self):
"""Custom authentication."""
config.set("auth", "type", "custom")
config.set("auth", "custom_handler", "tests.custom.auth")
config.set("auth", "type", "tests.custom.auth")
self.application = radicale.Application()
status, headers, answer = self.request(
"GET", "/", HTTP_AUTHORIZATION=self.userpass)

View File

@ -23,10 +23,6 @@ import radicale
import shutil
import tempfile
from dulwich.repo import Repo
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from . import BaseTest
from .helpers import get_file_content
@ -44,15 +40,16 @@ class BaseRequests(object):
assert status == 200
assert "Radicale works!" in answer
# Test the creation of the collection
self.request(
"PUT", "/calendar.ics/", "BEGIN:VCALENDAR\r\nEND:VCALENDAR")
status, headers, answer = self.request("GET", "/calendar.ics/")
assert "BEGIN:VCALENDAR" in answer
#assert "VERSION:2.0" in answer
assert "END:VCALENDAR" in answer
#assert "PRODID:-//Radicale//NONSGML Radicale Server//EN" in answer
def test_add_event(self):
"""Add an event."""
self.request("GET", "/calendar.ics/")
self.request(
"PUT", "/calendar.ics/", "BEGIN:VCALENDAR\r\nEND:VCALENDAR")
event = get_file_content("event.ics")
path = "/calendar.ics/event.ics"
status, headers, answer = self.request("PUT", path, event)
@ -66,7 +63,8 @@ class BaseRequests(object):
def test_add_todo(self):
"""Add a todo."""
self.request("GET", "/calendar.ics/")
self.request(
"PUT", "/calendar.ics/", "BEGIN:VCALENDAR\r\nEND:VCALENDAR")
todo = get_file_content("todo.ics")
path = "/calendar.ics/todo.ics"
status, headers, answer = self.request("PUT", path, todo)
@ -79,7 +77,8 @@ class BaseRequests(object):
def test_delete(self):
"""Delete an event."""
self.request("GET", "/calendar.ics/")
self.request(
"PUT", "/calendar.ics/", "BEGIN:VCALENDAR\r\nEND:VCALENDAR")
event = get_file_content("event.ics")
path = "/calendar.ics/event.ics"
status, headers, answer = self.request("PUT", path, event)
@ -91,16 +90,15 @@ class BaseRequests(object):
assert "VEVENT" not in answer
class TestFileSystem(BaseRequests, BaseTest):
class TestMultiFileSystem(BaseRequests, BaseTest):
"""Base class for filesystem tests."""
storage_type = "filesystem"
storage_type = "multifilesystem"
def setup(self):
"""Setup function for each test."""
self.colpath = tempfile.mkdtemp()
from radicale.storage import filesystem
filesystem.FOLDER = self.colpath
filesystem.GIT_REPOSITORY = None
from radicale import storage
storage.FOLDER = self.colpath
self.application = radicale.Application()
def teardown(self):
@ -108,40 +106,6 @@ class TestFileSystem(BaseRequests, BaseTest):
shutil.rmtree(self.colpath)
class TestMultiFileSystem(TestFileSystem):
"""Base class for multifilesystem tests."""
storage_type = "multifilesystem"
class TestDataBaseSystem(BaseRequests, BaseTest):
"""Base class for database tests"""
storage_type = "database"
def setup(self):
super().setup()
radicale.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().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"
@ -150,8 +114,7 @@ class TestCustomStorageSystem(BaseRequests, BaseTest):
"""Setup function for each test."""
super().setup()
self.colpath = tempfile.mkdtemp()
radicale.config.set(
"storage", "custom_handler", "tests.custom.storage")
radicale.config.set("storage", "type", "tests.custom.storage")
from tests.custom import storage
storage.FOLDER = self.colpath
storage.GIT_REPOSITORY = None