Greatly simplify monkeypatching code for radicale

This commit is contained in:
Markus Unterwaditzer 2014-05-17 23:09:26 +02:00
parent 5fd866b41b
commit 5c6806ce97
2 changed files with 9 additions and 22 deletions

View file

@ -4,11 +4,10 @@ import os
import sys import sys
import pytest import pytest
import wsgi_intercept
import wsgi_intercept.requests_intercept
from werkzeug.test import Client wsgi_intercept.requests_intercept.install()
from werkzeug.wrappers import BaseResponse as WerkzeugResponse
from vdirsyncer.utils import urlparse
RADICALE_SCHEMA = ''' RADICALE_SCHEMA = '''
@ -90,27 +89,15 @@ def do_the_radicale_dance(tmpdir):
class ServerMixin(object): class ServerMixin(object):
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def setup(self, monkeypatch, tmpdir): def setup(self, request, tmpdir):
do_the_radicale_dance(str(tmpdir)) do_the_radicale_dance(str(tmpdir))
from radicale import Application from radicale import Application
app = Application()
c = Client(app, WerkzeugResponse)
from requests import Response wsgi_intercept.add_wsgi_intercept('127.0.0.1', 80, Application)
def send(self, request, *args, **kwargs): def teardown():
path = urlparse.urlparse(request.url).path wsgi_intercept.remove_wsgi_intercept('127.0.0.1', 80)
wr = c.open(path=path, method=request.method, request.addfinalizer(teardown)
data=request.body, headers=dict(request.headers))
r = Response()
r.request = request
r._content = wr.get_data(as_text=False)
r.headers = wr.headers
r.encoding = wr.charset
r.status_code = wr.status_code
return r
monkeypatch.setattr('requests.adapters.HTTPAdapter.send', send)
def get_storage_args(self, collection='test'): def get_storage_args(self, collection='test'):
url = 'http://127.0.0.1/bob/' url = 'http://127.0.0.1/bob/'

View file

@ -11,7 +11,7 @@ else
echo "Invalid requirements envvar" echo "Invalid requirements envvar"
false false
fi fi
pip install werkzeug $radicale_pkg pip install wsgi_intercept $radicale_pkg
if [ "$RADICALE_BACKEND" = "database" ]; then if [ "$RADICALE_BACKEND" = "database" ]; then
pip install sqlalchemy pip install sqlalchemy