Skip to content

Commit

Permalink
Factor out admin account as general fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
johannaengland committed Sep 15, 2023
1 parent fea1cf9 commit 3aad8c3
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 24 deletions.
5 changes: 2 additions & 3 deletions tests/integration/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def test_api_urls_should_resolve(urlname, arg):


@pytest.fixture()
def serializer_models(localhost):
def serializer_models(localhost, admin_account):
"""Fixture for testing API serializers
- unrecognized_neighbor
Expand Down Expand Up @@ -433,7 +433,6 @@ def serializer_models(localhost):
alert_type_id=boxdown_id,
end_time=INFINITY,
).save()
admin = profiles.Account.objects.get(login='admin')
auditlog.LogEntry.add_log_entry(admin, verb='verb', template='asd')
auditlog.LogEntry.add_log_entry(admin_account, verb='verb', template='asd')
manage.Usage(id='ans', description='Ansatte').save()
manage.Usage(id='student', description='Studenter').save()
7 changes: 7 additions & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,10 @@ def _lookfor(string, filename):
"""Very simple grep-like function"""
data = io.open(filename, 'r', encoding='utf-8').read()
return string in data


@pytest.fixture
def admin_account(db):
from nav.models.profiles import Account

yield Account.objects.get(id=Account.ADMIN_ACCOUNT)
13 changes: 4 additions & 9 deletions tests/integration/models/alertsubscription_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,9 @@ def test_delete_alert_subscription(db, alert, alertsub):


@pytest.fixture
def account():
return Account.objects.get(pk=Account.ADMIN_ACCOUNT)


@pytest.fixture
def alert_address(account):
def alert_address(admin_account):
addr = AlertAddress(
account=account,
account=admin_account,
type=AlertSender.objects.get(name=AlertSender.SMS),
)
addr.save()
Expand All @@ -39,8 +34,8 @@ def alert_address(account):


@pytest.fixture
def alert_profile(account):
profile = AlertProfile(account=account)
def alert_profile(admin_account):
profile = AlertProfile(account=admin_account)
profile.save()
yield profile
if profile.pk:
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/seeddb_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ def test_usage_edit_url_should_allow_slashes():
assert reverse('seeddb-usage-edit', args=('TEST/SLASH',))


def test_editing_deleted_netboxes_should_raise_404():
def test_editing_deleted_netboxes_should_raise_404(admin_account):
netboxid = 666 # Assuming no such netbox exists in test data set!
factory = RequestFactory()
url = reverse('seeddb-netbox-edit', args=(netboxid,))
request = factory.get(url)
request.account = Account.objects.get(pk=Account.ADMIN_ACCOUNT)
request.account = admin_account
request.session = MagicMock()

with pytest.raises(Http404):
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/web/info_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ def test_failures_should_be_mentioned_in_search_page(client, failing_searchprovi
assert failing_searchprovider in response.content.decode('utf-8')


def test_room_csv_download_should_not_produce_bytestring_representations():
def test_room_csv_download_should_not_produce_bytestring_representations(admin_account):
factory = RequestFactory()
request = factory.post(
reverse("room-csv"), data={"roomid": "myroom", "rows": "one;two;three\n"}
)
request.account = Account.objects.get(pk=Account.ADMIN_ACCOUNT)
request.account = admin_account
request.session = MagicMock()

response = create_csv(request) # type: django.http.response.HttpResponse
Expand Down
9 changes: 1 addition & 8 deletions tests/integration/web/webfront_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

from django.urls import reverse
from nav.compatibility import smart_str
from nav.models.profiles import Account, AccountDashboard
from nav.models.profiles import AccountDashboard
from nav.web.webfront.utils import tool_list

import pytest


def test_tools_should_be_readable():
admin = Mock()
Expand Down Expand Up @@ -60,8 +58,3 @@ def test_set_default_dashboard_with_multiple_previous_defaults_should_succeed(
AccountDashboard.objects.filter(account=admin_account, is_default=True).count()
== 1
)


@pytest.fixture
def admin_account(db):
yield Account.objects.get(id=Account.ADMIN_ACCOUNT)

0 comments on commit 3aad8c3

Please sign in to comment.