Exemple #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'
    def test_put_get_activity_record(self, mock_config_with_activitystore):
        """Method to test creating and getting an individual activity record"""
        adr1 = ActivityDetailRecord(ActivityDetailType.CODE)
        adr1.show = True
        adr1.importance = 100
        adr1.add_value("text/plain", "this is a thing" * 1000)
        adr1.tags = ['tag1', 'tag2']

        adr2 = ActivityDetailRecord(ActivityDetailType.RESULT)
        adr2.show = False
        adr2.importance = 0
        adr2.add_value("text/plain", "another item")
        adr2.tags = ['tag1', 'tag2']

        linked_commit = helper_create_labbook_change(mock_config_with_activitystore[1], 1)

        ar = ActivityRecord(ActivityType.CODE,
                            show=True,
                            message="added some code",
                            importance=50,
                            linked_commit=linked_commit.hexsha)

        ar.add_detail_object(adr1)
        ar.add_detail_object(adr2)

        assert ar.commit is None

        # Create Activity Record
        ar_written = mock_config_with_activitystore[0].create_activity_record(ar)
        assert ar.commit is not None
        assert ar.username == 'default'
        assert ar.email == '*****@*****.**'

        # Get Note and check
        stored_ar = mock_config_with_activitystore[0].get_activity_record(ar_written.commit)

        assert ar.commit == stored_ar.commit
        assert ar.importance == stored_ar.importance
        assert ar.linked_commit == stored_ar.linked_commit
        assert ar.log_str == stored_ar.log_str
        assert ar.message == stored_ar.message
        assert ar.show == stored_ar.show
        assert ar.tags == stored_ar.tags
        assert ar.type == stored_ar.type
        assert len(ar._detail_objects) == len(stored_ar._detail_objects)

        assert ar._detail_objects[0][0] == stored_ar._detail_objects[0][0]
        assert ar._detail_objects[0][1] == stored_ar._detail_objects[0][1]
        assert ar._detail_objects[0][2] == stored_ar._detail_objects[0][2]

        assert ar._detail_objects[0][3].is_loaded is True
        assert ar._detail_objects[1][3].is_loaded is True

        assert stored_ar._detail_objects[0][3].is_loaded is False
        assert stored_ar._detail_objects[1][3].is_loaded is False

        assert stored_ar.username == 'default'
        assert stored_ar.email == '*****@*****.**'
    def test_put_get_detail_record_with_tags(self, mock_config_with_activitystore):
        """Test to test storing and retrieving data from the activity detail db"""
        # Create test values
        adr1 = ActivityDetailRecord(ActivityDetailType.CODE, action=ActivityAction.CREATE)
        adr1.show = True
        adr1.importance = 100
        adr1.add_value("text/plain", "first")
        adr1.tags = ['test1']

        adr2 = ActivityDetailRecord(ActivityDetailType.CODE_EXECUTED, action=ActivityAction.EXECUTE)
        adr2.show = True
        adr2.importance = 0
        adr2.add_value("text/plain", "second")
        adr2.tags = ['test2', 'test:3']

        adr1 = mock_config_with_activitystore[0].put_detail_record(adr1)
        adr2 = mock_config_with_activitystore[0].put_detail_record(adr2)

        assert adr1.key is not None
        assert adr2.key is not None
        assert type(adr1.key) == str
        assert type(adr2.key) == str

        # Load
        adr1_loaded = mock_config_with_activitystore[0].get_detail_record(adr1.key)
        adr2_loaded = mock_config_with_activitystore[0].get_detail_record(adr2.key)

        assert adr1.key == adr1_loaded.key
        assert adr1.importance == adr1_loaded.importance
        assert adr1.type == adr1_loaded.type
        assert adr1.is_loaded == adr1_loaded.is_loaded is True
        assert adr1.data == adr1_loaded.data
        assert adr1.tags == adr1_loaded.tags
        assert adr1.action == adr1_loaded.action == ActivityAction.CREATE

        assert adr2.key == adr2_loaded.key
        assert adr2.importance == adr2_loaded.importance
        assert adr2.type == adr2_loaded.type
        assert adr2.is_loaded == adr2_loaded.is_loaded is True
        assert adr2.data == adr2_loaded.data
        assert adr2.tags == adr2_loaded.tags
        assert adr2.action == adr2_loaded.action == ActivityAction.EXECUTE
Exemple #4
0
    def test_trim_detail_objects(self):
        """"""
        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)

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

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

        with ar.inspect_detail_objects():
            ar.trim_detail_objects(2)

        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'

        with pytest.raises(ValueError):
            with ar.inspect_detail_objects():
                ar.trim_detail_objects(0)
    def test_put_get_detail_record_with_compression(self, mock_config_with_activitystore):
        """Test to test storing and retrieving data from the activity detail db w/ compression"""
        # Create test values
        adr1 = ActivityDetailRecord(ActivityDetailType.CODE)
        adr1.show = True
        adr1.importance = 100
        adr1.add_value("text/plain", "first" * 1000)

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

        adr1 = mock_config_with_activitystore[0].put_detail_record(adr1)
        adr2 = mock_config_with_activitystore[0].put_detail_record(adr2)

        assert adr1.key is not None
        assert adr2.key is not None
        assert type(adr1.key) == str
        assert type(adr2.key) == str

        # Load
        adr1_loaded = mock_config_with_activitystore[0].get_detail_record(adr1.key)
        adr2_loaded = mock_config_with_activitystore[0].get_detail_record(adr2.key)

        assert adr1.key == adr1_loaded.key
        assert adr1.importance == adr1_loaded.importance
        assert adr1.type == adr1_loaded.type
        assert adr1.is_loaded == adr1_loaded.is_loaded is True
        assert adr1.data == adr1_loaded.data

        assert adr2.key == adr2_loaded.key
        assert adr2.importance == adr2_loaded.importance
        assert adr2.type == adr2_loaded.type
        assert adr2.is_loaded == adr2_loaded.is_loaded is True
        assert adr2.data == adr2_loaded.data
Exemple #6
0
    def test_add_detail_objects_sort(self):
        """Test adding values to the detail object"""
        ar = ActivityRecord(ActivityType.CODE,
                            show=True,
                            message="added some code",
                            importance=50,
                            linked_commit='aaaaaaaa')

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

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

        adr = ActivityDetailRecord(ActivityDetailType.CODE)
        adr.show = False
        adr.importance = 0
        adr.add_value("text/plain", "sixth")
        ar.add_detail_object(adr)

        adr = ActivityDetailRecord(ActivityDetailType.OUTPUT_DATA)
        adr.show = True
        adr.importance = 201
        adr.add_value("text/plain", "forth")
        ar.add_detail_object(adr)

        adr = ActivityDetailRecord(ActivityDetailType.RESULT)
        adr.show = True
        adr.importance = 201
        adr.add_value("text/plain", "third")
        ar.add_detail_object(adr)

        adr = ActivityDetailRecord(ActivityDetailType.INPUT_DATA)
        adr.show = False
        adr.importance = 201
        adr.add_value("text/plain", "fifth")
        ar.add_detail_object(adr)

        assert len(ar._detail_objects) == 6

        assert ar._detail_objects[0][3].data['text/plain'] == 'first'
        assert ar._detail_objects[1][3].data['text/plain'] == 'second'
        assert ar._detail_objects[2][3].data['text/plain'] == 'third'
        assert ar._detail_objects[3][3].data['text/plain'] == 'forth'
        assert ar._detail_objects[4][3].data['text/plain'] == 'fifth'
        assert ar._detail_objects[5][3].data['text/plain'] == 'sixth'