mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
More tests
I was bored
This commit is contained in:
parent
cdae049df2
commit
8db16454f8
6 changed files with 75 additions and 15 deletions
|
|
@ -58,3 +58,20 @@ class CaldavStorageTests(TestCase, DavStorageTests):
|
||||||
href_etag_task,
|
href_etag_task,
|
||||||
href_etag_event
|
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
16
tests/test_cli.py
Normal 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
27
tests/test_utils.py
Normal 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
|
||||||
|
}
|
||||||
|
|
@ -12,7 +12,7 @@ import sys
|
||||||
import json
|
import json
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
from vdirsyncer.sync import sync
|
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
|
from vdirsyncer.storage import storage_names
|
||||||
import vdirsyncer.log as log
|
import vdirsyncer.log as log
|
||||||
import argvard
|
import argvard
|
||||||
|
|
@ -21,19 +21,6 @@ import argvard
|
||||||
cli_logger = log.get('cli')
|
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')):
|
def load_config(fname, pair_options=('collections', 'conflict_resolution')):
|
||||||
c = ConfigParser.RawConfigParser()
|
c = ConfigParser.RawConfigParser()
|
||||||
c.read(fname)
|
c.read(fname)
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ class CaldavStorage(DavStorage):
|
||||||
super(CaldavStorage, self).__init__(**kwargs)
|
super(CaldavStorage, self).__init__(**kwargs)
|
||||||
if isinstance(item_types, str):
|
if isinstance(item_types, str):
|
||||||
item_types = [x.strip() for x in item_types.split(',')]
|
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):
|
if (start_date is None) != (end_date is None):
|
||||||
raise ValueError('If start_date is given, '
|
raise ValueError('If start_date is given, '
|
||||||
'end_date has to be given too.')
|
'end_date has to be given too.')
|
||||||
|
|
|
||||||
|
|
@ -26,3 +26,16 @@ def split_dict(d, f):
|
||||||
b[k] = v
|
b[k] = v
|
||||||
|
|
||||||
return a, b
|
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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue