File: test_howto_custom_handler.py

package info (click to toggle)
pytest-httpserver 1.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 908 kB
  • sloc: python: 2,382; makefile: 77; sh: 21
file content (13 lines) | stat: -rw-r--r-- 342 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
from random import randint

from werkzeug import Request
from werkzeug import Response

from pytest_httpserver import HTTPServer


def test_expected_request_handler(httpserver: HTTPServer):
    def handler(request: Request):
        return Response(str(randint(1, 10)))

    httpserver.expect_request("/foobar").respond_with_handler(handler)