vdirsyncer/tests/storage/servers/davical/__init__.py
Markus Unterwaditzer feea65ff1d Stylefix
2017-03-08 11:38:57 +01:00

47 lines
1.5 KiB
Python

import os
import pytest
import uuid
try:
caldav_args = {
# Those credentials are configured through the Travis UI
'username': os.environ['DAVICAL_USERNAME'].strip(),
'password': os.environ['DAVICAL_PASSWORD'].strip(),
'url': 'https://brutus.lostpackets.de/davical-test/caldav.php/',
}
except KeyError as e:
pytestmark = pytest.mark.skip('Missing envkey: {}'.format(str(e)))
@pytest.mark.flaky(reruns=5)
class ServerMixin(object):
@pytest.fixture
def davical_args(self):
if self.storage_class.fileext == '.ics':
return dict(caldav_args)
elif self.storage_class.fileext == '.vcf':
pytest.skip('No carddav')
else:
raise RuntimeError()
@pytest.fixture
def get_storage_args(self, davical_args, request):
def inner(collection='test'):
if collection is None:
return davical_args
assert collection.startswith('test')
for _ in range(4):
args = self.storage_class.create_collection(
collection + str(uuid.uuid4()),
**davical_args
)
s = self.storage_class(**args)
if not list(s.list()):
request.addfinalizer(
lambda: s.session.request('DELETE', ''))
return args
raise RuntimeError('Failed to find free collection.')
return inner