def test_GetLabelIndicesInfo(events_server): events_server.invoke_unary_unary( events_pb2.DESCRIPTOR.services_by_name['Events']. methods_by_name['OpenEvent'], {}, events_pb2.OpenEventRequest(event_id='1'), None) events_server.invoke_unary_unary( events_pb2.DESCRIPTOR.services_by_name['Events']. methods_by_name['AddDocument'], {}, events_pb2.AddDocumentRequest(event_id='1', document_name='plaintext', text=PHASERS), None) request = events_pb2.AddLabelsRequest(event_id='1', document_name='plaintext', index_name='labels') s = request.generic_labels.labels.add() s.start_index = 15 s.end_index = 20 s.fields['some_other_field'] = 'blah' _, _, status_code, _ = events_server.invoke_unary_unary( events_pb2.DESCRIPTOR.services_by_name['Events']. methods_by_name['AddLabels'], {}, request, None).termination() assert status_code == grpc.StatusCode.OK request = events_pb2.GetLabelIndicesInfoRequest(event_id='1', document_name='plaintext') res, _, status_code, _ = events_server.invoke_unary_unary( events_pb2.DESCRIPTOR.services_by_name['Events']. methods_by_name['GetLabelIndicesInfo'], {}, request, None).termination() assert status_code == grpc.StatusCode.OK assert len(res.label_index_infos) == 1 assert res.label_index_infos[0].index_name == 'labels' assert res.label_index_infos[ 0].type == events_pb2.GetLabelIndicesInfoResponse.LabelIndexInfo.GENERIC
def test_GetLabelIndicesInfo_bad_event(events_server): request = events_pb2.GetLabelIndicesInfoRequest(event_id='1', document_name='plaintext') _, _, status_code, _ = events_server.invoke_unary_unary( events_pb2.DESCRIPTOR.services_by_name['Events']. methods_by_name['GetLabelIndicesInfo'], {}, request, None).termination() assert status_code == grpc.StatusCode.NOT_FOUND
def get_label_index_info(self, event_id: str, document_name: str) -> List[LabelIndexInfo]: request = events_pb2.GetLabelIndicesInfoRequest( event_id=event_id, document_name=document_name) response = self.stub.GetLabelIndicesInfo(request) result = [] for index in response.label_index_infos: if index.type == events_pb2.GetLabelIndicesInfoResponse.LabelIndexInfo.JSON: index_type = LabelIndexType.JSON elif index.type == events_pb2.GetLabelIndicesInfoResponse.LabelIndexInfo.OTHER: index_type = LabelIndexType.OTHER else: index_type = LabelIndexType.UNKNOWN result.append(LabelIndexInfo(index.index_name, index_type)) return result
def get_label_index_info( self, event_id: str, document_name: str) -> List['data.LabelIndexInfo']: request = events_pb2.GetLabelIndicesInfoRequest( event_id=event_id, document_name=document_name) response = self.stub.GetLabelIndicesInfo(request) result = [] for index in response.label_index_infos: if index.type == events_pb2.GetLabelIndicesInfoResponse.LabelIndexInfo.GENERIC: index_type = _base.LabelIndexType.GENERIC elif index.type == events_pb2.GetLabelIndicesInfoResponse.LabelIndexInfo.CUSTOM: index_type = _base.LabelIndexType.CUSTOM else: index_type = _base.LabelIndexType.UNKNOWN result.append(_base.LabelIndexInfo(index.index_name, index_type)) return result