Skip to content

Commit

Permalink
Put admin credentials in its own fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
stveit committed Feb 23, 2024
1 parent 062e746 commit fdc76b5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
16 changes: 12 additions & 4 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_


Expand Down Expand Up @@ -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')
8 changes: 4 additions & 4 deletions tests/integration/web/webfront_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit fdc76b5

Please sign in to comment.