From 668220dbd76ffcafef9fa493b4482c59ef5c2491 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Thu, 2 Mar 2017 21:13:08 +0100 Subject: [PATCH] Add fastmail testserver (#572) --- .travis.yml | 100 +-------------------- AUTHORS.rst | 3 + scripts/make_travisconf.py | 18 ++-- tests/storage/__init__.py | 11 +-- tests/storage/conftest.py | 36 ++++++++ tests/storage/dav/__init__.py | 6 +- tests/storage/servers/fastmail/__init__.py | 27 ++++++ tests/storage/servers/fastmail/install.sh | 0 tests/storage/servers/icloud/__init__.py | 30 +------ 9 files changed, 91 insertions(+), 140 deletions(-) create mode 100644 tests/storage/conftest.py create mode 100644 tests/storage/servers/fastmail/__init__.py create mode 100644 tests/storage/servers/fastmail/install.sh diff --git a/.travis.yml b/.travis.yml index 7fed586..f447911 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,18 +21,6 @@ "env": "BUILD=style", "python": "3.6" }, - { - "env": "BUILD=test DAV_SERVER=skip REQUIREMENTS=devel ", - "python": "3.3" - }, - { - "env": "BUILD=test DAV_SERVER=skip REQUIREMENTS=release ", - "python": "3.3" - }, - { - "env": "BUILD=test DAV_SERVER=skip REQUIREMENTS=minimal ", - "python": "3.3" - }, { "env": "BUILD=test DAV_SERVER=radicale REQUIREMENTS=devel ", "python": "3.3" @@ -45,18 +33,6 @@ "env": "BUILD=test DAV_SERVER=radicale REQUIREMENTS=minimal ", "python": "3.3" }, - { - "env": "BUILD=test DAV_SERVER=skip REQUIREMENTS=devel ", - "python": "3.4" - }, - { - "env": "BUILD=test DAV_SERVER=skip REQUIREMENTS=release ", - "python": "3.4" - }, - { - "env": "BUILD=test DAV_SERVER=skip REQUIREMENTS=minimal ", - "python": "3.4" - }, { "env": "BUILD=test DAV_SERVER=radicale REQUIREMENTS=devel ", "python": "3.4" @@ -69,18 +45,6 @@ "env": "BUILD=test DAV_SERVER=radicale REQUIREMENTS=minimal ", "python": "3.4" }, - { - "env": "BUILD=test DAV_SERVER=skip REQUIREMENTS=devel ", - "python": "3.5" - }, - { - "env": "BUILD=test DAV_SERVER=skip REQUIREMENTS=release ", - "python": "3.5" - }, - { - "env": "BUILD=test DAV_SERVER=skip REQUIREMENTS=minimal ", - "python": "3.5" - }, { "env": "BUILD=test DAV_SERVER=radicale REQUIREMENTS=devel ", "python": "3.5" @@ -94,100 +58,44 @@ "python": "3.5" }, { - "env": "BUILD=test DAV_SERVER=skip REQUIREMENTS=devel ", + "env": "BUILD=test DAV_SERVER=radicale REQUIREMENTS=devel ", "python": "3.6" }, { "env": "BUILD=test DAV_SERVER=skip REQUIREMENTS=release ", "python": "3.6" }, - { - "env": "BUILD=test DAV_SERVER=skip REQUIREMENTS=minimal ", - "python": "3.6" - }, - { - "env": "BUILD=test DAV_SERVER=radicale REQUIREMENTS=devel ", - "python": "3.6" - }, { "env": "BUILD=test DAV_SERVER=radicale REQUIREMENTS=release ", "python": "3.6" }, - { - "env": "BUILD=test DAV_SERVER=radicale REQUIREMENTS=minimal ", - "python": "3.6" - }, - { - "env": "BUILD=test DAV_SERVER=owncloud REQUIREMENTS=devel ", - "python": "3.6" - }, { "env": "BUILD=test DAV_SERVER=owncloud REQUIREMENTS=release ", "python": "3.6" }, - { - "env": "BUILD=test DAV_SERVER=owncloud REQUIREMENTS=minimal ", - "python": "3.6" - }, - { - "env": "BUILD=test DAV_SERVER=nextcloud REQUIREMENTS=devel ", - "python": "3.6" - }, { "env": "BUILD=test DAV_SERVER=nextcloud REQUIREMENTS=release ", "python": "3.6" }, - { - "env": "BUILD=test DAV_SERVER=nextcloud REQUIREMENTS=minimal ", - "python": "3.6" - }, - { - "env": "BUILD=test DAV_SERVER=baikal REQUIREMENTS=devel ", - "python": "3.6" - }, { "env": "BUILD=test DAV_SERVER=baikal REQUIREMENTS=release ", "python": "3.6" }, - { - "env": "BUILD=test DAV_SERVER=baikal REQUIREMENTS=minimal ", - "python": "3.6" - }, - { - "env": "BUILD=test DAV_SERVER=davical REQUIREMENTS=devel ", - "python": "3.6" - }, { "env": "BUILD=test DAV_SERVER=davical REQUIREMENTS=release ", "python": "3.6" }, - { - "env": "BUILD=test DAV_SERVER=davical REQUIREMENTS=minimal ", - "python": "3.6" - }, - { - "env": "BUILD=test DAV_SERVER=icloud REQUIREMENTS=devel ", - "python": "3.6" - }, { "env": "BUILD=test DAV_SERVER=icloud REQUIREMENTS=release ", "python": "3.6" }, { - "env": "BUILD=test DAV_SERVER=icloud REQUIREMENTS=minimal ", + "env": "BUILD=test DAV_SERVER=fastmail REQUIREMENTS=release ", "python": "3.6" }, { - "env": "BUILD=test DAV_SERVER=skip REQUIREMENTS=devel ", - "python": "pypy3" - }, - { - "env": "BUILD=test DAV_SERVER=skip REQUIREMENTS=release ", - "python": "pypy3" - }, - { - "env": "BUILD=test DAV_SERVER=skip REQUIREMENTS=minimal ", - "python": "pypy3" + "env": "BUILD=test DAV_SERVER=radicale REQUIREMENTS=minimal ", + "python": "3.6" }, { "env": "BUILD=test DAV_SERVER=radicale REQUIREMENTS=devel ", diff --git a/AUTHORS.rst b/AUTHORS.rst index 699890b..b8a55d6 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -13,3 +13,6 @@ In alphabetical order: - Markus Unterwaditzer - Michael Adler - Thomas Weißschuh + +Additionally `FastMail sponsored a paid account for testing +`_. Thanks! diff --git a/scripts/make_travisconf.py b/scripts/make_travisconf.py index d4c482c..5616f07 100644 --- a/scripts/make_travisconf.py +++ b/scripts/make_travisconf.py @@ -38,21 +38,19 @@ matrix.append({ }) -for python in python_versions: - if python == latest_python: +for python, requirements in itertools.product(python_versions, + ("devel", "release", "minimal")): + if python == latest_python and requirements == "release": dav_servers = ("skip", "radicale", "owncloud", "nextcloud", "baikal", - "davical", "icloud") + "davical", "icloud", "fastmail") rs_servers = () else: - dav_servers = ("skip", "radicale") + dav_servers = ("radicale",) rs_servers = () - for (server_type, server), requirements in itertools.product( - itertools.chain( - (("REMOTESTORAGE", x) for x in rs_servers), - (("DAV", x) for x in dav_servers) - ), - ("devel", "release", "minimal") + for server_type, server in itertools.chain( + (("REMOTESTORAGE", x) for x in rs_servers), + (("DAV", x) for x in dav_servers) ): matrix.append({ 'python': python, diff --git a/tests/storage/__init__.py b/tests/storage/__init__.py index c584e9f..574a371 100644 --- a/tests/storage/__init__.py +++ b/tests/storage/__init__.py @@ -203,8 +203,9 @@ class StorageTests(object): if getattr(self, 'dav_server', '') == 'radicale': pytest.skip('MKCOL is broken under Radicale 1.x') - if getattr(self, 'dav_server', '') == 'icloud': - pytest.skip('iCloud requires a minimum-length for collection name') + if getattr(self, 'dav_server', '') in \ + ('icloud', 'fastmail', 'davical'): + pytest.skip('Manual cleanup would be necessary.') args = get_storage_args(collection=None) args['collection'] = 'test' @@ -249,8 +250,8 @@ class StorageTests(object): get_storage_args, get_item): if getattr(self, 'dav_server', '') == 'radicale': pytest.skip('Radicale is fundamentally broken.') - if getattr(self, 'dav_server', '') == 'icloud': - pytest.skip('iCloud rejects uploads.') + if getattr(self, 'dav_server', '') in ('icloud', 'fastmail'): + pytest.skip('iCloud and FastMail reject this name.') monkeypatch.setattr('vdirsyncer.utils.generate_href', lambda x: x) @@ -309,7 +310,7 @@ class StorageTests(object): if item_type != 'VEVENT': pytest.skip('This storage instance doesn\'t support iCalendar.') - uid = u'abc123' + uid = str(uuid.uuid4()) item = Item(textwrap.dedent(u''' BEGIN:VCALENDAR VERSION:2.0 diff --git a/tests/storage/conftest.py b/tests/storage/conftest.py new file mode 100644 index 0000000..90333ad --- /dev/null +++ b/tests/storage/conftest.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- + +import pytest + +import uuid + + +@pytest.fixture +def slow_create_collection(request): + # We need to properly clean up because otherwise we might run into + # storage limits. + to_delete = [] + + def delete_collections(): + for s in to_delete: + s.session.request('DELETE', '') + + request.addfinalizer(delete_collections) + + def inner(cls, args, collection): + assert collection.startswith('test') + collection += '-vdirsyncer-ci-' + str(uuid.uuid4()) + + args = cls.create_collection(collection, **args) + s = cls(**args) + _clear_collection(s) + assert not list(s.list()) + to_delete.append(s) + return args + + return inner + + +def _clear_collection(s): + for href, etag in s.list(): + s.delete(href, etag) diff --git a/tests/storage/dav/__init__.py b/tests/storage/dav/__init__.py index 5567973..edcd2a4 100644 --- a/tests/storage/dav/__init__.py +++ b/tests/storage/dav/__init__.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- +import uuid + import os import pytest @@ -44,11 +46,11 @@ class DAVStorageTests(ServerMixin, StorageTests): def test_dav_unicode_href(self, s, get_item, monkeypatch): if self.dav_server == 'radicale': - pytest.xfail('Radicale is unable to deal with unicode hrefs') + pytest.skip('Radicale is unable to deal with unicode hrefs') monkeypatch.setattr(s, '_get_href', lambda item: item.ident + s.fileext) - item = get_item(uid=u'lolätvdirsynceröü град сатану') + item = get_item(uid=u'град сатану' + str(uuid.uuid4())) href, etag = s.upload(item) item2, etag2 = s.get(href) assert_item_equals(item, item2) diff --git a/tests/storage/servers/fastmail/__init__.py b/tests/storage/servers/fastmail/__init__.py new file mode 100644 index 0000000..a421f92 --- /dev/null +++ b/tests/storage/servers/fastmail/__init__.py @@ -0,0 +1,27 @@ +import os + +import pytest + + +class ServerMixin(object): + + @pytest.fixture + def get_storage_args(self, slow_create_collection): + def inner(collection='test'): + args = { + 'username': os.environ['FASTMAIL_USERNAME'], + 'password': os.environ['FASTMAIL_PASSWORD'] + } + + if self.storage_class.fileext == '.ics': + args['url'] = 'https://caldav.messagingengine.com/' + elif self.storage_class.fileext == '.vcf': + args['url'] = 'https://carddav.messagingengine.com/' + else: + raise RuntimeError() + + if collection is not None: + args = slow_create_collection(self.storage_class, args, + collection) + return args + return inner diff --git a/tests/storage/servers/fastmail/install.sh b/tests/storage/servers/fastmail/install.sh new file mode 100644 index 0000000..e69de29 diff --git a/tests/storage/servers/icloud/__init__.py b/tests/storage/servers/icloud/__init__.py index f7a69f9..8af0a8f 100644 --- a/tests/storage/servers/icloud/__init__.py +++ b/tests/storage/servers/icloud/__init__.py @@ -1,28 +1,12 @@ import os -import uuid import pytest -def _clear_collection(s): - for href, etag in s.list(): - s.delete(href, etag) - - class ServerMixin(object): @pytest.fixture - def get_storage_args(self, item_type, request): - # We need to properly clean up because otherwise we will run into - # iCloud's storage limit. - collections_to_delete = [] - - def delete_collections(): - for s in collections_to_delete: - s.session.request('DELETE', '') - - request.addfinalizer(delete_collections) - + def get_storage_args(self, item_type, slow_create_collection): if item_type != 'VEVENT': # For some reason the collections created by vdirsyncer are not # usable as task lists. @@ -42,15 +26,7 @@ class ServerMixin(object): raise RuntimeError() if collection is not None: - assert collection.startswith('test') - # iCloud requires a minimum length for collection names - collection += '-vdirsyncer-ci-' + str(uuid.uuid4()) - - args = self.storage_class.create_collection(collection, - **args) - s = self.storage_class(**args) - _clear_collection(s) - assert not list(s.list()) - collections_to_delete.append(s) + args = slow_create_collection(self.storage_class, args, + collection) return args return inner