Skip to content

Commit

Permalink
[req-changes] Added test for checking optimized query
Browse files Browse the repository at this point in the history
  • Loading branch information
pandafy committed Sep 20, 2023
1 parent 15b69a6 commit 760f23d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions openwisp_monitoring/device/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 760f23d

Please sign in to comment.