def test_multiplecells(self, redis_client, mock_labbook):
        """Make sure that RStudio detects and splits cells"""

        server_monitor = RStudioServerMonitor("test",
                                              "test",
                                              mock_labbook[2].name,
                                              "foo:activity_monitor:73467b78",
                                              config_file=mock_labbook[0])

        mitmlog = open(
            f"{os.path.dirname(os.path.realpath(__file__))}/73467b78.rserver.dump",
            "rb")

        # Read activity and return an aggregated activity record
        server_monitor.process_activity(mitmlog)
        # call processor
        server_monitor.store_record()

        a_store = ActivityStore(mock_labbook[2])
        ars = a_store.get_activity_records()

        # details object [x][3] gets the x^th object
        cell_1 = a_store.get_detail_record(
            ars[0]._detail_objects[2][3].key).data
        cell_2 = a_store.get_detail_record(
            ars[0]._detail_objects[3][3].key).data

        # if the cells were divided, there will be two records
        assert (cell_1['text/plain'][55:58] == 'pop')
        assert (cell_2['text/plain'][200:204] == 'stan')
    def test_code_and_image(self, redis_client, mock_labbook):
        """Test reading a log and storing a record"""

        # create a server monitor
        server_monitor = RStudioServerMonitor("test",
                                              "test",
                                              mock_labbook[2].name,
                                              "foo:activity_monitor:52f5a3a9",
                                              config_file=mock_labbook[0])

        mitmlog = open(
            f"{os.path.dirname(os.path.realpath(__file__))}/52f5a3a9.rserver.dump",
            "rb")

        # Read activity and return an aggregated activity record
        server_monitor.process_activity(mitmlog)
        # call processor
        server_monitor.store_record()

        a_store = ActivityStore(mock_labbook[2])
        ars = a_store.get_activity_records()

        # details object [x][3] gets the x^th object
        code_dict = a_store.get_detail_record(
            ars[0]._detail_objects[1][3].key).data

        # check the code results
        assert (code_dict['text/markdown'][101:109] == 'y("knitr')

        # check part of an image
        imgdata = a_store.get_detail_record(
            ars[1]._detail_objects[1][3].key).data['image/png'][0:20]
        assert (imgdata == '/9j/4AAQSkZJRgABAQAA')
Example #3
0
    def help_resolve_recent_activity(self, labbook):
        """Method to create 4 activity records with show=True"""
        # Create instance of ActivityStore for this LabBook
        store = ActivityStore(labbook)

        records = list()
        # Get 4 records with show=True
        after = None
        while len(records) < 4:
            items = store.get_activity_records(first=4, after=after)

            if not items:
                # if no more items, continue
                break

            for item in items:
                if item.show is True and item.num_detail_objects > 0:
                    ar = ActivityRecordObject(
                        id=f"labbook&{self.owner}&{self.name}&{item.commit}",
                        owner=self.owner,
                        name=self.name,
                        _repository_type='labbook',
                        commit=item.commit,
                        _activity_record=item)
                    records.append(ar)
                    if len(records) >= 4:
                        break

                # Set after cursor to last commit
                after = item.commit

        return records
Example #4
0
    def helper_resolve_activity_records(self, dataset, kwargs):
        """Helper method to generate ActivityRecord objects and populate the connection"""
        # Create instance of ActivityStore for this dataset
        store = ActivityStore(dataset)

        if kwargs.get('before') or kwargs.get('last'):
            raise ValueError(
                "Only `after` and `first` arguments are supported when paging activity records"
            )

        # Get edges and cursors
        edges = store.get_activity_records(after=kwargs.get('after'),
                                           first=kwargs.get('first'))
        if edges:
            cursors = [x.commit for x in edges]
        else:
            cursors = []

        # Get ActivityRecordObject instances
        edge_objs = []
        for edge, cursor in zip(edges, cursors):
            edge_objs.append(
                ActivityConnection.Edge(node=ActivityRecordObject(
                    id=f"dataset&{self.owner}&{self.name}&{edge.commit}",
                    owner=self.owner,
                    name=self.name,
                    _repository_type='dataset',
                    commit=edge.commit,
                    _activity_record=edge),
                                        cursor=cursor))

        # Create page info based on first commit. Since only paging backwards right now, just check for commit
        if edges:
            has_next_page = True

            # Get the message of the linked commit and check if it is the non-activity record dataset creation commit
            if len(edges) > 1:
                if edges[-2].linked_commit != "no-linked-commit":
                    linked_msg = dataset.git.log_entry(
                        edges[-2].linked_commit)['message']
                    if linked_msg == f"Creating new empty Dataset: {dataset.name}" and "_GTM_ACTIVITY_" not in linked_msg:
                        # if you get here, this is the first activity record
                        has_next_page = False

            end_cursor = cursors[-1]
        else:
            has_next_page = False
            end_cursor = None

        page_info = graphene.relay.PageInfo(has_next_page=has_next_page,
                                            has_previous_page=False,
                                            end_cursor=end_cursor)

        return ActivityConnection(edges=edge_objs, page_info=page_info)