def test_compression(self):
        """Test compression on large objects"""
        adr = ActivityDetailRecord(ActivityDetailType.INPUT_DATA, key="my_ke3", show=True, importance=125)
        adr.add_value("text/plain", "this is some data00000000000000000000000000000000000" * 1000)

        byte_array_no_compression = adr.to_bytes(compress=False)
        assert type(byte_array_no_compression) == bytes

        adr2 = ActivityDetailRecord(ActivityDetailType.INPUT_DATA, key="my_ke3", show=True, importance=125)
        adr2.add_value("text/plain", "this is some data00000000000000000000000000000000000" * 1000)
        byte_array_compression = adr2.to_bytes(compress=True)
        assert type(byte_array_compression) == bytes

        assert len(byte_array_compression) < len(byte_array_no_compression)

        adr3 = ActivityDetailRecord.from_bytes(byte_array_compression, decompress=True)

        assert type(adr3) == ActivityDetailRecord
        assert adr3.type == ActivityDetailType.INPUT_DATA
        assert adr3.action == ActivityAction.NOACTION
        assert adr3.key is None
        assert adr3.show is True
        assert adr3.importance == 125
        assert adr3.tags == []
        assert adr3.data == adr.data
    def test_to_bytes_from_bytes(self):
        """Test converting to a byte array"""
        adr = ActivityDetailRecord(ActivityDetailType.CODE_EXECUTED, key="my_key3", show=True, importance=225,
                                   action=ActivityAction.CREATE)
        adr.add_value("text/plain", "this is some data")

        byte_array_no_compression = adr.to_bytes(compress=False)
        assert type(byte_array_no_compression) == bytes

        adr2 = ActivityDetailRecord.from_bytes(byte_array_no_compression, decompress=False)

        assert type(adr2) == ActivityDetailRecord
        assert adr2.type == ActivityDetailType.CODE_EXECUTED
        assert adr2.action == ActivityAction.CREATE
        assert adr2.key is None
        assert adr2.show is True
        assert adr2.importance == 225
        assert adr2.tags == []
        assert adr2.data == {"text/plain": "this is some data"}
Exemple #3
0
    def get_detail_record(self, detail_key: str) -> ActivityDetailRecord:
        """Method to fetch a detail entry from the activity detail db

            Args:
                detail_key : the key returned from the activity detail DB when storing.

            Returns:
                 ActivityDetailRecord
        """
        # Get value from key-value store
        detail_bytes = self.detaildb.get(detail_key)

        # Remove header
        options = self._decode_write_options(detail_bytes[:1])

        # Create object
        record = ActivityDetailRecord.from_bytes(
            detail_bytes[1:], decompress=options['compress'])
        record.key = detail_key
        return record