Remove stupid print statements, more comments

This commit is contained in:
Markus Unterwaditzer 2014-02-26 23:02:28 +01:00
parent ce264e2455
commit f94649950e
3 changed files with 39 additions and 21 deletions

View file

@ -85,6 +85,12 @@ class CaldavStorage(Storage):
path = self.url + item
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):
data = '''<?xml version="1.0" encoding="utf-8" ?>
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
@ -193,9 +199,7 @@ class CaldavStorage(Storage):
data=obj.raw,
headers=headers
)
if response.status_code == 412:
raise exceptions.PreconditionFailed(response.content)
response.raise_for_status()
self._check_response(response)
etag = response.headers.get('etag', None)
if not etag:
@ -215,9 +219,7 @@ class CaldavStorage(Storage):
data=obj.raw,
headers=headers
)
if response.status_code == 412:
raise exceptions.PreconditionFailed(response.content)
response.raise_for_status()
self._check_response(response)
etag = response.headers.get('etag', None)
if not etag:
@ -236,4 +238,4 @@ class CaldavStorage(Storage):
href,
headers=headers
)
response.raise_for_status()
self._check_response(response)

View file

@ -15,26 +15,41 @@
__version__ = '0.1.0'
from unittest import TestCase
import os
import tempfile
import shutil
from vdirsyncer.storage.caldav import CaldavStorage
from . import StorageTests
import sys
import os
from werkzeug.test import Client
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
import radicale.log
radicale.log.start()
def do_the_radicale_dance(tmpdir):
# All of radicale is already global state, the cleanliness of the code and
# 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):
@ -59,7 +74,9 @@ class CaldavStorageTests(TestCase, StorageTests):
def _get_storage(self, **kwargs):
self.tmpdir = tempfile.mkdtemp()
radicale_config.set('storage', 'filesystem_folder', self.tmpdir)
do_the_radicale_dance(self.tmpdir)
from radicale import Application
app = Application()
c = Client(app, WerkzeugResponse)

View file

@ -24,7 +24,6 @@ class FilesystemStorageTests(TestCase, StorageTests):
return FilesystemStorage(path=path, fileext='.txt', **kwargs)
def tearDown(self):
print("lol")
if self.tmpdir is not None:
shutil.rmtree(self.tmpdir)
self.tmpdir = None