More tests

I was bored
This commit is contained in:
Markus Unterwaditzer 2014-03-13 16:03:32 +01:00
parent cdae049df2
commit 8db16454f8
6 changed files with 75 additions and 15 deletions

View file

@ -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')

16
tests/test_cli.py Normal file
View file

@ -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

27
tests/test_utils.py Normal file
View file

@ -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
}

View file

@ -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)

View file

@ -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.')

View file

@ -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