Skip to content

Commit 85e3e09

Browse files
committed
Add expect method
1 parent de47983 commit 85e3e09

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pytest_httpserver/httpserver.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,21 @@ def clear_all_handlers(self):
972972
self.oneshot_handlers = RequestHandlerList()
973973
self.handlers = RequestHandlerList()
974974

975+
def expect(self, matcher: RequestMatcher) -> RequestHandler:
976+
"""
977+
Create and register a request handler.
978+
979+
:param matcher: :py:class:`RequestMatcher` used to match requests.
980+
"""
981+
request_handler = RequestHandler(matcher)
982+
if handler_type == HandlerType.PERMANENT:
983+
self.handlers.append(request_handler)
984+
elif handler_type == HandlerType.ONESHOT:
985+
self.oneshot_handlers.append(request_handler)
986+
elif handler_type == HandlerType.ORDERED:
987+
self.ordered_handlers.append(request_handler)
988+
return request_handler
989+
975990
def expect_request(
976991
self,
977992
uri: str | URIPattern | Pattern[str],

0 commit comments

Comments
 (0)