I am testing redirects in my flask application. The application has multiple blueprints. The concerned route is in page
blueprint while the final route is in user
blueprint.
The route in question looks as -
@page.route('/')
def home():
if current_user.is_authenticated:
return redirect('user.welcome')
return render_template('page/home.html')
The test looks as below.
@pytest.mark.usefixtures('empty_db')
def test_home_page_redirects_to_user_welcome_view_for_logged_in_user(client, user):
# create the user and also logs him in'
response = client.post(url_for('user.signup'), data=user)
response = client.get(url_for('page.home'))
assert response.status_code == 302
assert urlparse(response.location).path == url_for('user.welcome')
The error I'm facing is that the response.location
has the blueprint name in it. That is
response.location = 'http://0.0.0.0:9000/user.welcome'
which is causing the test to fail. The redirection is to the correct page, but the path returned by response.location
is what i'm trying to fix. Is there a fix or any workaround? Thanks for taking the time to answer.
Aucun commentaire:
Enregistrer un commentaire