From 8db16454f8db4f7f1ef15bf63afb22b1c5852113 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Thu, 13 Mar 2014 16:03:32 +0100 Subject: [PATCH] More tests I was bored --- tests/storage/dav/test_caldav.py | 17 +++++++++++++++++ tests/test_cli.py | 16 ++++++++++++++++ tests/test_utils.py | 27 +++++++++++++++++++++++++++ vdirsyncer/cli.py | 15 +-------------- vdirsyncer/storage/dav/caldav.py | 2 +- vdirsyncer/utils.py | 13 +++++++++++++ 6 files changed, 75 insertions(+), 15 deletions(-) create mode 100644 tests/test_cli.py create mode 100644 tests/test_utils.py diff --git a/tests/storage/dav/test_caldav.py b/tests/storage/dav/test_caldav.py index ee1eee7..32cac4e 100644 --- a/tests/storage/dav/test_caldav.py +++ b/tests/storage/dav/test_caldav.py @@ -58,3 +58,20 @@ class CaldavStorageTests(TestCase, DavStorageTests): href_etag_task, href_etag_event ]) + + def test_item_types(self): + kw = self.get_storage_args() + s = self.storage_class(item_types=('VTODO',), **kw) + s.upload(self._create_bogus_item(1, item_template=EVENT_TEMPLATE)) + s.upload(self._create_bogus_item(5, item_template=EVENT_TEMPLATE)) + href, etag = \ + s.upload(self._create_bogus_item(3, item_template=TASK_TEMPLATE)) + ((href2, etag2),) = s.list() + assert href2 == href + assert etag2 == etag + + def test_item_types_passed_as_string(self): + kw = self.get_storage_args() + a = self.storage_class(item_types='VTODO,VEVENT', **kw) + b = self.storage_class(item_types=('VTODO', 'VEVENT'), **kw) + assert a.item_types == b.item_types == ('VTODO', 'VEVENT') diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 0000000..2097521 --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +''' + vdirsyncer.tests.test_cli + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + + :copyright: (c) 2014 Markus Unterwaditzer + :license: MIT, see LICENSE for more details. +''' + +from unittest import TestCase +import vdirsyncer.cli as cli +import vdirsyncer.exceptions as exceptions + + +class CliTests(TestCase): + pass diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 0000000..89b4837 --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +''' + vdirsyncer.tests.test_utils + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + :copyright: (c) 2014 Markus Unterwaditzer + :license: MIT, see LICENSE for more details. +''' + +import vdirsyncer.utils as utils + +def test_parse_options(): + o = { + 'foo': 'yes', + 'bar': '', + 'baz': 'whatever', + 'bam': '123', + 'asd': 'off' + } + + assert dict(utils.parse_options(o.items())) == { + 'foo': True, + 'bar': '', + 'baz': 'whatever', + 'bam': 123, + 'asd': False + } diff --git a/vdirsyncer/cli.py b/vdirsyncer/cli.py index c7c6284..bb763c2 100644 --- a/vdirsyncer/cli.py +++ b/vdirsyncer/cli.py @@ -12,7 +12,7 @@ import sys import json import ConfigParser from vdirsyncer.sync import sync -from vdirsyncer.utils import expand_path, split_dict +from vdirsyncer.utils import expand_path, split_dict, parse_options from vdirsyncer.storage import storage_names import vdirsyncer.log as log import argvard @@ -21,19 +21,6 @@ import argvard cli_logger = log.get('cli') -def parse_options(items): - for key, value in items: - if value.lower() in ('yes', 'true', 'on'): - value = True - elif value.lower() in ('no', 'false', 'off'): - value = False - try: - value = int(value) - except ValueError: - pass - yield key, value - - def load_config(fname, pair_options=('collections', 'conflict_resolution')): c = ConfigParser.RawConfigParser() c.read(fname) diff --git a/vdirsyncer/storage/dav/caldav.py b/vdirsyncer/storage/dav/caldav.py index 7df8c4e..90a6306 100644 --- a/vdirsyncer/storage/dav/caldav.py +++ b/vdirsyncer/storage/dav/caldav.py @@ -51,7 +51,7 @@ class CaldavStorage(DavStorage): super(CaldavStorage, self).__init__(**kwargs) if isinstance(item_types, str): item_types = [x.strip() for x in item_types.split(',')] - self.item_types = item_types + self.item_types = tuple(item_types) if (start_date is None) != (end_date is None): raise ValueError('If start_date is given, ' 'end_date has to be given too.') diff --git a/vdirsyncer/utils.py b/vdirsyncer/utils.py index 463d8ae..152eae1 100644 --- a/vdirsyncer/utils.py +++ b/vdirsyncer/utils.py @@ -26,3 +26,16 @@ def split_dict(d, f): b[k] = v return a, b + + +def parse_options(items): + for key, value in items: + if value.lower() in ('yes', 'true', 'on'): + value = True + elif value.lower() in ('no', 'false', 'off'): + value = False + try: + value = int(value) + except ValueError: + pass + yield key, value