def test_migrate_no_op_on_new_labbook(self, mock_labbook_lfs_disabled):
        username = '******'
        lb = mock_labbook_lfs_disabled[2]
        wf = LabbookWorkflow(lb)

        h1 = wf.labbook.git.commit_hash
        wf.migrate()

        # No change of git status after no-op migration
        assert h1 == wf.labbook.git.commit_hash
Пример #2
0
    def mutate_and_get_payload(cls,
                               root,
                               info,
                               owner,
                               labbook_name,
                               client_mutation_id=None):
        username = get_logged_in_username()
        lb = InventoryManager().load_labbook(username,
                                             owner,
                                             labbook_name,
                                             author=get_logged_in_author())

        migrated = False
        with lb.lock():
            t0 = time.time()
            workflow = LabbookWorkflow(lb)
            migrated = workflow.migrate()
            tf = time.time()

        if migrated:
            logger.info(f"Migrated {str(lb)} in {tf-t0:.2}sec")
        else:
            logger.info(f"No migration needed for {str(lb)}")

        return MigrateLabbookSchema(
            Labbook(id=f"{owner}&{labbook_name}",
                    name=labbook_name,
                    owner=owner))
    def test_should_migrate_on_old_project(self, mock_config_file):
        p = resource_filename('gtmcore', 'workflows')
        p2 = os.path.join(p, 'tests', 'lb-to-migrate-197b6a.zip')
        with tempfile.TemporaryDirectory() as tempdir:
            lbp = shutil.copyfile(p2, os.path.join(tempdir,
                                                   'lb-to-migrate.zip'))
            subprocess.run(f'unzip lb-to-migrate.zip'.split(),
                           check=True,
                           cwd=tempdir)

            im = InventoryManager(mock_config_file[0])
            lb = im.load_labbook_from_directory(
                os.path.join(tempdir, 'lb-to-migrate'))
            wf = LabbookWorkflow(lb)

            assert wf.should_migrate() is True

            wf.migrate()

            assert wf.labbook.active_branch == 'master'
            assert wf.should_migrate() is False

            wf.labbook.git.checkout('gm.workspace')
            assert wf.should_migrate() is False
    def test_migrate_old_schema_1_project(self, mock_config_file):
        """ Test migrating a very old schema 1/gm.workspace LabBook """
        p = resource_filename('gtmcore', 'workflows')
        p2 = os.path.join(p, 'tests', 'snappy.zip')

        with tempfile.TemporaryDirectory() as td:
            call_subprocess(f"unzip {p2} -d {td}".split(), cwd=td)
            temp_lb_path = os.path.join(td, 'snappy')

            # Tests backwards compatibility (test.zip is a very old schema 1 LabBook)
            lb = InventoryManager(
                mock_config_file[0]).load_labbook_from_directory(temp_lb_path)
            wf = LabbookWorkflow(lb)

            wf.labbook.remove_remote()
            wf.migrate()

            # Test that current branch is as appropriate
            assert wf.labbook.active_branch == 'master'

            # Test that there is an activity record indicate migration
            assert any([
                'Migrate schema to 2' in c['message']
                for c in wf.labbook.git.log()[:5]
            ])

            # Test schema has successfully rolled to 2
            assert wf.labbook.schema == 2

            # Test that untracked space exists (if we add something to untracked space)
            assert wf.labbook.is_repo_clean
            with open(
                    os.path.join(lb.root_dir, 'output/untracked',
                                 'untracked-file'), 'wb') as fb:
                fb.write(b'cat' * 100)
            assert wf.labbook.is_repo_clean