mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
More tests and more coverage
This commit is contained in:
parent
91a631fb5a
commit
15658b1f31
3 changed files with 57 additions and 5 deletions
|
|
@ -6,10 +6,60 @@
|
||||||
:copyright: (c) 2014 Markus Unterwaditzer
|
:copyright: (c) 2014 Markus Unterwaditzer
|
||||||
:license: MIT, see LICENSE for more details.
|
:license: MIT, see LICENSE for more details.
|
||||||
'''
|
'''
|
||||||
|
from textwrap import dedent
|
||||||
|
|
||||||
import vdirsyncer.cli as cli
|
import vdirsyncer.cli as cli
|
||||||
import vdirsyncer.exceptions as exceptions
|
import vdirsyncer.exceptions as exceptions
|
||||||
|
|
||||||
|
def test_load_config(tmpdir, monkeypatch):
|
||||||
|
f = tmpdir.join('test.cfg')
|
||||||
|
f.write(dedent('''
|
||||||
|
[general]
|
||||||
|
status_path = ~/.vdirsyncer/status/
|
||||||
|
foo = 1
|
||||||
|
|
||||||
class TestCli(object):
|
[pair bob]
|
||||||
pass
|
a = bob_a
|
||||||
|
b = bob_b
|
||||||
|
foo = bar
|
||||||
|
bam = true
|
||||||
|
|
||||||
|
[storage bob_a]
|
||||||
|
type = filesystem
|
||||||
|
path = ~/.contacts/
|
||||||
|
fileext = .vcf
|
||||||
|
yesno = off
|
||||||
|
number = 42
|
||||||
|
|
||||||
|
[storage bob_b]
|
||||||
|
type = carddav
|
||||||
|
|
||||||
|
[bogus]
|
||||||
|
lol = true
|
||||||
|
''').strip())
|
||||||
|
|
||||||
|
fname = str(tmpdir) + '/test.cfg'
|
||||||
|
errors = []
|
||||||
|
monkeypatch.setattr('vdirsyncer.cli.cli_logger.error', errors.append)
|
||||||
|
general, pairs, storages = cli.load_config(fname, pair_options=('bam',))
|
||||||
|
assert general == {'foo': 1, 'status_path': '~/.vdirsyncer/status/'}
|
||||||
|
assert pairs == {'bob': ('bob_a', 'bob_b', {'bam': True}, {'foo': 'bar'})}
|
||||||
|
assert storages == {
|
||||||
|
'bob_a': {'type': 'filesystem', 'path': '~/.contacts/',
|
||||||
|
'fileext': '.vcf', 'yesno': False, 'number': 42},
|
||||||
|
'bob_b': {'type': 'carddav'}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert len(errors) == 1
|
||||||
|
assert errors[0].startswith('Unknown section')
|
||||||
|
assert 'bogus' in errors[0]
|
||||||
|
|
||||||
|
def test_storage_instance_from_config(monkeypatch):
|
||||||
|
def lol(**kw):
|
||||||
|
assert kw == {'foo': 'bar', 'baz': 1}
|
||||||
|
return 'OK'
|
||||||
|
|
||||||
|
import vdirsyncer.storage
|
||||||
|
monkeypatch.setitem(vdirsyncer.storage.storage_names, 'lol', lol)
|
||||||
|
config = {'type': 'lol', 'foo': 'bar', 'baz': 1}
|
||||||
|
assert cli.storage_instance_from_config(config) == 'OK'
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import vdirsyncer.utils as utils
|
||||||
def test_parse_options():
|
def test_parse_options():
|
||||||
o = {
|
o = {
|
||||||
'foo': 'yes',
|
'foo': 'yes',
|
||||||
|
'hah': 'true',
|
||||||
'bar': '',
|
'bar': '',
|
||||||
'baz': 'whatever',
|
'baz': 'whatever',
|
||||||
'bam': '123',
|
'bam': '123',
|
||||||
|
|
@ -22,6 +23,7 @@ def test_parse_options():
|
||||||
|
|
||||||
assert dict(utils.parse_options(o.items())) == {
|
assert dict(utils.parse_options(o.items())) == {
|
||||||
'foo': True,
|
'foo': True,
|
||||||
|
'hah': True,
|
||||||
'bar': '',
|
'bar': '',
|
||||||
'baz': 'whatever',
|
'baz': 'whatever',
|
||||||
'bam': 123,
|
'bam': 123,
|
||||||
|
|
|
||||||
|
|
@ -67,10 +67,10 @@ def get_password(username, resource):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import getpass
|
import getpass
|
||||||
try:
|
try: # pragma: no cover
|
||||||
from urlparse import urlsplit, urlunsplit
|
|
||||||
except ImportError:
|
|
||||||
from urllib.parse import urlsplit, urlunsplit
|
from urllib.parse import urlsplit, urlunsplit
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from urlparse import urlsplit, urlunsplit
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import keyring
|
import keyring
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue