Skip to content

Commit

Permalink
add tests for empty chart views
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrDlouhy committed Aug 1, 2022
1 parent 9399037 commit e836f03
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
30 changes: 29 additions & 1 deletion admin_tools_stats/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.urls import reverse
from model_bakery import baker

from admin_tools_stats.models import DashboardStatsCriteria
from admin_tools_stats.models import DashboardStats, DashboardStatsCriteria

from .utils import BaseSuperuserAuthenticatedClient

Expand All @@ -21,6 +21,34 @@ def setUp(self):
)
super().setUp()

@override_settings(
INSTALLED_APPS=[
"django_nvd3",
"admin_tools_stats",
"admin_tools.menu",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.sites",
"django.contrib.messages",
"django.contrib.staticfiles",
"djangobower",
"demoproject",
]
)
def test_admin_index_empty(self):
"""Vanila admin index page without any chart, should note how to create it"""
DashboardStats.objects.all().delete()
url = reverse("admin:index")
response = self.client.get(url)
self.assertContains(
response,
"<p>No charts available, please "
'<a href="/admin/admin_tools_stats/dashboardstats/">configure them</a></p>',
html=True,
)

@override_settings(
INSTALLED_APPS=[
"django_nvd3",
Expand Down
21 changes: 21 additions & 0 deletions admin_tools_stats/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from django.urls import reverse
from model_bakery import baker

from admin_tools_stats.models import DashboardStats
from admin_tools_stats.views import AnalyticsView, ChartDataView, Interval

from .utils import (
Expand Down Expand Up @@ -48,11 +49,31 @@ def setUp(self):
)
super().setUp()

def test_analytics_view_empty(self):
"""Test of analytics page when no charts are present"""
DashboardStats.objects.all().delete()
response = self.client.get(reverse("chart-analytics"))
self.assertEqual(response.status_code, 200)
self.assertContains(
response,
"<p>No charts available, please "
'<a href="/admin/admin_tools_stats/dashboardstats/">configure them</a></p>',
html=True,
)

def test_analytics_view(self):
"""Test function to check dashboardstats admin pages"""
response = self.client.get(reverse("chart-analytics"))
self.assertEqual(response.status_code, 200)
self.assertContains(response, "<button>Kid chart</button>", html=True)
self.assertNotContains(response, "loadAnalyticsChart('")

def test_analytics_view_show(self):
"""Test function to check dashboardstats admin pages that should show certain chart"""
response = self.client.get(reverse("chart-analytics") + "?show=kid_graph")
self.assertEqual(response.status_code, 200)
self.assertContains(response, "<button>Kid chart</button>", html=True)
self.assertContains(response, "loadAnalyticsChart('kid_graph')")

def test_analytics_chart_view(self):
"""Test function to check dashboardstats admin pages"""
Expand Down

0 comments on commit e836f03

Please sign in to comment.