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_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
Ejemplo n.º 3
0
 def add_labels(self, event_id, document_name, index_name, labels, adapter):
     request = events_pb2.AddLabelsRequest(event_id=event_id,
                                           document_name=document_name,
                                           index_name=index_name,
                                           no_key_validation=True)
     adapter.add_to_message(labels, request)
     response = self.stub.AddLabels(request)
     return response is not None
Ejemplo n.º 4
0
def test_AddLabels_bad_event(events_server):
    request = events_pb2.AddLabelsRequest(event_id='1',
                                          document_name='plaintext',
                                          index_name='labels')
    label = request.generic_labels.labels.add()
    label.start_index = 15
    label.end_index = 20
    label.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.NOT_FOUND
Ejemplo n.º 5
0
def test_AddLabels_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)
    request = events_pb2.AddLabelsRequest(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['AddLabels'], {}, request, None).termination()
    assert status_code == grpc.StatusCode.OK
Ejemplo n.º 6
0
def test_AddLabels(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.json_labels.labels.add()
    s['start_index'] = 15
    s['end_index'] = 20
    s['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
Ejemplo n.º 7
0
def test_AddLabels_bad_index_name(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='')
    label = request.generic_labels.labels.add()
    label.start_index = 15
    label.end_index = 20
    label.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.INVALID_ARGUMENT
Ejemplo n.º 8
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