From bb35d7c091b25722ecffe7830edfecbf5f3e2d4a Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Wed, 8 Mar 2017 10:16:24 +0100 Subject: [PATCH] Flatten mysteryshack submodule --- .gitmodules | 3 - tests/storage/servers/mysteryshack | 1 - tests/storage/servers/mysteryshack/.gitignore | 1 + .../storage/servers/mysteryshack/__init__.py | 75 +++++++++++++++++++ tests/storage/servers/mysteryshack/install.sh | 18 +++++ tests/storage/servers/mysteryshack/make.sh | 9 +++ .../storage/servers/mysteryshack/variables.sh | 1 + 7 files changed, 104 insertions(+), 4 deletions(-) delete mode 160000 tests/storage/servers/mysteryshack create mode 100644 tests/storage/servers/mysteryshack/.gitignore create mode 100644 tests/storage/servers/mysteryshack/__init__.py create mode 100644 tests/storage/servers/mysteryshack/install.sh create mode 100644 tests/storage/servers/mysteryshack/make.sh create mode 100644 tests/storage/servers/mysteryshack/variables.sh diff --git a/.gitmodules b/.gitmodules index 40aab99..cc13351 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,9 +4,6 @@ [submodule "tests/storage/servers/owncloud"] path = tests/storage/servers/owncloud url = https://github.com/vdirsyncer/owncloud-testserver -[submodule "tests/storage/servers/mysteryshack"] - path = tests/storage/servers/mysteryshack - url = https://github.com/vdirsyncer/mysteryshack-testserver [submodule "tests/storage/servers/nextcloud"] path = tests/storage/servers/nextcloud url = https://github.com/vdirsyncer/nextcloud-testserver diff --git a/tests/storage/servers/mysteryshack b/tests/storage/servers/mysteryshack deleted file mode 160000 index 8e50135..0000000 --- a/tests/storage/servers/mysteryshack +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8e501355582e072b5b9bf3b1d40ae8fa06e52eac diff --git a/tests/storage/servers/mysteryshack/.gitignore b/tests/storage/servers/mysteryshack/.gitignore new file mode 100644 index 0000000..904d2ca --- /dev/null +++ b/tests/storage/servers/mysteryshack/.gitignore @@ -0,0 +1 @@ +mysteryshack diff --git a/tests/storage/servers/mysteryshack/__init__.py b/tests/storage/servers/mysteryshack/__init__.py new file mode 100644 index 0000000..b5e7478 --- /dev/null +++ b/tests/storage/servers/mysteryshack/__init__.py @@ -0,0 +1,75 @@ +# -*- coding: utf-8 -*- + +import os +import subprocess +import time +import shutil + +import pytest + +import requests + +testserver_repo = os.path.dirname(__file__) +make_sh = os.path.abspath(os.path.join(testserver_repo, 'make.sh')) + + +def wait(): + for i in range(100): + try: + requests.get('http://127.0.0.1:6767/', verify=False) + except Exception as e: + # Don't know exact exception class, don't care. + # Also, https://github.com/kennethreitz/requests/issues/2192 + if 'connection refused' not in str(e).lower(): + raise + time.sleep(2 ** i) + else: + return True + return False + + +class ServerMixin(object): + @pytest.fixture(scope='session') + def setup_mysteryshack_server(self, xprocess): + def preparefunc(cwd): + return wait, ['sh', make_sh, 'testserver'] + + subprocess.check_call(['sh', make_sh, 'testserver-config']) + xprocess.ensure('mysteryshack_server', preparefunc) + + return subprocess.check_output([ + os.path.join( + testserver_repo, + 'mysteryshack/target/debug/mysteryshack' + ), + '-c', '/tmp/mysteryshack/config', + 'user', + 'authorize', + 'testuser', + 'https://example.com', + self.storage_class.scope + ':rw' + ]).strip().decode() + + @pytest.fixture + def get_storage_args(self, monkeypatch, setup_mysteryshack_server): + from requests import Session + + monkeypatch.setitem(os.environ, 'OAUTHLIB_INSECURE_TRANSPORT', 'true') + + old_request = Session.request + + def request(self, method, url, **kw): + url = url.replace('https://', 'http://') + return old_request(self, method, url, **kw) + + monkeypatch.setattr(Session, 'request', request) + shutil.rmtree('/tmp/mysteryshack/testuser/data', ignore_errors=True) + shutil.rmtree('/tmp/mysteryshack/testuser/meta', ignore_errors=True) + + def inner(**kw): + kw['account'] = 'testuser@127.0.0.1:6767' + kw['access_token'] = setup_mysteryshack_server + if self.storage_class.fileext == '.ics': + kw.setdefault('collection', 'test') + return kw + return inner diff --git a/tests/storage/servers/mysteryshack/install.sh b/tests/storage/servers/mysteryshack/install.sh new file mode 100644 index 0000000..36b1269 --- /dev/null +++ b/tests/storage/servers/mysteryshack/install.sh @@ -0,0 +1,18 @@ +#!/bin/sh +set -ex +cd "$(dirname "$0")" +. ./variables.sh + +if [ "$CI" = "true" ]; then + curl -sL https://static.rust-lang.org/rustup.sh -o ~/rust-installer/rustup.sh + sh ~/rust-installer/rustup.sh --prefix=~/rust --spec=stable -y --disable-sudo 2> /dev/null +fi + +if [ ! -d mysteryshack ]; then + git clone https://github.com/untitaker/mysteryshack +fi + +pip install pytest-xprocess + +cd mysteryshack +make debug-build # such that first test doesn't hang too long w/o output diff --git a/tests/storage/servers/mysteryshack/make.sh b/tests/storage/servers/mysteryshack/make.sh new file mode 100644 index 0000000..c2484a4 --- /dev/null +++ b/tests/storage/servers/mysteryshack/make.sh @@ -0,0 +1,9 @@ +#!/bin/sh +set -e + +# pytest-xprocess doesn't allow us to CD into a particular directory before +# launching a command, so we do it here. +cd "$(dirname "$0")" +. ./variables.sh +cd mysteryshack +exec make "$@" diff --git a/tests/storage/servers/mysteryshack/variables.sh b/tests/storage/servers/mysteryshack/variables.sh new file mode 100644 index 0000000..8eda6e7 --- /dev/null +++ b/tests/storage/servers/mysteryshack/variables.sh @@ -0,0 +1 @@ +export PATH="$PATH:$HOME/.cargo/bin/"