Exemplo n.º 1
0
    def mutate_and_get_payload(cls,
                               root,
                               info,
                               name,
                               description,
                               repository,
                               base_id,
                               revision,
                               is_untracked=False,
                               client_mutation_id=None):
        username = get_logged_in_username()
        inv_manager = InventoryManager()
        if is_untracked:
            lb = inv_manager.create_labbook_disabled_lfs(
                username=username,
                owner=username,
                labbook_name=name,
                description=description,
                author=get_logged_in_author())
        else:
            lb = inv_manager.create_labbook(username=username,
                                            owner=username,
                                            labbook_name=name,
                                            description=description,
                                            author=get_logged_in_author())

        if is_untracked:
            FileOperations.set_untracked(lb, 'input')
            FileOperations.set_untracked(lb, 'output')
            input_set = FileOperations.is_set_untracked(lb, 'input')
            output_set = FileOperations.is_set_untracked(lb, 'output')
            if not (input_set and output_set):
                raise ValueError(
                    f'{str(lb)} untracking for input/output in malformed state'
                )
            if not lb.is_repo_clean:
                raise ValueError(
                    f'{str(lb)} should have clean Git state after setting for untracked'
                )

        adr = ActivityDetailRecord(ActivityDetailType.LABBOOK,
                                   show=False,
                                   importance=0)
        adr.add_value('text/plain', f"Created new LabBook: {username}/{name}")

        # Create activity record
        ar = ActivityRecord(ActivityType.LABBOOK,
                            message=f"Created new LabBook: {username}/{name}",
                            show=True,
                            importance=255,
                            linked_commit=lb.git.commit_hash)
        ar.add_detail_object(adr)

        store = ActivityStore(lb)
        store.create_activity_record(ar)

        cm = ComponentManager(lb)
        cm.add_base(repository, base_id, revision)

        return CreateLabbook(labbook=Labbook(owner=username, name=lb.name))
Exemplo n.º 2
0
    def test_set_new_lb_section_for_large_files(self, mock_labbook):
        x, y, lb = mock_labbook

        assert FileOperations.is_set_untracked(labbook=lb,
                                               section='input') is False

        FileOperations.set_untracked(labbook=lb, section='input')

        assert FileOperations.is_set_untracked(labbook=lb,
                                               section='input') is True
        assert FileOperations.is_set_untracked(labbook=lb,
                                               section='code') is False

        # 1 - Ensure there are no untracked changes after the set operation
        s = lb.git.status()
        for key in s.keys():
            assert not s[key]

        # 2 - Add a file to the input directory using the old-fashioned add file op.
        with open('/tmp/unittestfile', 'w') as f:
            f.write('------------------------\n')
        r = FileOperations.put_file(lb,
                                    section="input",
                                    src_file=f.name,
                                    dst_path='')
        assert os.path.isfile(
            os.path.join(lb.root_dir, 'input', 'unittestfile'))

        # 3 - Make sure the new file exists but is not tracked (i.e., the git commit is the same)
        s = lb.git.status()
        for key in s.keys():
            assert not s[key]
Exemplo n.º 3
0
    def test_with_the_whole_suite_of_file_operations_on_an_UNTRACKED_labbook(
            self, mock_labbook):
        x, y, lb = mock_labbook

        hash_0 = lb.git.commit_hash
        FileOperations.set_untracked(labbook=lb, section='input')
        hash_1 = lb.git.commit_hash
        assert hash_0 != hash_1

        with open('/tmp/unittestfile', 'wb') as f:
            f.write('àbčdęfghįjkłmñöpqrštūvwxÿż0123456789'.encode('utf-8'))
        assert not os.path.exists(
            os.path.join(lb.root_dir, 'input', 'unittestfile'))
        r = FileOperations.put_file(lb,
                                    section="input",
                                    src_file=f.name,
                                    dst_path='')
        assert os.path.exists(
            os.path.join(lb.root_dir, 'input', 'unittestfile'))
        hash_2 = lb.git.commit_hash

        FileOperations.delete_files(lb,
                                    section='input',
                                    relative_paths=['unittestfile'])
        hash_3 = lb.git.commit_hash
        target_path = os.path.join(lb.root_dir, 'input', 'unittestfile')
        assert not os.path.exists(target_path)
        assert lb.is_repo_clean
        # Hash_2 == hash_3 because we delete a file in an UNTRACKED section
        assert hash_2 == hash_3

        FileOperations.makedir(lb, 'input/sample-untracked-dir/nested-dir')
        hash_4 = lb.git.commit_hash
        assert hash_3 == hash_4
        with open('/tmp/unittestfile', 'wb') as f:
            f.write('aaaaaæ'.encode('utf-8'))
        FileOperations.put_file(lb,
                                section='input',
                                src_file=f.name,
                                dst_path='sample-untracked-dir/nested-dir')
        hash_5 = lb.git.commit_hash
        assert hash_4 == hash_5

        FileOperations.move_file(
            lb,
            section='input',
            src_rel_path='sample-untracked-dir/nested-dir/unittestfile',
            dst_rel_path='unittestfile')
        assert not os.path.exists(
            os.path.join(lb.root_dir, 'input',
                         'sample-untracked-dir/nested-dir/unittestfile'))
        assert os.path.exists(
            os.path.join(lb.root_dir, 'input', 'unittestfile'))
        hash_6 = lb.git.commit_hash
        assert hash_5 == hash_6

        FileOperations.delete_files(
            lb,
            section='input',
            relative_paths=['sample-untracked-dir/nested-dir'])
        hash_7 = lb.git.commit_hash
        assert hash_6 == hash_7