diff options
Diffstat (limited to 'tests/mocks.py')
-rw-r--r-- | tests/mocks.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/mocks.py b/tests/mocks.py new file mode 100644 index 0000000..dc6e117 --- /dev/null +++ b/tests/mocks.py @@ -0,0 +1,40 @@ +from typing import List + +from grpclib.client import Channel + + +class MockChannel(Channel): + # noinspection PyMissingConstructor + def __init__(self, responses=None) -> None: + self.responses = responses or [] + self.requests = [] + self._loop = None + + def request(self, route, cardinality, request, response_type, **kwargs): + self.requests.append( + { + "route": route, + "cardinality": cardinality, + "request": request, + "response_type": response_type, + } + ) + return MockStream(self.responses) + + +class MockStream: + def __init__(self, responses: List) -> None: + super().__init__() + self.responses = responses + + async def recv_message(self): + return self.responses.pop(0) + + async def send_message(self, *args, **kwargs): + pass + + async def __aexit__(self, exc_type, exc_val, exc_tb): + return True + + async def __aenter__(self): + return self |