From fdc76b589745d685264ee2cd280ae74f3e76cc53 Mon Sep 17 00:00:00 2001 From: Simon Oliver Tveit Date: Thu, 22 Feb 2024 15:29:11 +0100 Subject: [PATCH] Put admin credentials in its own fixture --- tests/integration/conftest.py | 16 ++++++++++++---- tests/integration/web/webfront_test.py | 8 ++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index aadc768365..5f0b7807d4 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -218,16 +218,14 @@ def localhost_using_legacy_db(): @pytest.fixture(scope='session') -def client(): +def client(admin_username, admin_password): """Provides a Django test Client object already logged in to the web UI as an admin""" from django.urls import reverse client_ = Client() url = reverse('webfront-login') - username = os.environ.get('ADMINUSERNAME', 'admin') - password = os.environ.get('ADMINPASSWORD', 'admin') - client_.post(url, {'username': username, 'password': password}) + client_.post(url, {'username': admin_username, 'password': admin_password}) return client_ @@ -373,3 +371,13 @@ def admin_account(db): from nav.models.profiles import Account yield Account.objects.get(id=Account.ADMIN_ACCOUNT) + + +@pytest.fixture(scope='session') +def admin_username(): + return os.environ.get('ADMINUSERNAME', 'admin') + + +@pytest.fixture(scope='session') +def admin_password(): + return os.environ.get('ADMINPASSWORD', 'admin') diff --git a/tests/integration/web/webfront_test.py b/tests/integration/web/webfront_test.py index a7749ec878..3dc64a35d0 100644 --- a/tests/integration/web/webfront_test.py +++ b/tests/integration/web/webfront_test.py @@ -68,14 +68,14 @@ def test_set_default_dashboard_with_multiple_previous_defaults_should_succeed( ) -def test_session_id_is_changed_after_logging_in(db, client, admin_account): +def test_session_id_is_changed_after_logging_in( + db, client, admin_username, admin_password +): login_url = reverse('webfront-login') # make sure we have a session ID we can use for comparison assert client.session.session_key session_id_pre_login = client.session.session_key - client.post( - login_url, {'username': admin_account.login, 'password': admin_account.password} - ) + client.post(login_url, {'username': admin_username, 'password': admin_password}) session_id_post_login = client.session.session_key assert session_id_post_login != session_id_pre_login