Exemple #1
0
    def test_configure_filedepot(self, no_filedepots):
        from depot.manager import DepotManager
        from kotti.filedepot import configure_filedepot
        from kotti import tests

        tests.TFS1 = Mock(return_value=Mock(marker="TFS1"))
        tests.TFS2 = Mock(return_value=Mock(marker="TFS2"))

        settings = {
            'kotti.depot.0.backend': 'kotti.tests.TFS1',
            'kotti.depot.0.name': 'localfs',
            'kotti.depot.0.location': '/tmp',
            'kotti.depot.1.backend': 'kotti.tests.TFS2',
            'kotti.depot.1.uri': 'mongo://',
            'kotti.depot.1.name': 'mongo',
        }

        configure_filedepot(settings)

        assert DepotManager.get().marker == 'TFS1'
        assert DepotManager.get('localfs').marker == 'TFS1'
        assert DepotManager.get('mongo').marker == 'TFS2'

        tests.TFS1.assert_called_with(location='/tmp')
        tests.TFS2.assert_called_with(uri='mongo://')

        del tests.TFS1
        del tests.TFS2
Exemple #2
0
    def test_configure_filedepot(self, no_filedepots):
        from depot.manager import DepotManager
        from kotti.filedepot import configure_filedepot
        from kotti import tests

        tests.TFS1 = Mock(return_value=Mock(marker="TFS1"))
        tests.TFS2 = Mock(return_value=Mock(marker="TFS2"))

        settings = {
            "kotti.depot.0.backend": "kotti.tests.TFS1",
            "kotti.depot.0.name": "localfs",
            "kotti.depot.0.location": "/tmp",
            "kotti.depot.1.backend": "kotti.tests.TFS2",
            "kotti.depot.1.uri": "mongo://",
            "kotti.depot.1.name": "mongo",
        }

        configure_filedepot(settings)

        assert DepotManager.get().marker == "TFS1"
        assert DepotManager.get("localfs").marker == "TFS1"
        assert DepotManager.get("mongo").marker == "TFS2"

        tests.TFS1.assert_called_with(location="/tmp")
        tests.TFS2.assert_called_with(uri="mongo://")

        del tests.TFS1
        del tests.TFS2
Exemple #3
0
    def test_configure_filedepot(self, no_filedepots):
        from depot.manager import DepotManager
        from kotti.filedepot import configure_filedepot
        from kotti import tests

        tests.TFS1 = Mock(return_value=Mock(marker="TFS1"))
        tests.TFS2 = Mock(return_value=Mock(marker="TFS2"))

        settings = {
            "kotti.depot.0.backend": "kotti.tests.TFS1",
            "kotti.depot.0.name": "localfs",
            "kotti.depot.0.location": "/tmp",
            "kotti.depot.1.backend": "kotti.tests.TFS2",
            "kotti.depot.1.uri": "mongo://",
            "kotti.depot.1.name": "mongo",
        }

        configure_filedepot(settings)

        assert DepotManager.get().marker == "TFS1"
        assert DepotManager.get("localfs").marker == "TFS1"
        assert DepotManager.get("mongo").marker == "TFS2"

        tests.TFS1.assert_called_with(location="/tmp")
        tests.TFS2.assert_called_with(uri="mongo://")

        del tests.TFS1
        del tests.TFS2
Exemple #4
0
    def test_configure_filedepot(self, no_filedepots):
        from depot.manager import DepotManager
        from kotti.filedepot import configure_filedepot
        from kotti import tests

        tests.TFS1 = Mock(return_value=Mock(marker="TFS1"))
        tests.TFS2 = Mock(return_value=Mock(marker="TFS2"))

        settings = {
            'kotti.depot.0.backend': 'kotti.tests.TFS1',
            'kotti.depot.0.name': 'localfs',
            'kotti.depot.0.location': '/tmp',
            'kotti.depot.1.backend': 'kotti.tests.TFS2',
            'kotti.depot.1.uri': 'mongo://',
            'kotti.depot.1.name': 'mongo',
        }

        configure_filedepot(settings)

        assert DepotManager.get().marker == 'TFS1'
        assert DepotManager.get('localfs').marker == 'TFS1'
        assert DepotManager.get('mongo').marker == 'TFS2'

        tests.TFS1.assert_called_with(location='/tmp')
        tests.TFS2.assert_called_with(uri='mongo://')

        del tests.TFS1
        del tests.TFS2
Exemple #5
0
    def test_migrate_between_storages(self, db_session, root, no_filedepots):
        from kotti.filedepot import configure_filedepot
        from kotti.filedepot import migrate_storage
        from kotti.resources import Node
        from depot.fields.sqlalchemy import _SQLAMutationTracker
        from sqlalchemy import event
        import os
        import tempfile
        import shutil

        event.listen(db_session, 'before_commit',
                     _SQLAMutationTracker._session_committed)

        tmp_location = tempfile.mkdtemp()

        settings = {
            'kotti.depot.0.backend': 'kotti.filedepot.DBFileStorage',
            'kotti.depot.0.name': 'dbfiles',
            'kotti.depot.1.backend': 'depot.io.local.LocalFileStorage',
            'kotti.depot.1.name': 'localfs',
            'kotti.depot.1.storage_path': tmp_location,
        }

        configure_filedepot(settings)
        self._create_content(db_session, root)

        assert db_session.query(DBStoredFile).count() == 4

        migrate_storage('dbfiles', 'localfs')

        folders = os.listdir(tmp_location)
        assert len(folders) == 4

        db_session.flush()

        # here we need a transaction.commit(), but that would mess with the
        # rest of the tests; we'll just trigger the event handler manually
        _SQLAMutationTracker._session_committed(db_session)

        root = db_session.query(Node).filter_by(parent=None).one()
        f1 = root['file1.jpg']
        assert f1.data.file_id in folders
        assert f1.data.file.read() == 'f1...'

        f2 = root['file2.png']
        assert f2.data.file_id in folders
        assert f2.data.file.read() == 'f2...'

        i1 = root['image1.jpg']
        assert i1.data.file_id in folders
        assert i1.data.file.read() == 'i1...'

        i2 = root['image2.png']
        assert i2.data.file_id in folders
        assert i2.data.file.read() == 'i2...'

        assert db_session.query(DBStoredFile).count() == 0

        shutil.rmtree(tmp_location)
    def test_migrate_between_storages(self, db_session, root, no_filedepots,
                                      image_asset, image_asset2):
        from kotti.filedepot import configure_filedepot
        from kotti.filedepot import migrate_storage
        from kotti.resources import Node
        from depot.fields.sqlalchemy import _SQLAMutationTracker
        from sqlalchemy import event
        import os
        import tempfile
        import shutil

        event.listen(db_session,
                     'before_commit',
                     _SQLAMutationTracker._session_committed)

        tmp_location = tempfile.mkdtemp()

        settings = {
            'kotti.depot.0.backend': 'kotti.filedepot.DBFileStorage',
            'kotti.depot.0.name': 'dbfiles',

            'kotti.depot.1.backend': 'depot.io.local.LocalFileStorage',
            'kotti.depot.1.name': 'localfs',
            'kotti.depot.1.storage_path': tmp_location,
        }

        configure_filedepot(settings)
        image1 = image_asset.read()
        image2 = image_asset2.read()
        self._create_content(db_session, root, image1, image2)

        assert db_session.query(DBStoredFile).count() == 8

        migrate_storage('dbfiles', 'localfs')

        folders = os.listdir(tmp_location)
        assert len(folders) == 8

        db_session.flush()

        # here we need a transaction.commit(), but that would mess with the
        # rest of the tests; we'll just trigger the event handler manually
        _SQLAMutationTracker._session_committed(db_session)

        root = db_session.query(Node).filter_by(parent=None).one()
        f1 = root['file1.jpg']
        assert f1.data.file_id in folders
        assert f1.data.file.read() == 'f1...'

        f2 = root['file2.png']
        assert f2.data.file_id in folders
        assert f2.data.file.read() == 'f2...'

        i1 = root['image1.jpg']
        assert i1.data.file_id in folders
        i1data = i1.data.file.read()
        assert i1data == image2

        i2 = root['image2.png']
        assert i2.data.file_id in folders
        i2data = i2.data.file.read()
        assert i2data == image1

        assert db_session.query(DBStoredFile).count() == 0

        shutil.rmtree(tmp_location)
Exemple #7
0
    def test_migrate_between_storages(
        self, db_session, root, no_filedepots, image_asset, image_asset2
    ):
        from kotti.filedepot import configure_filedepot
        from kotti.filedepot import migrate_storage
        from kotti.resources import Node
        from depot.fields.sqlalchemy import _SQLAMutationTracker
        from sqlalchemy import event
        import os
        import tempfile
        import shutil

        event.listen(
            db_session, "before_commit", _SQLAMutationTracker._session_committed
        )

        tmp_location = tempfile.mkdtemp()

        settings = {
            "kotti.depot.0.backend": "kotti.filedepot.DBFileStorage",
            "kotti.depot.0.name": "dbfiles",
            "kotti.depot.1.backend": "depot.io.local.LocalFileStorage",
            "kotti.depot.1.name": "localfs",
            "kotti.depot.1.storage_path": tmp_location,
        }

        configure_filedepot(settings)
        image1 = image_asset.read()
        image2 = image_asset2.read()
        self._create_content(db_session, root, image1, image2)

        assert db_session.query(DBStoredFile).count() == 4

        migrate_storage("dbfiles", "localfs")

        folders = os.listdir(tmp_location)
        assert len(folders) == 4

        db_session.flush()

        # here we need a transaction.commit(), but that would mess with the
        # rest of the tests; we'll just trigger the event handler manually
        _SQLAMutationTracker._session_committed(db_session)

        root = db_session.query(Node).filter_by(parent=None).one()
        f1 = root["file1.jpg"]
        assert f1.data.file_id in folders
        assert f1.data.file.read() == b"f1..."

        f2 = root["file2.png"]
        assert f2.data.file_id in folders
        assert f2.data.file.read() == b"f2..."

        i1 = root["image1.jpg"]
        assert i1.data.file_id in folders
        i1data = i1.data.file.read()
        assert i1data == image2

        i2 = root["image2.png"]
        assert i2.data.file_id in folders
        i2data = i2.data.file.read()
        assert i2data == image1

        assert db_session.query(DBStoredFile).count() == 0

        shutil.rmtree(tmp_location)