Ejemplo n.º 1
0
def test_GetLabels(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'
    events_server.invoke_unary_unary(
        events_pb2.DESCRIPTOR.services_by_name['Events'].
        methods_by_name['AddLabels'], {}, request, None)

    req = events_pb2.GetLabelsRequest(event_id='1',
                                      document_name='plaintext',
                                      index_name='labels')
    res, _, status_code, _ = events_server.invoke_unary_unary(
        events_pb2.DESCRIPTOR.services_by_name['Events'].
        methods_by_name['GetLabels'], {}, req, None).termination()
    assert len(res.generic_labels.labels) == 1
    label = res.generic_labels.labels[0]
    assert label.start_index == 15
    assert label.end_index == 20
    assert label.fields['some_other_field'] == 'blah'
Ejemplo n.º 2
0
def test_GetLabels_bad_event(events_server):
    r = events_pb2.GetLabelsRequest(event_id='1',
                                    document_name='plaintext',
                                    index_name='labels')
    _, _, status_code, _ = events_server.invoke_unary_unary(
        events_pb2.DESCRIPTOR.services_by_name['Events'].
        methods_by_name['GetLabels'], {}, r, None).termination()
    assert status_code == grpc.StatusCode.NOT_FOUND
Ejemplo n.º 3
0
def test_GetLabels_no_labels(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)
    events_server.invoke_unary_unary(
        events_pb2.DESCRIPTOR.services_by_name['Events'].
        methods_by_name['AddLabels'], {},
        events_pb2.AddLabelsRequest(event_id='1',
                                    document_name='plaintext',
                                    index_name='labels'), None)
    req = events_pb2.GetLabelsRequest(event_id='1',
                                      document_name='plaintext',
                                      index_name='labels')
    res, _, status_code, _ = events_server.invoke_unary_unary(
        events_pb2.DESCRIPTOR.services_by_name['Events'].
        methods_by_name['GetLabels'], {}, req, None).termination()
    assert len(res.generic_labels.labels) == 0
Ejemplo n.º 4
0
 def get_labels(self, event_id, document_name, index_name, adapter):
     request = events_pb2.GetLabelsRequest(event_id=event_id,
                                           document_name=document_name,
                                           index_name=index_name)
     response = self.stub.GetLabels(request)
     return adapter.create_index_from_response(response)