Skip to content

Hanaasagi/papurika

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Papurika

Build Status black License

Installing

# Require pip>=19.0
pip install git+https://github.com/Hanaasagi/papurika.git

Basics

Use the quick way to mock.

class Greeter(helloworld_pb2_grpc.GreeterServicer):
    def SayHello(self, request, context):
        return helloworld_pb2.HelloReply(
            message="Hello, %s!" % request.name
        )


@papurika.activite
def test_shortcut():
    papurika.add("localhost:50051", Greeter)
    with grpc.insecure_channel("localhost:50051") as channel:
        stub = helloworld_pb2_grpc.GreeterStub(channel)
        response = stub.SayHello(helloworld_pb2.HelloRequest(name="you"))
        assert response.message == "Hello, you!"

Mock single service.

with ServiceMock("localhost:50051", Greeter):
    with grpc.insecure_channel("localhost:50051") as channel:
        stub = helloworld_pb2_grpc.GreeterStub(channel)
        response = stub.SayHello(helloworld_pb2.HelloRequest(name="you"))
        assert response.message == "Hello, you!"

Mock multi service.

with ServiceMockGroup() as services:
    services.add("localhost:50051", Greeter)
    with grpc.insecure_channel("localhost:50051") as channel:
        stub = helloworld_pb2_grpc.GreeterStub(channel)
        response = stub.SayHello(helloworld_pb2.HelloRequest(name="you"))
        assert response.message == "Hello, you!"