Files
notifications-admin/tests/app/main/views/test_sign_out.py
Rebecca Law 8a19d9496a Check if user is authenticated before signing out, this will prevent a 500 if the user is an AnonymousUser.
I ended up creating a new test user and logged_in_client, which isn't really great. But I tried adding a current_session_id to the active user in the test, but that broke all other tests.
I tried setting current_session_id in all the users being tested but that didn't work either. I'd like to come back to fixing the tests and reducing the number of conftest methods in another PR. For now this fixes the bug.
2020-02-04 12:16:58 +00:00

64 lines
1.6 KiB
Python

import flask
from flask import url_for
from tests.conftest import SERVICE_ONE_ID
def test_render_sign_out_redirects_to_sign_in(
logged_in_client_with_session
):
assert flask.session
response = logged_in_client_with_session.get(
url_for('main.sign_out'))
assert response.status_code == 302
assert response.location == url_for(
'main.index', _external=True)
assert not flask.session
def test_sign_out_user(
client_request,
mock_get_service,
api_user_active,
mock_get_user,
mock_get_user_by_email,
mock_login,
mock_get_service_templates,
mock_get_jobs,
mock_has_permissions,
mock_get_template_statistics,
mock_get_service_statistics,
mock_get_usage,
mock_get_free_sms_fragment_limit,
mock_get_inbound_sms_summary,
):
with client_request.session_transaction() as session:
assert session.get('user_id') is not None
# Check we are logged in
client_request.get(
'main.service_dashboard',
service_id=SERVICE_ONE_ID,
)
client_request.get(
'main.sign_out',
_expected_status=302,
_expected_redirect=url_for(
'main.index',
_external=True,
)
)
with client_request.session_transaction() as session:
assert session.get('user_id') is None
def test_sign_out_of_two_sessions(
logged_in_client_with_session
):
logged_in_client_with_session.get(
url_for('main.sign_out'))
assert not flask.session
response = logged_in_client_with_session.get(
url_for('main.sign_out'))
assert response.status_code == 302