mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-23 07:46:23 -04:00
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.
This commit is contained in:
@@ -1184,6 +1184,33 @@ def active_user_with_permissions(fake_uuid):
|
||||
return user_data
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def active_user_with_session(fake_uuid):
|
||||
user_data = {'id': fake_uuid,
|
||||
'name': 'Test User',
|
||||
'password': 'somepassword',
|
||||
'password_changed_at': str(datetime.utcnow()),
|
||||
'email_address': 'test@user.gov.uk',
|
||||
'mobile_number': '07700 900762',
|
||||
'state': 'active',
|
||||
'failed_login_count': 0,
|
||||
'permissions': {SERVICE_ONE_ID: ['send_texts',
|
||||
'send_emails',
|
||||
'send_letters',
|
||||
'manage_users',
|
||||
'manage_templates',
|
||||
'manage_settings',
|
||||
'manage_api_keys',
|
||||
'view_activity']},
|
||||
'platform_admin': False,
|
||||
'auth_type': 'sms_auth',
|
||||
'organisations': [ORGANISATION_ID],
|
||||
'services': [SERVICE_ONE_ID],
|
||||
'current_session_id': fake_uuid,
|
||||
}
|
||||
return user_data
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def active_user_with_permission_to_two_services(fake_uuid):
|
||||
|
||||
@@ -2619,6 +2646,18 @@ def logged_in_client(
|
||||
yield client
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def logged_in_client_with_session(
|
||||
client,
|
||||
active_user_with_session,
|
||||
mocker,
|
||||
service_one,
|
||||
mock_login
|
||||
):
|
||||
client.login(active_user_with_session, mocker, service_one)
|
||||
yield client
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def platform_admin_client(
|
||||
client,
|
||||
|
||||
Reference in New Issue
Block a user