jeudi 24 novembre 2016

Testing method using grpc.ServicerContext object in Python

I am trying to test the following method:

def my_method(self, request, context):
    context.set_details('Already exists')
    context.set_code(grpc.StatusCode.ALREADY_EXISTS)

To test it, I must pass in a request and a context (which is a grpc.ServicerContext object), like so:

import grcp

def test_my_method(self):
    request = {"something": "something-else"}
    context = grpc.ServicerContext()

    my_method(request, context)

    # Assert something here

The problem is, I get the following error when I run my tests:

TypeError: Can't instantiate abstract class ServicerContext with abstract methods add_callback, cancel, invocation_metadata, is_active, peer, send_initial_metadata, set_code, set_details, set_trailing_metadata, time_remaining

How can I get a grpc.ServicerContext object? If I can't, how do I test the method?

Aucun commentaire:

Enregistrer un commentaire