Skip to content

Commit

Permalink
refactor: add type hints for request matcher for better usability
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-sipgate committed Apr 30, 2024
1 parent 28a7507 commit 3914fb9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions http_request_recorder/http_request_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from itertools import tee
from logging import getLogger
from typing import Iterable, Union
from collections.abc import Callable

from aiohttp import web
from aiohttp.web_request import BaseRequest
Expand Down Expand Up @@ -38,7 +39,7 @@ def __init__(self, response):
self.was_triggered = Event()
self.response = response

def __init__(self, matcher, responses: ResponsesType, name: str, timeout: int):
def __init__(self, matcher: Callable[[RecordedRequest], bool], responses: ResponsesType, name: str, timeout: int):
self.name: str = name
self._timeout: int = timeout

Expand All @@ -55,7 +56,7 @@ def __init__(self, matcher, responses: ResponsesType, name: str, timeout: int):

self._recorded = []
self._next_for_response, self._next_to_return = tee(self.responses)
self._matcher = matcher
self._matcher: Callable[[RecordedRequest], bool] = matcher

def __repr__(self):
return f"<{self.__class__.__name__} '{self.name}'>"
Expand Down Expand Up @@ -156,7 +157,7 @@ async def handle_request(self, request: BaseRequest):

return web.Response(status=200, body=response)

def expect(self, matcher, responses: ResponsesType = "", name: str = None, timeout: int = 3) -> ExpectedInteraction:
def expect(self, matcher: Callable[[RecordedRequest], bool], responses: ResponsesType = "", name: str = None, timeout: int = 3) -> ExpectedInteraction:
expectation = ExpectedInteraction(matcher, responses, name, timeout)
self._expectations.append(expectation)
return expectation
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

setup(
name='http_request_recorder',
version='0.2.1',
version='0.2.2',
description='A package to record an respond to http requests, primarily for use in black box testing.',
long_description=readme,
author='',
Expand Down

0 comments on commit 3914fb9

Please sign in to comment.