forked from Uninett/nav
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for setting default dashboard
- Loading branch information
1 parent
2d0ef43
commit ef57161
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |