From 6406a0826d357800c688bf2e07dd6baa5ffcc6d0 Mon Sep 17 00:00:00 2001 From: Gagan Deep Date: Fri, 9 Jun 2023 20:15:46 +0530 Subject: [PATCH] [test] Fixed coverage --- .../device/tests/test_wifi_mesh.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/openwisp_network_topology/integrations/device/tests/test_wifi_mesh.py b/openwisp_network_topology/integrations/device/tests/test_wifi_mesh.py index 4cfd2662..5b0c289f 100644 --- a/openwisp_network_topology/integrations/device/tests/test_wifi_mesh.py +++ b/openwisp_network_topology/integrations/device/tests/test_wifi_mesh.py @@ -4,11 +4,13 @@ import swapper from django.core.cache import cache +from django.core.exceptions import ImproperlyConfigured from django.test import TransactionTestCase, tag from django.urls import reverse from django.utils.timezone import now, timedelta from freezegun import freeze_time +from .. import settings as app_settings from ..tasks import create_mesh_topology from . import SIMPLE_MESH_DATA, SINGLE_NODE_MESH_DATA from .utils import TopologyTestMixin @@ -57,6 +59,28 @@ def _populate_mesh(self, data): create_mesh_topology.delay(organization_ids=(org.id,)) return devices, org + @patch.object(app_settings, 'WIFI_MESH_INTEGRATION', False) + def test_wifi_mesh_integration_disabled(self): + with self.subTest('Test calling "create_mesh_topology" task'): + with patch.object(WifiMesh, 'create_topology') as mocked: + _, org = self._populate_mesh(SIMPLE_MESH_DATA) + self.assertEqual(Topology.objects.count(), 0) + mocked.assert_not_called() + + # Ensure the following sub-test does not fail if the + # previous one fails. + Topology.objects.all().delete() + + with self.subTest('Test calling WifiMesh.create_topology'): + with self.assertRaises(ImproperlyConfigured) as error: + WifiMesh.create_topology( + organization_ids=[org.id], discard_older_data_time=360 + ) + self.assertEqual( + str(error.exception), + '"OPENIWSP_NETWORK_TOPOLOGY_WIFI_MESH_INTEGRATION" is set to "False".', + ) + def test_simple_mesh(self): devices, org = self._populate_mesh(SIMPLE_MESH_DATA) self.assertEqual(Topology.objects.filter(organization=org).count(), 1)