-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2680 from johannaengland/bugfix/fix-multiple-defa…
…ult-dashboards Prevent error when setting new default for multiple existing default dashboards
- Loading branch information
Showing
7 changed files
with
88 additions
and
27 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
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
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
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
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
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
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,68 @@ | ||
from mock import Mock | ||
|
||
from django.urls import reverse | ||
from nav.compatibility import smart_str | ||
from nav.models.profiles import 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, admin_account): | ||
"""Tests that a default dashboard can be set""" | ||
dashboard = AccountDashboard.objects.create( | ||
name="new_default", | ||
is_default=False, | ||
account=admin_account, | ||
) | ||
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(account=admin_account, is_default=True).count() | ||
== 1 | ||
) | ||
|
||
|
||
def test_set_default_dashboard_with_multiple_previous_defaults_should_succeed( | ||
db, client, admin_account | ||
): | ||
""" | ||
Tests that a default dashboard can be set if multiple default dashboards | ||
exist currently | ||
""" | ||
# By default there already exists one default dashboard for the admin user | ||
# which is why we only have to create a second default one | ||
default_dashboard = AccountDashboard.objects.create( | ||
name="default_dashboard", | ||
is_default=True, | ||
account=admin_account, | ||
) | ||
dashboard = AccountDashboard.objects.create( | ||
name="new_default", | ||
is_default=False, | ||
account=admin_account, | ||
) | ||
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(account=admin_account, is_default=True).count() | ||
== 1 | ||
) |