Пример #1
0
    def test_update_detail_object(self):
        """Test converting to a dictionary"""
        ar = ActivityRecord(ActivityType.CODE,
                            show=True,
                            message="added some code",
                            importance=50,
                            linked_commit='aaaaaaaa')

        adr1 = ActivityDetailRecord(ActivityDetailType.CODE)
        adr1.show = True
        adr1.importance = 100
        adr1.add_value("text/plain", "first")
        ar.add_detail_object(adr1)

        adr2 = ActivityDetailRecord(ActivityDetailType.CODE)
        adr2.show = True
        adr2.importance = 0
        adr2.add_value("text/plain", "second")
        ar.add_detail_object(adr2)

        assert len(ar._detail_objects) == 2
        assert ar._detail_objects[0][3].data['text/plain'] == 'first'
        assert ar._detail_objects[1][3].data['text/plain'] == 'second'

        adr2.importance = 200

        with ar.inspect_detail_objects():
            ar.update_detail_object(adr2, 1)

        assert len(ar._detail_objects) == 2
        assert ar._detail_objects[0][3].data['text/plain'] == 'second'
        assert ar._detail_objects[1][3].data['text/plain'] == 'first'
Пример #2
0
    def create_activity_record(self, record: ActivityRecord) -> ActivityRecord:
        """Method to write an activity record and its details to the git log and detaildb

        Args:
            record(ActivityRecord): A populated activity record

        Returns:
            ActivityRecord
        """
        # If there isn't a linked commit, generate a UUID to uniquely ID the data in levelDB that will never
        # collide with the actual git hash space by making it 32 char vs. 40 for git
        if not record.linked_commit:
            record.linked_commit = uuid.uuid4().hex

        # Write all ActivityDetailObjects to the datastore
        with record.inspect_detail_objects() as details:
            for idx, detail in enumerate(details):
                updated_detail = self.put_detail_record(detail)
                record.update_detail_object(updated_detail, idx)

        # Add everything in the repo activity/log directory
        self.repository.git.add_all(self.detaildb.root_path)

        # Commit changes and update record
        commit = self.repository.git.commit(record.log_str)
        record.commit = commit.hexsha

        # Update record with username and email
        record.username = self.repository.git.author.name
        record.email = self.repository.git.author.email

        logger.debug(f"Successfully created ActivityRecord {commit.hexsha}")
        return record