Straighten tests

This commit is contained in:
Markus Unterwaditzer 2014-03-29 13:04:50 +01:00
parent d088098e20
commit 577ab54025
2 changed files with 31 additions and 23 deletions

View file

@ -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,30 +98,37 @@ 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():
# Create collections on-the-fly for most storages for i in range(1, 5):
# Except ownCloud, which already has all of them, and more collection = 'test{}'.format(i)
i += 1 # Create collections on-the-fly for most storages
s = self.storage_class( # Except ownCloud, which already has all of them, and more
**self.get_storage_args(collection=collection)) i += 1
item = self._create_bogus_item(str(i)) s = self.storage_class(
s.upload(item) **self.get_storage_args(collection=collection))
items.add(item.raw) item = self._create_bogus_item(str(i))
s.upload(item)
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))
for s in d:
if s.collection not in collections: def main():
# ownCloud has many more collections, as on-the-fly creation for s in d:
# doesn't really work there. Skip those collections, as they if not s.collection.startswith('test'):
# are not relevant to us. # ownCloud has many more collections, as on-the-fly
continue # creation doesn't really work there. Skip those
collection = collections.remove(s.collection) # collections, as they are not relevant to us.
((href, etag),) = s.list() print('Skipping {}'.format(s.collection))
item, etag = s.get(href) continue
assert item.raw in items ((href, etag),) = s.list()
item, etag = s.get(href)
assert collections[s.collection] == normalize_item(item)
del collections[s.collection]
main()
assert not collections assert not collections

View file

@ -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