2017-12-11 30 views
0

병 응용 프로그램에서 리디렉션을 테스트하려고했습니다. 불행히도 리디렉션 위치를 테스트하는 방법을 찾지 못했습니다. 지금까지 나는 BottleException이 제기되었는지 테스트하여 리다이렉션이 수행되었는지 테스트 할 수있었습니다.Bottle.py에서 리디렉션을 테스트하는 방법은 무엇입니까?

def test_authorize_without_token(mocked_database_utils): 
    with pytest.raises(BottleException) as resp: 
    auth_utils.authorize() 

HTTP 응답 상태 코드 또는/및 리디렉션 위치를 얻을 수있는 방법이 있습니까?

도움 주셔서 감사합니다.

+0

'Webtest'는 원하는 작업을 수행합니다. https://docs.pylonsproject.org/projects/webtest/en/latest/ –

답변

3

WebTest은 완벽한 기능을 갖춘 WSGI 응용 프로그램을 테스트하기위한 쉬운 방법입니다. 다음은 리디렉션을 확인하는 예입니다.

from bottle import Bottle, redirect 
from webtest import TestApp 

# the real webapp 
app = Bottle() 


@app.route('/mypage') 
def mypage(): 
    '''Redirect''' 
    redirect('https://some/other/url') 


def test_redirect(): 
    '''Test that GET /mypage redirects''' 

    # wrap the real app in a TestApp object 
    test_app = TestApp(app) 

    # simulate a call (HTTP GET) 
    resp = test_app.get('/mypage', status=[302]) 

    # validate the response 
    assert resp.headers['Location'] == 'https://some/other/url' 


# run the test 
test_redirect() 
+0

니스, 내 문제를 해결해 주셔서 감사합니다. – Sudet