From aa7d2f3eeb821bcefd1c73f753037b44ee1df6da Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Sat, 1 Mar 2014 21:36:01 +0100 Subject: [PATCH] Restructuring of DAV storage We will need this when writing CarddavStorage, assuming we can share much code between them. --- vdirsyncer/cli.py | 9 +------ vdirsyncer/storage/__init__.py | 8 +++++++ vdirsyncer/storage/dav/__init__.py | 8 +++++++ vdirsyncer/storage/{ => dav}/caldav.py | 4 ++-- .../{test_caldav.py => dav/__init__.py} | 19 +++++++-------- vdirsyncer/tests/storage/dav/test_caldav.py | 24 +++++++++++++++++++ 6 files changed, 52 insertions(+), 20 deletions(-) create mode 100644 vdirsyncer/storage/dav/__init__.py rename vdirsyncer/storage/{ => dav}/caldav.py (99%) rename vdirsyncer/tests/storage/{test_caldav.py => dav/__init__.py} (83%) create mode 100644 vdirsyncer/tests/storage/dav/test_caldav.py diff --git a/vdirsyncer/cli.py b/vdirsyncer/cli.py index 243ea46..367389e 100644 --- a/vdirsyncer/cli.py +++ b/vdirsyncer/cli.py @@ -12,9 +12,8 @@ import sys import json import ConfigParser from vdirsyncer.sync import sync -from vdirsyncer.storage.caldav import CaldavStorage -from vdirsyncer.storage.filesystem import FilesystemStorage from vdirsyncer.utils import expand_path +from vdirsyncer.storage import storage_names import vdirsyncer.log as log import argvard @@ -22,12 +21,6 @@ import argvard cli_logger = log.get('cli') -storage_names = { - 'caldav': CaldavStorage, - 'filesystem': FilesystemStorage -} - - def parse_options(items): for key, value in items: if value.lower() in ('yes', 'true', 'on'): diff --git a/vdirsyncer/storage/__init__.py b/vdirsyncer/storage/__init__.py index ad3a5b4..7b23370 100644 --- a/vdirsyncer/storage/__init__.py +++ b/vdirsyncer/storage/__init__.py @@ -11,3 +11,11 @@ :copyright: (c) 2014 Markus Unterwaditzer :license: MIT, see LICENSE for more details. ''' + +from .dav.caldav import CaldavStorage +from .filesystem import FilesystemStorage + +storage_names = { + 'caldav': CaldavStorage, + 'filesystem': FilesystemStorage +} diff --git a/vdirsyncer/storage/dav/__init__.py b/vdirsyncer/storage/dav/__init__.py new file mode 100644 index 0000000..dd12acd --- /dev/null +++ b/vdirsyncer/storage/dav/__init__.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +''' + vdirsyncer.storage.dav + ~~~~~~~~~~~~~~~~~~~~~~ + + :copyright: (c) 2014 Markus Unterwaditzer + :license: MIT, see LICENSE for more details. +''' diff --git a/vdirsyncer/storage/caldav.py b/vdirsyncer/storage/dav/caldav.py similarity index 99% rename from vdirsyncer/storage/caldav.py rename to vdirsyncer/storage/dav/caldav.py index 3eb72d3..42d2af3 100644 --- a/vdirsyncer/storage/caldav.py +++ b/vdirsyncer/storage/dav/caldav.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ''' - vdirsyncer.storage.caldav + vdirsyncer.storage.dav.caldav ~~~~~~~~~~~~~~~~~~~~~~~~~ Original version from khal: https://github.com/geier/khal @@ -9,7 +9,7 @@ :license: MIT, see LICENSE for more details. ''' -from .base import Storage, Item +from ..base import Storage, Item import vdirsyncer.exceptions as exceptions from lxml import etree import requests diff --git a/vdirsyncer/tests/storage/test_caldav.py b/vdirsyncer/tests/storage/dav/__init__.py similarity index 83% rename from vdirsyncer/tests/storage/test_caldav.py rename to vdirsyncer/tests/storage/dav/__init__.py index 2551a2b..e13d7f7 100644 --- a/vdirsyncer/tests/storage/test_caldav.py +++ b/vdirsyncer/tests/storage/dav/__init__.py @@ -1,20 +1,19 @@ # -*- coding: utf-8 -*- ''' - vdirsyncer.tests.storage.test_caldav + vdirsyncer.tests.storage.dav ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Using an actual CalDAV server to test the CalDAV storage. Done by using - Werkzeug's test client for WSGI apps. While this is pretty fast, Radicale - has so much global state such that a clean separation of the unit tests is - not guaranteed. + Using an actual CalDAV/CardDAV server to test the CalDAV and CardDAV + storages. Done by using Werkzeug's test client for WSGI apps. While this is + pretty fast, Radicale has so much global state such that a clean separation + of the unit tests is not easy. :copyright: (c) 2014 Markus Unterwaditzer :license: MIT, see LICENSE for more details. ''' __version__ = '0.1.0' -from unittest import TestCase import tempfile import shutil import sys @@ -23,8 +22,7 @@ import os from werkzeug.test import Client from werkzeug.wrappers import BaseResponse as WerkzeugResponse -from vdirsyncer.storage.caldav import CaldavStorage -from . import StorageTests +from .. import StorageTests def do_the_radicale_dance(tmpdir): @@ -69,8 +67,9 @@ class Response(object): raise HTTPError(str(self.status_code)) -class CaldavStorageTests(TestCase, StorageTests): +class DavStorageTests(StorageTests): tmpdir = None + storage_class = None def _get_storage(self, **kwargs): self.tmpdir = tempfile.mkdtemp() @@ -90,7 +89,7 @@ class CaldavStorageTests(TestCase, StorageTests): r = c.open(path=url, method=method, data=data, headers=headers) r = Response(r) return r - return CaldavStorage(full_url, _request_func=x) + return self.storage_class(url=full_url, _request_func=x, **kwargs) def tearDown(self): self.app = None diff --git a/vdirsyncer/tests/storage/dav/test_caldav.py b/vdirsyncer/tests/storage/dav/test_caldav.py new file mode 100644 index 0000000..decf49a --- /dev/null +++ b/vdirsyncer/tests/storage/dav/test_caldav.py @@ -0,0 +1,24 @@ + +# -*- coding: utf-8 -*- +''' + vdirsyncer.tests.storage.test_caldav + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + Using an actual CalDAV server to test the CalDAV storage. Done by using + Werkzeug's test client for WSGI apps. While this is pretty fast, Radicale + has so much global state such that a clean separation of the unit tests is + not guaranteed. + + :copyright: (c) 2014 Markus Unterwaditzer + :license: MIT, see LICENSE for more details. +''' +__version__ = '0.1.0' + +from unittest import TestCase + +from vdirsyncer.storage.caldav import CaldavStorage +from . import DavStorageTests + + +class CaldavStorageTests(TestCase, DavStorageTests): + storage_class = CaldavStorage