-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtest_handler.py
More file actions
40 lines (28 loc) · 909 Bytes
/
test_handler.py
File metadata and controls
40 lines (28 loc) · 909 Bytes
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
import pytest
from webob import Request
from webob.exc import HTTPNotFound
from web.core import Application
from web.core.testing import MockRequest
from web.core.ext.handler import StatusHandlers
def mock_endpoint(context, status, state=None):
context.response.status_int = int(status)
mock_endpoint.state = state
return state
@pytest.fixture
def app():
return Application(mock_endpoint, [StatusHandlers({
HTTPNotFound: '/404/notfound',
503: '/503/maintenance',
})])
def test_notfound(app):
with MockRequest('/404') as request:
response = request.send(app)
assert response.text == 'notfound'
assert response.status_int == 404
assert mock_endpoint.state == 'notfound'
def test_maintenance(app):
with MockRequest('/404') as request:
response = request.send(app)
assert response.text == 'notfound'
assert response.status_int == 404
assert mock_endpoint.state == 'notfound'