mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
More tests
This commit is contained in:
parent
1050a4e157
commit
2156051056
2 changed files with 48 additions and 0 deletions
|
|
@ -48,6 +48,10 @@ class StorageTests(object):
|
||||||
assert etag == etag2
|
assert etag == etag2
|
||||||
assert 'UID:{}'.format(item.uid) in item.raw
|
assert 'UID:{}'.format(item.uid) in item.raw
|
||||||
|
|
||||||
|
def test_empty_get_multi(self):
|
||||||
|
s = self._get_storage()
|
||||||
|
assert list(s.get_multi([])) == []
|
||||||
|
|
||||||
def test_upload_already_existing(self):
|
def test_upload_already_existing(self):
|
||||||
s = self._get_storage()
|
s = self._get_storage()
|
||||||
item = self._create_bogus_item(1)
|
item = self._create_bogus_item(1)
|
||||||
|
|
@ -88,6 +92,12 @@ class StorageTests(object):
|
||||||
with pytest.raises(exceptions.PreconditionFailed):
|
with pytest.raises(exceptions.PreconditionFailed):
|
||||||
s.delete(href, '"lolnope"')
|
s.delete(href, '"lolnope"')
|
||||||
|
|
||||||
|
def test_delete(self):
|
||||||
|
s = self._get_storage()
|
||||||
|
href, etag = s.upload(self._create_bogus_item(1))
|
||||||
|
s.delete(href, etag)
|
||||||
|
assert not list(s.list())
|
||||||
|
|
||||||
def test_delete_nonexisting(self):
|
def test_delete_nonexisting(self):
|
||||||
s = self._get_storage()
|
s = self._get_storage()
|
||||||
with pytest.raises(exceptions.PreconditionFailed):
|
with pytest.raises(exceptions.PreconditionFailed):
|
||||||
|
|
@ -146,3 +156,9 @@ class StorageTests(object):
|
||||||
# Can't do stronger assertion because of radicale, which needs a
|
# Can't do stronger assertion because of radicale, which needs a
|
||||||
# fileextension to guess the collection type.
|
# fileextension to guess the collection type.
|
||||||
assert 'test2' in s.collection
|
assert 'test2' in s.collection
|
||||||
|
|
||||||
|
def test_has(self):
|
||||||
|
s = self._get_storage()
|
||||||
|
assert not s.has('asd')
|
||||||
|
href, etag = s.upload(self._create_bogus_item(1))
|
||||||
|
assert s.has(href)
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@ from .. import StorageTests
|
||||||
import vdirsyncer.exceptions as exceptions
|
import vdirsyncer.exceptions as exceptions
|
||||||
from vdirsyncer.storage.base import Item
|
from vdirsyncer.storage.base import Item
|
||||||
from vdirsyncer.storage.dav import CaldavStorage, CarddavStorage
|
from vdirsyncer.storage.dav import CaldavStorage, CarddavStorage
|
||||||
|
import vdirsyncer.exceptions
|
||||||
|
import requests
|
||||||
import requests.exceptions
|
import requests.exceptions
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -209,6 +211,36 @@ class TestCaldavStorage(DavStorageTests):
|
||||||
b = 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')
|
assert a.item_types == b.item_types == ('VTODO', 'VEVENT')
|
||||||
|
|
||||||
|
def test_invalid_resource(self, monkeypatch):
|
||||||
|
calls = []
|
||||||
|
args = self.get_storage_args(collection=None)
|
||||||
|
|
||||||
|
def request(session, method, url, data=None, headers=None, auth=None,
|
||||||
|
verify=None):
|
||||||
|
assert method == 'OPTIONS'
|
||||||
|
assert url == args['url']
|
||||||
|
calls.append(None)
|
||||||
|
|
||||||
|
r = requests.Response()
|
||||||
|
r.status_code = 200
|
||||||
|
r._content = 'Hello World.'
|
||||||
|
return r
|
||||||
|
|
||||||
|
monkeypatch.setattr('requests.sessions.Session.request', request)
|
||||||
|
|
||||||
|
with pytest.raises(vdirsyncer.exceptions.StorageError):
|
||||||
|
s = self.storage_class(**args)
|
||||||
|
assert len(calls) == 1
|
||||||
|
|
||||||
|
def test_empty_get_multi_performance(self, monkeypatch):
|
||||||
|
s = self._get_storage()
|
||||||
|
|
||||||
|
def breakdown(*a, **kw):
|
||||||
|
raise AssertionError('Expected not to be called.')
|
||||||
|
|
||||||
|
monkeypatch.setattr('requests.sessions.Session.request', breakdown)
|
||||||
|
|
||||||
|
assert list(s.get_multi([])) == []
|
||||||
|
|
||||||
class TestCarddavStorage(DavStorageTests):
|
class TestCarddavStorage(DavStorageTests):
|
||||||
storage_class = CarddavStorage
|
storage_class = CarddavStorage
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue