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

@ -5,13 +5,6 @@ python:
- 3.4
- 3.5
install:
- pip install sqlalchemy
- pip install nose-cov
- pip install pam
- pip install requests
- pip install dulwich
script: nosetests
sudo: false

View File

@ -381,13 +381,7 @@ class Application(object):
def do_GET(self, environ, read_collections, write_collections, content,
user):
"""Manage GET request.
In Radicale, GET requests create collections when the URL is not
available. This is useful for clients with no MKCOL or MKCALENDAR
support.
"""
"""Manage GET request."""
# Display a "Radicale works!" message if the root URL is requested
if environ["PATH_INFO"] == "/":
headers = {"Content-type": "text/html"}

View File

@ -123,7 +123,7 @@ class Collection(ical.Collection):
filenames = os.listdir(self._filesystem_path)
except (OSError, IOError) as e:
log.LOGGER.info(
'Error while reading collection %r: %r' % (
"Error while reading collection %r: %r" % (
self._filesystem_path, e))
return ""
@ -134,7 +134,7 @@ class Collection(ical.Collection):
items.update(self._parse(fd.read(), components))
except (OSError, IOError) as e:
log.LOGGER.warning(
'Error while reading item %r: %r' % (path, e))
"Error while reading item %r: %r" % (path, e))
return ical.serialize(
self.tag, self.headers, sorted(items.values(), key=lambda x: x.name))
@ -164,7 +164,8 @@ class Collection(ical.Collection):
def is_leaf(cls, path):
filesystem_path = pathutils.path_to_filesystem(path, FOLDER)
return (
os.path.isdir(filesystem_path) and os.path.exists(path + ".props"))
os.path.isdir(filesystem_path) and
os.path.exists(filesystem_path + ".props"))
@property
def last_modified(self):

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