From c3bbc427e2cce3c646ae04c42f388b1cc5744627 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Wed, 13 Oct 2021 11:31:27 +0100 Subject: [PATCH] =?UTF-8?q?Check=20that=20user=20isn=E2=80=99t=20signed=20?= =?UTF-8?q?in=20before=20registering?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously this test asserted on `current_user.is_authenticated`. That isn’t possible now because the object imported into tests isn’t the same one the app is using. A different proxy for whether the user is signed in is whether they have a user id in their session, because we set this every time they sign in: https://github.com/alphagov/notifications-admin/blob/ff32e73d9bda80e556a9ee81fb0d867eef35e1e2/app/models/user.py#L162 --- tests/app/main/views/test_register.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/app/main/views/test_register.py b/tests/app/main/views/test_register.py index 97a3bf0cf..f8c974148 100644 --- a/tests/app/main/views/test_register.py +++ b/tests/app/main/views/test_register.py @@ -340,6 +340,8 @@ def test_register_from_email_auth_invite( sample_invite['email_address'] = invite_email_address with client.session_transaction() as session: session['invited_user_id'] = sample_invite['id'] + # Prove that the user isn’t already signed in + assert 'user_id' not in session data = { 'name': 'invited user', @@ -382,6 +384,8 @@ def test_register_from_email_auth_invite( ) with client.session_transaction() as session: + # The user is signed in + assert 'user_id' in session # invited user details are still there so they can get added to the service assert session['invited_user_id'] == sample_invite['id']