More storage tests

This commit is contained in:
Markus Unterwaditzer 2014-02-16 23:59:08 +01:00
parent 9b9f17f69f
commit a1d6a6f19a
2 changed files with 29 additions and 3 deletions

View file

@ -47,9 +47,9 @@ class FilesystemStorage(Storage):
return os.path.getmtime(fpath)
def update(self, obj, etag):
fpath = self._get_filepath(obj)
fpath = self._get_filepath(obj.uid)
if not os.path.exists(fpath):
raise exceptions.NotFoundError(href)
raise exceptions.NotFoundError(obj.uid)
actual_etag = os.path.getmtime(fpath)
if etag != actual_etag:
raise exceptions.WrongEtagError(etag, actual_etag)
@ -60,6 +60,9 @@ class FilesystemStorage(Storage):
def delete(self, uid, etag):
fpath = self._get_filepath(uid)
if etag != os.path.getmtime(fpath):
if not os.path.isfile(fpath):
raise exceptions.NotFoundError(uid)
actual_etag = os.path.getmtime(fpath)
if etag != actual_etag:
raise exceptions.WrongEtagError(etag, actual_etag)
os.remove(fpath)

View file

@ -15,6 +15,7 @@ import shutil
from vdirsyncer.storage.base import Item
from vdirsyncer.storage.filesystem import FilesystemStorage
from vdirsyncer.storage.memory import MemoryStorage
import vdirsyncer.exceptions as exceptions
class StorageTests(object):
def _get_storage(self, **kwargs):
@ -44,6 +45,28 @@ class StorageTests(object):
item, etag = s.get(i)
assert item.raw == 'UID:{}'.format(i)
def test_upload_already_existing(self):
s = self._get_storage()
item = Item('UID:1')
s.upload(item)
self.assertRaises(exceptions.AlreadyExistingError, s.upload, item)
def test_update_nonexisting(self):
s = self._get_storage()
item = Item('UID:1')
self.assertRaises(exceptions.NotFoundError, s.update, item, 123)
def test_wrong_etag(self):
s = self._get_storage()
item = Item('UID:1')
etag = s.upload(item)
self.assertRaises(exceptions.WrongEtagError, s.update, item, 'lolnope')
self.assertRaises(exceptions.WrongEtagError, s.delete, '1', 'lolnope')
def test_delete_nonexisting(self):
s = self._get_storage()
self.assertRaises(exceptions.NotFoundError, s.delete, '1', 123)
class FilesystemStorageTests(TestCase, StorageTests):
tmpdir = None