File: test_repair.py

package info (click to toggle)
vdirsyncer 0.14.1-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 848 kB
  • sloc: python: 6,664; makefile: 243; sh: 59
file content (38 lines) | stat: -rw-r--r-- 1,099 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# encoding: utf-8

from textwrap import dedent

import pytest


@pytest.mark.parametrize('collection', [None, "foocoll"])
def test_full(tmpdir, runner, collection):
    runner.write_with_general(dedent('''
        [storage foo]
        type = "filesystem"
        path = "{base}/foo/"
        fileext = ".txt"
        ''').format(base=str(tmpdir)))

    storage = tmpdir.mkdir('foo')
    if collection is not None:
        storage = storage.mkdir(collection)
        collection_arg = 'foo/{}'.format(collection)
    else:
        collection_arg = 'foo'

    argv = ['repair', collection_arg]

    result = runner.invoke(argv, input='y')
    assert not result.exception

    storage.join('item.txt').write('BEGIN:VCARD\nEND:VCARD')
    storage.join('toobroken.txt').write('')

    result = runner.invoke(argv, input='y')
    assert not result.exception
    assert 'No UID' in result.output
    assert 'warning: Item toobroken.txt can\'t be parsed, skipping' \
        in result.output
    new_fname, = [x for x in storage.listdir() if 'toobroken' not in str(x)]
    assert 'UID:' in new_fname.read()