Skip to content

Commit

Permalink
Add tests for setting default dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
johannaengland committed Sep 12, 2023
1 parent 2d0ef43 commit ef57161
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/integration/web/webfront_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,56 @@
from mock import Mock

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


def test_tools_should_be_readable():
admin = Mock()
tools = tool_list(admin)
assert len(tools) > 0


def test_set_default_dashboard_should_succeed(db, client):
"""Tests that a default dashboard can be set"""
dashboard = AccountDashboard.objects.create(
name="new_default",
is_default=False,
account=Account.objects.get(login="admin"),
)
url = reverse("set-default-dashboard", args=(dashboard.pk,))
response = client.post(url, follow=True)

dashboard.refresh_from_db()

assert response.status_code == 200
assert f"Default dashboard set to «{dashboard.name}»" in smart_str(response.content)
assert dashboard.is_default
assert AccountDashboard.objects.filter(is_default=True).count() == 1


def test_set_default_dashboard_with_multiple_previous_defaults_should_succeed(
db, client
):
default_dashboard = AccountDashboard.objects.create(
name="default_dashboard",
is_default=True,
account=Account.objects.get(login="admin"),
)
dashboard = AccountDashboard.objects.create(
name="new_default",
is_default=False,
account=Account.objects.get(login="admin"),
)
url = reverse("set-default-dashboard", args=(dashboard.pk,))
response = client.post(url, follow=True)

default_dashboard.refresh_from_db()
dashboard.refresh_from_db()

assert response.status_code == 200
assert f"Default dashboard set to «{dashboard.name}»" in smart_str(response.content)
assert dashboard.is_default
assert not default_dashboard.is_default
assert AccountDashboard.objects.filter(is_default=True).count() == 1

0 comments on commit ef57161

Please sign in to comment.