mardi 9 janvier 2018

Context for testing services in GRPC

Currently we able to test positive cases following way:

class AuthServer(auth_grpc.AuthServicer):
    def __init__(self, *args, **kwargs):
        print("Initializing auth server..")
        super(AuthServer, self).__init__(*args, **kwargs)

    def register(self, request, context):
        return auth_messages.registerResponse(uuid="Test")

With pytest fixtures looking following way:

@pytest.fixture(scope="session")
def server():
    return AuthServer()


@pytest.fixture(scope="session")
def context():
    return DummyGRPCTestContext()

In test case environment accessed following way:

def test_user_registration(server, context, user):
    request = auth_messages.registerRequest(**user)
    result = server.register(request, context)
    print("RESULT %s " % result)

However, if we want test negative case and changing grpc servicer method to following:

def register(self, request, context):
    context.set_code(grpc.StatusCode.ALREADY_EXISTS)
    context.set_details("User already exists")
    return auth_messages.registerResponse()

We're failing in errors, related to dummy context.

Where we can get grpc context, that can be easily plugged into test environment?

Context like this one looks complex and not ready for plug and test.

Aucun commentaire:

Enregistrer un commentaire