summaryrefslogtreecommitdiff
path: root/tests/test_errordocument.py
blob: 57a01abbb89c84b878f9c3854aeda086b6262bc4 (plain)
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
from paste.errordocument import forward
from paste.fixture import *
from paste.recursive import RecursiveMiddleware

def simple_app(environ, start_response):
    start_response("200 OK", [('Content-type', 'text/plain')])
    return ['requested page returned']

def not_found_app(environ, start_response):
    start_response("404 Not found", [('Content-type', 'text/plain')])
    return ['requested page returned']
    
def test_ok():
    app = TestApp(simple_app)
    res = app.get('')
    assert res.header('content-type') == 'text/plain'
    assert res.full_status == '200 OK'
    assert 'requested page returned' in res
    
def error_docs_app(environ, start_response):
    if environ['PATH_INFO'] == '/not_found':
        start_response("404 Not found", [('Content-type', 'text/plain')])
        return ['Not found']
    elif environ['PATH_INFO'] == '/error':
        start_response("200 OK", [('Content-type', 'text/plain')])
        return ['Page not found']
    else:
        return simple_app(environ, start_response)
    
def test_error_docs_app():
    app = TestApp(error_docs_app)
    res = app.get('')
    assert res.header('content-type') == 'text/plain'
    assert res.full_status == '200 OK'
    assert 'requested page returned' in res
    res = app.get('/error')
    assert res.header('content-type') == 'text/plain'
    assert res.full_status == '200 OK'
    assert 'Page not found' in res
    res = app.get('/not_found', status=404)
    assert res.header('content-type') == 'text/plain'
    assert res.full_status == '404 Not found'
    assert 'Not found' in res

def test_forward():    
    app = forward(error_docs_app, codes={404:'/error'})
    app = TestApp(RecursiveMiddleware(app))
    res = app.get('')
    assert res.header('content-type') == 'text/plain'
    assert res.full_status == '200 OK'
    assert 'requested page returned' in res
    res = app.get('/error')
    assert res.header('content-type') == 'text/plain'
    assert res.full_status == '200 OK'
    assert 'Page not found' in res
    res = app.get('/not_found', status=404)
    assert res.header('content-type') == 'text/plain'
    assert res.full_status == '404 Not found'
    # Note changed response
    assert 'Page not found' in res