Skip to content

Commit

Permalink
[test] Fixed coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
pandafy committed Jun 9, 2023
1 parent 2f9a072 commit 6406a08
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6406a08

Please sign in to comment.