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.4
- 3.5 - 3.5
install:
- pip install sqlalchemy
- pip install nose-cov
- pip install pam
- pip install requests
- pip install dulwich
script: nosetests script: nosetests
sudo: false sudo: false

View File

@ -381,13 +381,7 @@ class Application(object):
def do_GET(self, environ, read_collections, write_collections, content, def do_GET(self, environ, read_collections, write_collections, content,
user): user):
"""Manage GET request. """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.
"""
# Display a "Radicale works!" message if the root URL is requested # Display a "Radicale works!" message if the root URL is requested
if environ["PATH_INFO"] == "/": if environ["PATH_INFO"] == "/":
headers = {"Content-type": "text/html"} headers = {"Content-type": "text/html"}

View File

@ -123,7 +123,7 @@ class Collection(ical.Collection):
filenames = os.listdir(self._filesystem_path) filenames = os.listdir(self._filesystem_path)
except (OSError, IOError) as e: except (OSError, IOError) as e:
log.LOGGER.info( log.LOGGER.info(
'Error while reading collection %r: %r' % ( "Error while reading collection %r: %r" % (
self._filesystem_path, e)) self._filesystem_path, e))
return "" return ""
@ -134,7 +134,7 @@ class Collection(ical.Collection):
items.update(self._parse(fd.read(), components)) items.update(self._parse(fd.read(), components))
except (OSError, IOError) as e: except (OSError, IOError) as e:
log.LOGGER.warning( log.LOGGER.warning(
'Error while reading item %r: %r' % (path, e)) "Error while reading item %r: %r" % (path, e))
return ical.serialize( return ical.serialize(
self.tag, self.headers, sorted(items.values(), key=lambda x: x.name)) 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): def is_leaf(cls, path):
filesystem_path = pathutils.path_to_filesystem(path, FOLDER) filesystem_path = pathutils.path_to_filesystem(path, FOLDER)
return ( 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 @property
def last_modified(self): 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): class Collection(storage.Collection):
"""Collection stored in a flat ical file.""" """Collection stored in a folder."""

View File

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

View File

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