mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
Straighten tests
This commit is contained in:
parent
d088098e20
commit
577ab54025
2 changed files with 31 additions and 23 deletions
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
from vdirsyncer.storage.base import Item
|
from vdirsyncer.storage.base import Item
|
||||||
import vdirsyncer.exceptions as exceptions
|
import vdirsyncer.exceptions as exceptions
|
||||||
from .. import assert_item_equals
|
from .. import assert_item_equals, normalize_item
|
||||||
import random
|
import random
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
@ -98,9 +98,11 @@ class StorageTests(object):
|
||||||
assert list(s.list())
|
assert list(s.list())
|
||||||
|
|
||||||
def test_discover(self):
|
def test_discover(self):
|
||||||
items = set()
|
collections = {}
|
||||||
collections = set(['test1', 'test2', 'test3', 'test4'])
|
|
||||||
for i, collection in enumerate(collections):
|
def main():
|
||||||
|
for i in range(1, 5):
|
||||||
|
collection = 'test{}'.format(i)
|
||||||
# Create collections on-the-fly for most storages
|
# Create collections on-the-fly for most storages
|
||||||
# Except ownCloud, which already has all of them, and more
|
# Except ownCloud, which already has all of them, and more
|
||||||
i += 1
|
i += 1
|
||||||
|
|
@ -108,20 +110,25 @@ class StorageTests(object):
|
||||||
**self.get_storage_args(collection=collection))
|
**self.get_storage_args(collection=collection))
|
||||||
item = self._create_bogus_item(str(i))
|
item = self._create_bogus_item(str(i))
|
||||||
s.upload(item)
|
s.upload(item)
|
||||||
items.add(item.raw)
|
collections[s.collection] = normalize_item(item)
|
||||||
|
main() # remove leftover variables from loop for safety
|
||||||
|
|
||||||
d = self.storage_class.discover(
|
d = self.storage_class.discover(
|
||||||
**self.get_storage_args(collection=None))
|
**self.get_storage_args(collection=None))
|
||||||
|
|
||||||
|
def main():
|
||||||
for s in d:
|
for s in d:
|
||||||
if s.collection not in collections:
|
if not s.collection.startswith('test'):
|
||||||
# ownCloud has many more collections, as on-the-fly creation
|
# ownCloud has many more collections, as on-the-fly
|
||||||
# doesn't really work there. Skip those collections, as they
|
# creation doesn't really work there. Skip those
|
||||||
# are not relevant to us.
|
# collections, as they are not relevant to us.
|
||||||
|
print('Skipping {}'.format(s.collection))
|
||||||
continue
|
continue
|
||||||
collection = collections.remove(s.collection)
|
|
||||||
((href, etag),) = s.list()
|
((href, etag),) = s.list()
|
||||||
item, etag = s.get(href)
|
item, etag = s.get(href)
|
||||||
assert item.raw in items
|
assert collections[s.collection] == normalize_item(item)
|
||||||
|
del collections[s.collection]
|
||||||
|
main()
|
||||||
|
|
||||||
assert not collections
|
assert not collections
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -69,9 +69,10 @@ class DavStorage(HttpStorageBase):
|
||||||
ssl_verify=kwargs.get('verify', True)
|
ssl_verify=kwargs.get('verify', True)
|
||||||
)
|
)
|
||||||
for c in d.discover():
|
for c in d.discover():
|
||||||
collection = c['href']
|
collection = urlparse.urljoin(url, c['href'])
|
||||||
if collection.startswith(url):
|
if collection.startswith(url):
|
||||||
collection = collection[len(url):]
|
collection = collection[len(url):]
|
||||||
|
collection = collection.rstrip('/')
|
||||||
s = cls(url=url, collection=collection, **kwargs)
|
s = cls(url=url, collection=collection, **kwargs)
|
||||||
s.displayname = c['displayname']
|
s.displayname = c['displayname']
|
||||||
yield s
|
yield s
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue