Stricten collection discovery test

This commit is contained in:
Markus Unterwaditzer 2014-12-07 16:47:56 +01:00
parent 7f2ccd6b3a
commit ca5a9cd8f9
2 changed files with 20 additions and 31 deletions

View file

@ -147,39 +147,22 @@ class BaseStorageTests(object):
class SupportsCollections(object): class SupportsCollections(object):
def test_discover(self, get_storage_args, get_item): def test_discover(self, get_storage_args, get_item):
collections = set() expected = set()
def main(): for i in range(1, 5):
for i in range(1, 5): # Create collections, but use the "collection" attribute because
collection = 'test{}'.format(i) # Radicale requires file extensions in their names.
# Create collections on-the-fly for most storages expected.add(
# Except ownCloud, which already has all of them, and more self.storage_class(
i += 1 **get_storage_args(collection='test{}'.format(i))
s = self.storage_class( ).collection
**get_storage_args(collection=collection)) )
# radicale ignores empty collections during discovery
item = get_item()
s.upload(item)
collections.add(s.collection)
main() # remove leftover variables from loop for safety
d = self.storage_class.discover( d = self.storage_class.discover(
**get_storage_args(collection=None)) **get_storage_args(collection=None))
def main(): actual = set(s.collection for s in d)
for s in d: assert not expected - actual
if s.collection not in collections:
# ownCloud has many more collections, as on-the-fly
# creation doesn't really work there. Skip those
# collections, as they are not relevant to us.
print('Skipping {}'.format(s.collection))
continue
collections.remove(s.collection)
main()
assert not collections
def test_discover_collection_arg(self, get_storage_args): def test_discover_collection_arg(self, get_storage_args):
args = get_storage_args(collection='test2') args = get_storage_args(collection='test2')

View file

@ -105,12 +105,18 @@ class ServerMixin(object):
request.addfinalizer(teardown) request.addfinalizer(teardown)
@pytest.fixture @pytest.fixture
def get_storage_args(self): def get_storage_args(self, get_item):
def inner(collection='test'): def inner(collection='test'):
url = 'http://127.0.0.1/bob/' url = 'http://127.0.0.1/bob/'
if collection is not None: if collection is not None:
collection += self.storage_class.fileext collection += self.storage_class.fileext
return {'url': url, 'username': 'bob', 'password': 'bob', rv = {'url': url, 'username': 'bob', 'password': 'bob',
'collection': collection, 'unsafe_href_chars': ''} 'collection': collection, 'unsafe_href_chars': ''}
if collection is not None:
s = self.storage_class(**rv)
s.delete(*s.upload(get_item())) # create collection
return rv
return inner return inner