Skip to content

Commit

Permalink
add test to make views.py coverage 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrDlouhy committed Aug 1, 2022
1 parent da33dc0 commit ec129e3
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions admin_tools_stats/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def setUp(self):
model_name="TestKid",
model_app_name="demoproject",
graph_key="kid_graph",
operation_field_name="height",
)
super().setUp()

Expand Down Expand Up @@ -152,6 +153,15 @@ def setUp(self):
graph_key="user_graph",
operation_field_name="is_active,is_staff",
)
self.kid_stats = baker.make(
"DashboardStats",
graph_title="Kid chart",
date_field_name="birthday",
model_name="TestKid",
model_app_name="demoproject",
graph_key="kid_graph",
operation_field_name="height",
)
self.request_factory = RequestFactory()
super().setUp()

Expand Down Expand Up @@ -279,6 +289,63 @@ def test_get_context_tz(self):
},
)

@override_settings(USE_TZ=True, TIME_ZONE="Europe/Prague")
def test_get_context_tz_operation(self):
"""
Test function view rendering multi series with multiple operations
Test correct context in more complicated timezone setting
Set select_box_operation field
"""
baker.make("TestKid", birthday=datetime(2021, 10, 30, tzinfo=timezone.utc), height=150)
baker.make("TestKid", birthday=datetime(2021, 10, 31, tzinfo=timezone.utc), height=160)
baker.make("TestKid", birthday=datetime(2021, 11, 1, tzinfo=timezone.utc), height=170)
baker.make("TestKid", birthday=datetime(2021, 11, 2, tzinfo=timezone.utc), height=180)
baker.make("TestKid", birthday=datetime(2021, 11, 3, tzinfo=timezone.utc), height=190)
baker.make("TestKid", birthday=datetime(2021, 11, 3, tzinfo=timezone.utc), height=210)
url = reverse("chart-data", kwargs={"graph_key": "kid_graph"})
url += (
"?time_since=2021-10-29&time_until=2021-11-05&select_box_interval=days&"
"select_box_chart_type=stackedAreaChart&select_box_operation_field=&debug=True&"
"select_box_operation=Avg"
)
chart_data_view = ChartDataView()
chart_data_view.request = self.request_factory.get(url)
chart_data_view.request.user = self.user
context = chart_data_view.get_context_data(graph_key="kid_graph")
self.assertDictEqual(
context,
{
"chart_container": "chart_container_kid_graph",
"chart_type": "stackedAreaChart",
"extra": {
"tag_script_js": False,
"use_interactive_guideline": True,
"x_axis_format": "%d %b %Y",
"x_is_date": True,
},
"values": {
"extra1": {
"date_format": "%a %d %b %Y",
"tooltip": {"y_end": "", "y_start": ""},
},
"name0": "",
"name1": Interval.days,
"x": [
1635458400000, # 2021-10-28 22:00:00 GMT
1635544800000,
1635631200000,
1635721200000,
1635807600000,
1635894000000,
1635980400000,
1636066800000, # 2021-11-04 23:00:00 GMT
],
"y0": [0, 150, 160, 170, 180, 200, 0, 0],
},
"view": chart_data_view,
},
)


class SuperuserViewsTests(BaseSuperuserAuthenticatedClient):
def setUp(self):
Expand Down

0 comments on commit ec129e3

Please sign in to comment.