mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
Remove stupid print statements, more comments
This commit is contained in:
parent
ce264e2455
commit
f94649950e
3 changed files with 39 additions and 21 deletions
|
|
@ -85,6 +85,12 @@ class CaldavStorage(Storage):
|
||||||
path = self.url + item
|
path = self.url + item
|
||||||
return self._session.request(method, url, data=data, headers=headers, **self._settings)
|
return self._session.request(method, url, data=data, headers=headers, **self._settings)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _check_response(response):
|
||||||
|
if response.status_code == 412:
|
||||||
|
raise exceptions.PreconditionFailed()
|
||||||
|
response.raise_for_status()
|
||||||
|
|
||||||
def list(self):
|
def list(self):
|
||||||
data = '''<?xml version="1.0" encoding="utf-8" ?>
|
data = '''<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
|
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
|
||||||
|
|
@ -193,9 +199,7 @@ class CaldavStorage(Storage):
|
||||||
data=obj.raw,
|
data=obj.raw,
|
||||||
headers=headers
|
headers=headers
|
||||||
)
|
)
|
||||||
if response.status_code == 412:
|
self._check_response(response)
|
||||||
raise exceptions.PreconditionFailed(response.content)
|
|
||||||
response.raise_for_status()
|
|
||||||
|
|
||||||
etag = response.headers.get('etag', None)
|
etag = response.headers.get('etag', None)
|
||||||
if not etag:
|
if not etag:
|
||||||
|
|
@ -215,9 +219,7 @@ class CaldavStorage(Storage):
|
||||||
data=obj.raw,
|
data=obj.raw,
|
||||||
headers=headers
|
headers=headers
|
||||||
)
|
)
|
||||||
if response.status_code == 412:
|
self._check_response(response)
|
||||||
raise exceptions.PreconditionFailed(response.content)
|
|
||||||
response.raise_for_status()
|
|
||||||
|
|
||||||
etag = response.headers.get('etag', None)
|
etag = response.headers.get('etag', None)
|
||||||
if not etag:
|
if not etag:
|
||||||
|
|
@ -236,4 +238,4 @@ class CaldavStorage(Storage):
|
||||||
href,
|
href,
|
||||||
headers=headers
|
headers=headers
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
self._check_response(response)
|
||||||
|
|
|
||||||
|
|
@ -15,26 +15,41 @@
|
||||||
__version__ = '0.1.0'
|
__version__ = '0.1.0'
|
||||||
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
import os
|
|
||||||
import tempfile
|
import tempfile
|
||||||
import shutil
|
import shutil
|
||||||
from vdirsyncer.storage.caldav import CaldavStorage
|
import sys
|
||||||
from . import StorageTests
|
import os
|
||||||
|
|
||||||
from werkzeug.test import Client
|
from werkzeug.test import Client
|
||||||
from werkzeug.wrappers import BaseResponse as WerkzeugResponse
|
from werkzeug.wrappers import BaseResponse as WerkzeugResponse
|
||||||
|
|
||||||
|
from vdirsyncer.storage.caldav import CaldavStorage
|
||||||
|
from . import StorageTests
|
||||||
|
|
||||||
# All of radicale is already global state, there's nothing we can do
|
|
||||||
os.environ['RADICALE_CONFIG'] = ''
|
|
||||||
import radicale.config as radicale_config
|
|
||||||
radicale_config.set('storage', 'type', 'filesystem')
|
|
||||||
radicale_config.set('storage', 'filesystem_folder', None)
|
|
||||||
radicale_config.set('rights', 'type', 'None')
|
|
||||||
|
|
||||||
from radicale import Application
|
def do_the_radicale_dance(tmpdir):
|
||||||
import radicale.log
|
# All of radicale is already global state, the cleanliness of the code and
|
||||||
radicale.log.start()
|
# all hope is already lost. This function runs before every test.
|
||||||
|
|
||||||
|
# This wipes out the radicale modules, to reset all of its state.
|
||||||
|
for module in list(sys.modules):
|
||||||
|
if module.startswith('radicale'):
|
||||||
|
del sys.modules[module]
|
||||||
|
|
||||||
|
# radicale.config looks for this envvar. We have to delete it before it
|
||||||
|
# tries to load a config file.
|
||||||
|
os.environ['RADICALE_CONFIG'] = ''
|
||||||
|
import radicale.config
|
||||||
|
|
||||||
|
# Now we can set some basic configuration.
|
||||||
|
radicale.config.set('storage', 'type', 'filesystem')
|
||||||
|
radicale.config.set('storage', 'filesystem_folder', tmpdir)
|
||||||
|
radicale.config.set('rights', 'type', 'None')
|
||||||
|
|
||||||
|
# This one is particularly useful with radicale's debugging logs and
|
||||||
|
# pytest-capturelog, however, it is very verbose.
|
||||||
|
#import radicale.log
|
||||||
|
#radicale.log.start()
|
||||||
|
|
||||||
|
|
||||||
class Response(object):
|
class Response(object):
|
||||||
|
|
@ -59,7 +74,9 @@ class CaldavStorageTests(TestCase, StorageTests):
|
||||||
|
|
||||||
def _get_storage(self, **kwargs):
|
def _get_storage(self, **kwargs):
|
||||||
self.tmpdir = tempfile.mkdtemp()
|
self.tmpdir = tempfile.mkdtemp()
|
||||||
radicale_config.set('storage', 'filesystem_folder', self.tmpdir)
|
|
||||||
|
do_the_radicale_dance(self.tmpdir)
|
||||||
|
from radicale import Application
|
||||||
app = Application()
|
app = Application()
|
||||||
|
|
||||||
c = Client(app, WerkzeugResponse)
|
c = Client(app, WerkzeugResponse)
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ class FilesystemStorageTests(TestCase, StorageTests):
|
||||||
return FilesystemStorage(path=path, fileext='.txt', **kwargs)
|
return FilesystemStorage(path=path, fileext='.txt', **kwargs)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
print("lol")
|
|
||||||
if self.tmpdir is not None:
|
if self.tmpdir is not None:
|
||||||
shutil.rmtree(self.tmpdir)
|
shutil.rmtree(self.tmpdir)
|
||||||
self.tmpdir = None
|
self.tmpdir = None
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue