How to use the vdirsyncer.exceptions function in vdirsyncer

To help you get started, we’ve selected a few vdirsyncer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pimutils / vdirsyncer / tests / unit / cli / test_fetchparams.py View on Github external
def test_unknown_strategy():
    with pytest.raises(exceptions.UserError) as excinfo:
        expand_fetch_params({
            'foo.fetch': ['unreal', 'asdf']
        })

    assert 'Unknown strategy' in str(excinfo.value)
github pimutils / vdirsyncer / tests / storage / __init__.py View on Github external
def test_upload_already_existing(self, s, get_item):
        item = get_item()
        s.upload(item)
        with pytest.raises(exceptions.PreconditionFailed):
            s.upload(item)
github pimutils / vdirsyncer / tests / unit / cli / test_fetchparams.py View on Github external
def test_empty_value(monkeypatch, mystrategy):
    with pytest.raises(exceptions.UserError) as excinfo:
        expand_fetch_params({
            'foo.fetch': ['mystrategy', '']
        })

    assert 'Empty value for foo.fetch, this most likely indicates an error' \
        in str(excinfo.value)
github pimutils / vdirsyncer / tests / unit / test_exceptions.py View on Github external
def test_user_error_problems():
    e = exceptions.UserError('A few problems occurred', problems=[
        'Problem one',
        'Problem two',
        'Problem three'
    ])

    assert 'one' in str(e)
    assert 'two' in str(e)
    assert 'three' in str(e)
    assert 'problems occurred' in str(e)
github pimutils / vdirsyncer / tests / system / cli / test_config.py View on Github external
def test_missing_collections_param(read_config):
    with pytest.raises(exceptions.UserError) as excinfo:
        read_config('''
            [general]
            status_path = "/tmp/status/"

            [pair bob]
            a = "bob_a"
            b = "bob_b"

            [storage bob_a]
            type = "lmao"

            [storage bob_b]
            type = "lmao"
            ''')

    assert 'collections parameter missing' in str(excinfo.value)
github pimutils / vdirsyncer / vdirsyncer / storage / filesystem.py View on Github external
def delete(self, href, etag):
        fpath = self._get_filepath(href)
        if not os.path.isfile(fpath):
            raise exceptions.NotFoundError(href)
        actual_etag = get_etag_from_file(fpath)
        if etag != actual_etag:
            raise exceptions.WrongEtagError(etag, actual_etag)
        os.remove(fpath)
github pimutils / vdirsyncer / vdirsyncer / storage / olddav.py View on Github external
def __init__(self, start_date=None, end_date=None,
                 item_types=(), **kwargs):
        super(CalDAVStorage, self).__init__(**kwargs)
        if not isinstance(item_types, (list, tuple)):
            raise exceptions.UserError('item_types must be a list.')

        self.item_types = tuple(item_types)
        if (start_date is None) != (end_date is None):
            raise exceptions.UserError('If start_date is given, '
                                       'end_date has to be given too.')
        elif start_date is not None and end_date is not None:
            namespace = dict(datetime.__dict__)
            namespace['start_date'] = self.start_date = \
                (eval(start_date, namespace)
                 if isinstance(start_date, (bytes, str))
                 else start_date)
            self.end_date = \
                (eval(end_date, namespace)
                 if isinstance(end_date, (bytes, str))
                 else end_date)
github pimutils / vdirsyncer / vdirsyncer / storage / dav.py View on Github external
def get_multi(self, hrefs):
        hrefs = set(hrefs)
        href_xml = []
        for href in hrefs:
            if href != self._normalize_href(href):
                raise exceptions.NotFoundError(href)
            href_xml.append('{}'.format(href))
        if not href_xml:
            return ()

        data = self.get_multi_template \
            .format(hrefs='\n'.join(href_xml)).encode('utf-8')
        response = self.session.request(
            'REPORT',
            '',
            data=data,
            headers=self.session.get_default_headers()
        )
        root = _parse_xml(response.content)  # etree only can handle bytes
        rv = []
        hrefs_left = set(hrefs)
        for href, etag, prop in self._parse_prop_responses(root):
github pimutils / vdirsyncer / vdirsyncer / native.py View on Github external
def check_error(e):
    try:
        errors.check_exception(e[0])
    except errors.Error.ItemNotFound as e:
        raise exceptions.NotFoundError(e) from e
    except errors.Error.ItemAlreadyExisting as e:
        raise exceptions.AlreadyExistingError(e) from e
    except errors.Error.WrongEtag as e:
        raise exceptions.WrongEtagError(e) from e
    except errors.Error.ReadOnly as e:
        raise exceptions.ReadOnlyError(e) from e
    except errors.Error.UnsupportedVobject as e:
        raise exceptions.UnsupportedVobjectError(e) from e
    except (errors.Error.BadDiscoveryConfig,
            errors.Error.BadCollectionConfig) as e:
        raise TypeError(e) from e
    except errors.Error.MetadataValueUnsupported as e:
        raise exceptions.UnsupportedMetadataError(e) from e