예제 #1
0
def test_repeated_processors():
    r = []
    
    def index(request):
        r.append('controller')
    
    def rq1(request):
        r.append('rq1')
    
    def rs1(response):
        r.append('rs1')
        return response
    
    def on_error(e):
        r.append('error')
    
    urls = [
        Rule('/', index),
        ]
    app = Shake(urls)
    
    app.before_request(rq1)
    app.before_request(rq1)
    app.before_response(rs1)
    app.before_response(rs1)
    app.on_exception(on_error)
    app.before_request(rq1)
    app.before_response(rs1)
    app.before_request(rq1)
    app.on_exception(on_error)
    c = app.test_client()
    
    c.get('/')
    assert r == ['rq1', 'controller', 'rs1']
예제 #2
0
def test_repeated_processors():
    r = []

    def index(request):
        r.append('controller')

    def rq1(request):
        r.append('rq1')

    def rs1(response):
        r.append('rs1')
        return response

    def on_error(e):
        r.append('error')

    urls = [
        Rule('/', index),
    ]
    app = Shake(urls)

    app.before_request(rq1)
    app.before_request(rq1)
    app.before_response(rs1)
    app.before_response(rs1)
    app.on_exception(on_error)
    app.before_request(rq1)
    app.before_response(rs1)
    app.before_request(rq1)
    app.on_exception(on_error)
    c = app.test_client()

    c.get('/')
    assert r == ['rq1', 'controller', 'rs1']
예제 #3
0
def test_processors_order_exception():
    r = []
    
    def index(request):
        r.append('controller')
        assert False
    
    def econtroller(request, error):
        r.append('econtroller')
    
    def rq1(request):
        r.append('rq1')
    
    def rq2(request):
        r.append('rq2')
    
    def rs1(response):
        r.append('rs1')
        return response
    
    def rs2(response):
        r.append('rs2')
        return response
    
    def on_error(e):
        r.append('error')
    
    urls = [
        Rule('/', index),
        ]
    settings = {'PAGE_ERROR': econtroller, 'DEBUG': False}
    app = Shake(urls, settings)
    
    app.before_request(rq1)
    app.before_request(rq2)
    app.before_response(rs1)
    app.before_response(rs2)
    app.on_exception(on_error)
    
    c = app.test_client()
    c.get('/')
    
    assert r == ['rq1', 'rq2', 'controller', 'error', 'econtroller']
예제 #4
0
def test_processors_order_exception():
    r = []

    def index(request):
        r.append('controller')
        assert False

    def econtroller(request, error):
        r.append('econtroller')

    def rq1(request):
        r.append('rq1')

    def rq2(request):
        r.append('rq2')

    def rs1(response):
        r.append('rs1')
        return response

    def rs2(response):
        r.append('rs2')
        return response

    def on_error(e):
        r.append('error')

    urls = [
        Rule('/', index),
    ]
    settings = {'PAGE_ERROR': econtroller, 'DEBUG': False}
    app = Shake(urls, settings)

    app.before_request(rq1)
    app.before_request(rq2)
    app.before_response(rs1)
    app.before_response(rs2)
    app.on_exception(on_error)

    c = app.test_client()
    c.get('/')

    assert r == ['rq1', 'rq2', 'controller', 'error', 'econtroller']