mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
More storage tests
This commit is contained in:
parent
9b9f17f69f
commit
a1d6a6f19a
2 changed files with 29 additions and 3 deletions
|
|
@ -47,9 +47,9 @@ class FilesystemStorage(Storage):
|
||||||
return os.path.getmtime(fpath)
|
return os.path.getmtime(fpath)
|
||||||
|
|
||||||
def update(self, obj, etag):
|
def update(self, obj, etag):
|
||||||
fpath = self._get_filepath(obj)
|
fpath = self._get_filepath(obj.uid)
|
||||||
if not os.path.exists(fpath):
|
if not os.path.exists(fpath):
|
||||||
raise exceptions.NotFoundError(href)
|
raise exceptions.NotFoundError(obj.uid)
|
||||||
actual_etag = os.path.getmtime(fpath)
|
actual_etag = os.path.getmtime(fpath)
|
||||||
if etag != actual_etag:
|
if etag != actual_etag:
|
||||||
raise exceptions.WrongEtagError(etag, actual_etag)
|
raise exceptions.WrongEtagError(etag, actual_etag)
|
||||||
|
|
@ -60,6 +60,9 @@ class FilesystemStorage(Storage):
|
||||||
|
|
||||||
def delete(self, uid, etag):
|
def delete(self, uid, etag):
|
||||||
fpath = self._get_filepath(uid)
|
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)
|
raise exceptions.WrongEtagError(etag, actual_etag)
|
||||||
os.remove(fpath)
|
os.remove(fpath)
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import shutil
|
||||||
from vdirsyncer.storage.base import Item
|
from vdirsyncer.storage.base import Item
|
||||||
from vdirsyncer.storage.filesystem import FilesystemStorage
|
from vdirsyncer.storage.filesystem import FilesystemStorage
|
||||||
from vdirsyncer.storage.memory import MemoryStorage
|
from vdirsyncer.storage.memory import MemoryStorage
|
||||||
|
import vdirsyncer.exceptions as exceptions
|
||||||
|
|
||||||
class StorageTests(object):
|
class StorageTests(object):
|
||||||
def _get_storage(self, **kwargs):
|
def _get_storage(self, **kwargs):
|
||||||
|
|
@ -44,6 +45,28 @@ class StorageTests(object):
|
||||||
item, etag = s.get(i)
|
item, etag = s.get(i)
|
||||||
assert item.raw == 'UID:{}'.format(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):
|
class FilesystemStorageTests(TestCase, StorageTests):
|
||||||
tmpdir = None
|
tmpdir = None
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue