From 760f23db88cba64899ca6a920a4efcec1e6bcb94 Mon Sep 17 00:00:00 2001 From: Gagan Deep Date: Tue, 19 Sep 2023 22:54:18 +0530 Subject: [PATCH] [req-changes] Added test for checking optimized query --- openwisp_monitoring/device/tests/test_admin.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/openwisp_monitoring/device/tests/test_admin.py b/openwisp_monitoring/device/tests/test_admin.py index c156ccc96..8d1e09f43 100644 --- a/openwisp_monitoring/device/tests/test_admin.py +++ b/openwisp_monitoring/device/tests/test_admin.py @@ -5,6 +5,7 @@ from django.contrib.auth.models import Permission from django.contrib.contenttypes.forms import generic_inlineformset_factory from django.core.cache import cache +from django.db import connection from django.test import TestCase from django.urls import reverse from django.utils.timezone import datetime, now, timedelta @@ -118,6 +119,21 @@ def test_dashboard_map_on_index(self): self.assertContains(response, "geoJsonUrl: \'http://testserver/api") self.assertContains(response, "locationDeviceUrl: \'http://testserver/api") + def test_wifisession_dashboard_chart_query(self): + url = reverse('admin:index') + with self.assertNumQueries(10): + response = self.client.get(url) + self.assertEqual(response.status_code, 200) + for query in connection.queries: + if query['sql'] == ( + 'SELECT COUNT("device_monitoring_wifisession"."id") ' + 'AS "active__count" FROM "device_monitoring_wifisession" ' + 'WHERE "device_monitoring_wifisession"."stop_time" IS NULL' + ): + break + else: + self.fail('WiFiSession dashboard query not found') + def test_status_data(self): d = self._create_device(organization=self._create_org()) data = self._data()