-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathtest_handler_errors.py
More file actions
92 lines (58 loc) · 2.5 KB
/
test_handler_errors.py
File metadata and controls
92 lines (58 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import pytest
import requests
import werkzeug
from pytest_httpserver import HTTPServer
def test_check_assertions_raises_handler_assertions(httpserver: HTTPServer):
def handler(_):
assert 1 == 2
httpserver.expect_request("/foobar").respond_with_handler(handler)
requests.get(httpserver.url_for("/foobar"))
with pytest.raises(AssertionError):
httpserver.check_assertions()
httpserver.check_handler_errors()
def test_check_handler_errors_raises_handler_error(httpserver: HTTPServer):
def handler(_) -> werkzeug.Response:
raise ValueError("should be propagated")
httpserver.expect_request("/foobar").respond_with_handler(handler)
requests.get(httpserver.url_for("/foobar"))
httpserver.check_assertions()
with pytest.raises(ValueError):
httpserver.check_handler_errors()
def test_check_handler_errors_correct_order(httpserver: HTTPServer):
def handler1(_) -> werkzeug.Response:
raise ValueError("should be propagated")
def handler2(_) -> werkzeug.Response:
raise OSError("should be propagated")
httpserver.expect_request("/foobar1").respond_with_handler(handler1)
httpserver.expect_request("/foobar2").respond_with_handler(handler2)
requests.get(httpserver.url_for("/foobar1"))
requests.get(httpserver.url_for("/foobar2"))
httpserver.check_assertions()
with pytest.raises(ValueError):
httpserver.check_handler_errors()
with pytest.raises(OSError):
httpserver.check_handler_errors()
httpserver.check_handler_errors()
def test_missing_matcher_raises_exception(httpserver):
requests.get(httpserver.url_for("/foobar"))
# missing handlers should not raise handler exception here
httpserver.check_handler_errors()
with pytest.raises(AssertionError):
httpserver.check_assertions()
def test_check_raises_errors_in_order(httpserver):
def handler1(_):
assert 1 == 2
def handler2(_):
pass # does nothing
def handler3(_):
raise ValueError
httpserver.expect_request("/foobar1").respond_with_handler(handler1)
httpserver.expect_request("/foobar2").respond_with_handler(handler2)
httpserver.expect_request("/foobar3").respond_with_handler(handler3)
requests.get(httpserver.url_for("/foobar1"))
requests.get(httpserver.url_for("/foobar2"))
requests.get(httpserver.url_for("/foobar3"))
with pytest.raises(AssertionError):
httpserver.check()
with pytest.raises(ValueError):
httpserver.check()