mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
Setup logging again
This commit is contained in:
parent
64a8a682e9
commit
d088098e20
4 changed files with 55 additions and 43 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
import vdirsyncer.log
|
import vdirsyncer.log
|
||||||
vdirsyncer.log.set_level(vdirsyncer.log.logging.DEBUG)
|
vdirsyncer.log.set_level(vdirsyncer.log.logging.DEBUG)
|
||||||
|
|
||||||
|
|
||||||
def normalize_item(item):
|
def normalize_item(item):
|
||||||
# - X-RADICALE-NAME is used by radicale, because hrefs don't really exist
|
# - X-RADICALE-NAME is used by radicale, because hrefs don't really exist
|
||||||
# in their filesystem backend
|
# in their filesystem backend
|
||||||
|
|
@ -18,3 +19,27 @@ def normalize_item(item):
|
||||||
|
|
||||||
def assert_item_equals(a, b):
|
def assert_item_equals(a, b):
|
||||||
assert normalize_item(a) == normalize_item(b)
|
assert normalize_item(a) == normalize_item(b)
|
||||||
|
|
||||||
|
|
||||||
|
def log_request(method, url, data, headers):
|
||||||
|
print(method)
|
||||||
|
print(url)
|
||||||
|
print(data)
|
||||||
|
print(headers)
|
||||||
|
|
||||||
|
|
||||||
|
def log_response(r):
|
||||||
|
print(r.status_code)
|
||||||
|
print(r.text)
|
||||||
|
|
||||||
|
|
||||||
|
def requests_mock(monkeypatch):
|
||||||
|
'''It is easier than setting up the logging module!'''
|
||||||
|
import requests.sessions
|
||||||
|
old_func = requests.sessions.Session.request
|
||||||
|
def mock_request(self, method, url, data=None, headers=None, **kw):
|
||||||
|
log_request(method, url, data, headers)
|
||||||
|
r = old_func(self, method, url, data=data, headers=headers, **kw)
|
||||||
|
log_response(r)
|
||||||
|
return r
|
||||||
|
monkeypatch.setattr('requests.sessions.Session.request', mock_request)
|
||||||
|
|
|
||||||
|
|
@ -12,18 +12,41 @@
|
||||||
from vdirsyncer.utils import expand_path
|
from vdirsyncer.utils import expand_path
|
||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import os
|
||||||
|
import time
|
||||||
|
import pytest
|
||||||
|
import requests
|
||||||
|
from tests import requests_mock
|
||||||
|
|
||||||
owncloud_repo = expand_path(os.path.join(
|
owncloud_repo = expand_path(os.path.join(
|
||||||
os.path.dirname(__file__), '../../../owncloud-testserver/'
|
os.path.dirname(__file__), '../../../owncloud-testserver/'
|
||||||
))
|
))
|
||||||
|
|
||||||
|
php_sh = os.path.abspath(os.path.join(owncloud_repo, 'php.sh'))
|
||||||
|
|
||||||
|
|
||||||
|
def wait():
|
||||||
|
for i in range(10):
|
||||||
|
try:
|
||||||
|
requests.get('http://127.0.0.1:8080/')
|
||||||
|
except requests.exceptions.ConnectionError:
|
||||||
|
time.sleep(1)
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class ServerMixin(object):
|
class ServerMixin(object):
|
||||||
storage_class = None
|
storage_class = None
|
||||||
wsgi_teardown = None
|
wsgi_teardown = None
|
||||||
|
|
||||||
def setup_method(self, method):
|
@pytest.fixture(autouse=True)
|
||||||
|
def setup(self, monkeypatch, xprocess):
|
||||||
|
def preparefunc(cwd):
|
||||||
|
return wait, ['sh', php_sh]
|
||||||
|
|
||||||
|
xprocess.ensure('owncloud_server', preparefunc)
|
||||||
subprocess.check_call([os.path.join(owncloud_repo, 'reset.sh')])
|
subprocess.check_call([os.path.join(owncloud_repo, 'reset.sh')])
|
||||||
|
requests_mock(monkeypatch)
|
||||||
|
|
||||||
def get_storage_args(self, collection='test'):
|
def get_storage_args(self, collection='test'):
|
||||||
url = 'http://127.0.0.1:8080'
|
url = 'http://127.0.0.1:8080'
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,8 @@ import urlparse
|
||||||
import shutil
|
import shutil
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from tests import log_request, log_response
|
||||||
|
|
||||||
from werkzeug.test import Client
|
from werkzeug.test import Client
|
||||||
from werkzeug.wrappers import BaseResponse as WerkzeugResponse
|
from werkzeug.wrappers import BaseResponse as WerkzeugResponse
|
||||||
|
|
||||||
|
|
@ -125,10 +127,11 @@ class ServerMixin(object):
|
||||||
|
|
||||||
def request(self, method, url, data=None, headers=None, **kw):
|
def request(self, method, url, data=None, headers=None, **kw):
|
||||||
path = urlparse.urlparse(url).path
|
path = urlparse.urlparse(url).path
|
||||||
|
log_request(method, url, data, headers)
|
||||||
assert isinstance(data, bytes) or data is None
|
assert isinstance(data, bytes) or data is None
|
||||||
r = c.open(path=path, method=method, data=data,
|
r = Response(c.open(path=path, method=method, data=data,
|
||||||
headers=headers)
|
headers=headers))
|
||||||
r = Response(r)
|
log_response(r)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
monkeypatch.setattr('requests.sessions.Session.request', request)
|
monkeypatch.setattr('requests.sessions.Session.request', request)
|
||||||
|
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
'''
|
|
||||||
vdirsyncer.tests.storage.dav.conftest
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
:copyright: (c) 2014 Markus Unterwaditzer
|
|
||||||
:license: MIT, see LICENSE for more details.
|
|
||||||
'''
|
|
||||||
|
|
||||||
import os
|
|
||||||
import pytest
|
|
||||||
import requests
|
|
||||||
import requests.exceptions
|
|
||||||
import time
|
|
||||||
|
|
||||||
dav_server = os.environ.get('DAV_SERVER', '').strip() or 'radicale_filesystem'
|
|
||||||
php_sh = os.path.abspath(os.path.join(
|
|
||||||
os.path.dirname(__file__), '../../../owncloud-testserver/php.sh'
|
|
||||||
))
|
|
||||||
|
|
||||||
|
|
||||||
def wait():
|
|
||||||
for i in range(10):
|
|
||||||
try:
|
|
||||||
requests.get('http://127.0.0.1:8080/')
|
|
||||||
except requests.exceptions.ConnectionError:
|
|
||||||
time.sleep(1)
|
|
||||||
else:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
if dav_server == 'owncloud':
|
|
||||||
@pytest.fixture(autouse=True)
|
|
||||||
def start_owncloud_server(xprocess):
|
|
||||||
def preparefunc(cwd):
|
|
||||||
return wait, ['sh', php_sh]
|
|
||||||
|
|
||||||
xprocess.ensure('owncloud_server', preparefunc)
|
|
||||||
Loading…
Reference in a new issue