when not logged in, redirect to sign-in

parts of the initial setup/login stages were throwing 500s if user
not already in process (ie: user directly navigated to url):
* /resend-email-verification
* /text-not-received
* /send-new-code
* verify
This commit is contained in:
Leo Hemsted
2016-06-17 11:36:30 +01:00
parent 7be111d260
commit 539950d772
6 changed files with 44 additions and 16 deletions

View File

@@ -1,6 +1,5 @@
import pytest
from flask import url_for
from bs4 import BeautifulSoup
@@ -128,3 +127,16 @@ def test_check_and_redirect_to_verify_if_user_pending(app_,
response = client.get(url_for('main.check_and_resend_verification_code'))
assert response.status_code == 302
assert response.location == url_for('main.verify', _external=True)
@pytest.mark.parametrize('endpoint', [
'main.resend_email_verification',
'main.check_and_resend_text_code',
'main.check_and_resend_verification_code',
])
def test_redirect_to_sign_in_if_not_logged_in(app_, endpoint):
with app_.test_request_context(), app_.test_client() as client:
response = client.get(url_for(endpoint))
assert response.location == url_for('main.sign_in', _external=True)
assert response.status_code == 302

View File

@@ -147,3 +147,11 @@ def test_verify_email_redirects_to_sign_in_if_user_active(app_,
assert page.h1.text == 'Sign in'
flash_banner = page.find('div', class_='banner-dangerous').string.strip()
assert flash_banner == "That verification link has expired."
def test_verify_redirects_to_sign_in_if_not_logged_in(app_):
with app_.test_request_context(), app_.test_client() as client:
response = client.get(url_for('main.verify'))
assert response.location == url_for('main.sign_in', _external=True)
assert response.status_code == 302