diff -r 48d70d143dc1 -r a6dc650bc230 cubicweb/server/test/unittest_migractions.py --- a/cubicweb/server/test/unittest_migractions.py Mon Oct 24 09:29:08 2016 +0200 +++ b/cubicweb/server/test/unittest_migractions.py Mon Oct 24 09:31:55 2016 +0200 @@ -24,7 +24,7 @@ import tempfile from hashlib import md5 -from logilab.common.testlib import unittest_main, Tags, tag, with_tempdir +from logilab.common.testlib import unittest_main, Tags, tag from logilab.common import tempattr from yams.constraints import UniqueConstraint @@ -32,7 +32,7 @@ from cubicweb import (ConfigurationError, ValidationError, ExecutionError, Binary) from cubicweb.devtools import startpgcluster, stoppgcluster -from cubicweb.devtools.testlib import CubicWebTC +from cubicweb.devtools.testlib import CubicWebTC, TemporaryDirectory from cubicweb.server.sqlutils import SQL_PREFIX from cubicweb.server.migractions import ServerMigrationHelper from cubicweb.server.sources import storages @@ -798,28 +798,28 @@ mh.drop_relation_definition('Note', 'ecrit_par', 'CWUser') self.assertFalse(mh.sqlexec('SELECT * FROM cw_Note WHERE cw_ecrit_par IS NOT NULL')) - @with_tempdir def test_storage_changed(self): with self.mh() as (cnx, mh): john = mh.cmd_create_entity('Personne', nom=u'john', photo=Binary(b'something')) bill = mh.cmd_create_entity('Personne', nom=u'bill') mh.commit() - bfs_storage = storages.BytesFileSystemStorage(tempfile.tempdir) - storages.set_attribute_storage(self.repo, 'Personne', 'photo', bfs_storage) - mh.cmd_storage_changed('Personne', 'photo') - bob = mh.cmd_create_entity('Personne', nom=u'bob') - bffss_dir_content = os.listdir(tempfile.tempdir) - self.assertEqual(len(bffss_dir_content), 1) - john.cw_clear_all_caches() - self.assertEqual(john.photo.getvalue(), - osp.join(tempfile.tempdir, - bffss_dir_content[0]).encode('utf8')) - bob.cw_clear_all_caches() - self.assertIsNone(bob.photo) - bill.cw_clear_all_caches() - self.assertIsNone(bill.photo) - storages.unset_attribute_storage(self.repo, 'Personne', 'photo') + with TemporaryDirectory() as tempdir: + bfs_storage = storages.BytesFileSystemStorage(tempdir) + storages.set_attribute_storage(self.repo, 'Personne', 'photo', bfs_storage) + mh.cmd_storage_changed('Personne', 'photo') + bob = mh.cmd_create_entity('Personne', nom=u'bob') + bffss_dir_content = os.listdir(tempdir) + self.assertEqual(len(bffss_dir_content), 1) + john.cw_clear_all_caches() + self.assertEqual(john.photo.getvalue(), + osp.join(tempdir, + bffss_dir_content[0]).encode('utf8')) + bob.cw_clear_all_caches() + self.assertIsNone(bob.photo) + bill.cw_clear_all_caches() + self.assertIsNone(bill.photo) + storages.unset_attribute_storage(self.repo, 'Personne', 'photo') class MigrationCommandsComputedTC(MigrationTC):