Skip to content

Commit cf466c6

Browse files
committed
tests: add test for hooks to check the correct order of calling
1 parent 50141e0 commit cf466c6

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

tests/test_hooks.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@ def _sleep(self):
2626
self.evidence = self._seconds
2727

2828

29-
def my_hook(_request: Request, response: Response) -> Response:
30-
response.set_data(response.get_data() + b"-SUFFIX")
31-
return response
29+
def suffix_hook_factory(suffix: bytes):
30+
def hook(_request: Request, response: Response) -> Response:
31+
response.set_data(response.get_data() + suffix)
32+
return response
3233

34+
return hook
3335

34-
def test_hook(httpserver: HTTPServer):
3536

37+
def test_hook(httpserver: HTTPServer):
38+
my_hook = suffix_hook_factory(b"-SUFFIX")
3639
httpserver.expect_request("/foo").with_hook(my_hook).respond_with_data("OK")
3740

3841
assert requests.get(httpserver.url_for("/foo")).text == "OK-SUFFIX"
@@ -86,3 +89,12 @@ def test_multiple_hooks(httpserver: HTTPServer):
8689
httpserver.expect_request("/foo").with_hook(delay).with_hook(Garbage(128)).respond_with_data("OK")
8790
assert len(requests.get(httpserver.url_for("/foo")).content) == 130
8891
assert delay.evidence == 10
92+
93+
94+
def test_multiple_hooks_correct_order(httpserver: HTTPServer):
95+
hook1 = suffix_hook_factory(b"-S1")
96+
hook2 = suffix_hook_factory(b"-S2")
97+
98+
httpserver.expect_request("/foo").with_hook(hook1).with_hook(hook2).respond_with_data("OK")
99+
100+
assert requests.get(httpserver.url_for("/foo")).text == "OK-S1-S2"

0 commit comments

Comments
 (0)