diff --git a/tests/integration/web/webfront_test.py b/tests/integration/web/webfront_test.py index 35f1a99526..c975a212aa 100644 --- a/tests/integration/web/webfront_test.py +++ b/tests/integration/web/webfront_test.py @@ -1,4 +1,8 @@ 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 @@ -6,3 +10,47 @@ 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