Commit 61411e10 authored by Pierre-Yves David's avatar Pierre-Yves David
Browse files

Add a fsimport context manage to localy enable fsimporting.

--HG--
branch : stable
parent 4efd0f07fd53
......@@ -18,6 +18,7 @@
"""custom storages for the system source"""
from os import unlink, path as osp
from contextlib import contextmanager
from yams.schema import role_name
......@@ -93,6 +94,17 @@ def uniquify_path(dirpath, basename):
return path
return None
@contextmanager
def fsimport(session):
present = 'fs_importing' in session.transaction_data
old_value = session.transaction_data.get('fs_importing')
session.transaction_data['fs_importing'] = True
yield
if present:
session.transaction_data['fs_importing'] = old_value
else:
del session.transaction_data['fs_importing']
class BytesFileSystemStorage(Storage):
"""store Bytes attribute value on the file system"""
......
......@@ -263,6 +263,35 @@ class StorageTC(CubicWebTC):
self.assertEqual(self.fspath(f1), new_fspath)
self.failIf(osp.isfile(old_fspath))
@tag('fsimport')
def test_clean(self):
fsimport = storages.fsimport
td = self.session.transaction_data
self.assertNotIn('fs_importing', td)
with fsimport(self.session):
self.assertIn('fs_importing', td)
self.assertTrue(td['fs_importing'])
self.assertNotIn('fs_importing', td)
@tag('fsimport')
def test_true(self):
fsimport = storages.fsimport
td = self.session.transaction_data
td['fs_importing'] = True
with fsimport(self.session):
self.assertIn('fs_importing', td)
self.assertTrue(td['fs_importing'])
self.assertTrue(td['fs_importing'])
@tag('fsimport')
def test_False(self):
fsimport = storages.fsimport
td = self.session.transaction_data
td['fs_importing'] = False
with fsimport(self.session):
self.assertIn('fs_importing', td)
self.assertTrue(td['fs_importing'])
self.assertFalse(td['fs_importing'])
if __name__ == '__main__':
unittest_main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment