Skip to content

Commit f4e3b99

Browse files
committed
[req-changes] Improved tests and comments
1 parent 9af0d9f commit f4e3b99

File tree

7 files changed

+7
-17
lines changed

7 files changed

+7
-17
lines changed

openwisp_controller/config/base/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -718,9 +718,9 @@ def _send_config_modified_signal(self, action=None):
718718
"""
719719
Emits ``config_modified`` signal.
720720
721-
A short-lived cache key (``_CONFIG_MODIFIED_TIMEOUT``)
722-
prevents emitting duplicate signals inside the same logical window;
723-
if that key exists the method returns early without emitting.
721+
A short-lived cache key prevents emitting duplicate signals inside the
722+
same change window; if that key exists the method returns early without
723+
emitting the signal again.
724724
725725
Side effects
726726
------------

openwisp_controller/config/tests/test_admin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2602,9 +2602,10 @@ def test_restoring_template_sends_config_modified(self):
26022602
self.assertEqual(config.status, "modified")
26032603
self.assertNotEqual(config.checksum, config_checksum)
26042604

2605+
@patch.object(Config, "_CONFIG_MODIFIED_TIMEOUT", 3)
26052606
def test_config_modified_signal(self):
26062607
"""
2607-
Verifies multiple config_modified signal is not send for
2608+
Verifies multiple config_modified signal are not sent for
26082609
a single change
26092610
"""
26102611
required = self._create_template(

openwisp_controller/config/tests/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,7 @@ def test_device_patch_with_templates_of_same_org(self):
16691669
self.assertEqual(d1.config.templates.count(), 2)
16701670
self.assertEqual(r.data["config"]["templates"], [t1.id, t2.id])
16711671

1672+
@patch.object(Config, "_CONFIG_MODIFIED_TIMEOUT", 3)
16721673
def test_config_modified_signal(self):
16731674
"""
16741675
Verifies that config_modified signal is sent only once.
@@ -1694,7 +1695,6 @@ def test_config_modified_signal(self):
16941695
self.assertEqual(config.templates.count(), 2)
16951696
device_detail = reverse("config_api:device_detail", args=[config.device_id])
16961697

1697-
config._delete_config_modified_timeout_cache()
16981698
with self.subTest(
16991699
"Updating the unused context variable does not send config_modified signal"
17001700
):

openwisp_controller/config/tests/test_config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,6 @@ def test_config_modified_sent(self):
818818
)
819819
self.assertEqual(c.status, "modified")
820820

821-
c._delete_config_modified_timeout_cache()
822821
with catch_signal(config_modified) as handler:
823822
c.config = {"general": {"description": "changed again"}}
824823
c.full_clean()

openwisp_controller/config/tests/test_template.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,6 @@ def test_config_modified_signal(self):
606606
# refresh instance to reset _just_created attribute
607607
conf = Config.objects.get(pk=conf.pk)
608608

609-
conf._delete_config_modified_timeout_cache()
610609
with self.subTest("signal sent if config status is already modified"):
611610
with catch_signal(config_modified) as handler:
612611
conf.templates.add(template1, template2)
@@ -624,7 +623,6 @@ def test_config_modified_signal(self):
624623
# reset status
625624
conf.set_status_applied()
626625

627-
conf._delete_config_modified_timeout_cache()
628626
with self.subTest("signal sent after assigning template to config"):
629627
with catch_signal(config_modified) as handler:
630628
conf.templates.remove(template2)
@@ -643,7 +641,6 @@ def test_config_modified_signal(self):
643641
# reset status
644642
conf.set_status_applied()
645643

646-
conf._delete_config_modified_timeout_cache()
647644
with self.subTest("post_clear m2m ignored"):
648645
with catch_signal(config_modified) as handler:
649646
conf.templates.clear()
@@ -658,7 +655,6 @@ def test_config_modified_signal(self):
658655
conf.save()
659656
conf.refresh_from_db()
660657

661-
conf._delete_config_modified_timeout_cache()
662658
with self.subTest("post_add and previous_status=applied"):
663659
with catch_signal(config_modified) as handler:
664660
conf.templates.add(template1, template2)
@@ -678,7 +674,6 @@ def test_config_modified_signal(self):
678674
# reset status
679675
conf.set_status_applied()
680676

681-
conf._delete_config_modified_timeout_cache()
682677
with self.subTest("test remove/add"):
683678
with catch_signal(config_modified) as handler:
684679
conf.templates.remove(template1, template2)
@@ -691,7 +686,6 @@ def test_config_modified_signal(self):
691686
# reset status
692687
conf.set_status_applied()
693688

694-
conf._delete_config_modified_timeout_cache()
695689
with self.subTest("signal sent after changing a template"):
696690
with catch_signal(config_modified) as handler:
697691
template1.config["interfaces"][0]["name"] = "eth1"
@@ -709,7 +703,6 @@ def test_config_modified_signal(self):
709703
conf.refresh_from_db()
710704
self.assertEqual(conf.status, "modified")
711705

712-
conf._delete_config_modified_timeout_cache()
713706
with self.subTest("signal sent also if config is already in modified status"):
714707
# status has already changed to modified
715708
# signal should be triggered anyway

openwisp_controller/config/tests/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def _create_device_config(self, device_opts=None, config_opts=None):
5555

5656
class CreateConfigMixin(CreateDeviceMixin):
5757
TEST_KEY = "w1gwJxKaHcamUw62TQIPgYchwLKn3AA0"
58+
Config._CONFIG_MODIFIED_TIMEOUT = 0
5859

5960
def _create_config(self, **kwargs):
6061
options = dict(backend="netjsonconfig.OpenWrt", config={"general": {}})

openwisp_controller/connection/tests/test_models.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,6 @@ def _assert_applying_conf_test_command(mocked_exec):
959959

960960
conf = self._prepare_conf_object()
961961

962-
conf._delete_config_modified_timeout_cache()
963962
with self.subTest("Unable to get openwisp-config version"):
964963
with mock.patch(_exec_command_path) as mocked_exec_command:
965964
mocked_exec_command.return_value = self._exec_command_return_value(
@@ -971,7 +970,6 @@ def _assert_applying_conf_test_command(mocked_exec):
971970
conf.refresh_from_db()
972971
self.assertEqual(conf.status, "modified")
973972

974-
conf._delete_config_modified_timeout_cache()
975973
with self.subTest("openwisp_config >= 0.6.0a"):
976974
conf.config = '{"dns_servers": []}'
977975
conf.full_clean()
@@ -987,7 +985,6 @@ def _assert_applying_conf_test_command(mocked_exec):
987985
conf.refresh_from_db()
988986
self.assertEqual(conf.status, "modified")
989987

990-
conf._delete_config_modified_timeout_cache()
991988
with self.subTest("openwisp_config < 0.6.0a: exit_code 0"):
992989
conf.config = '{"interfaces": [{"name": "eth00","type": "ethernet"}]}'
993990
conf.full_clean()
@@ -1002,7 +999,6 @@ def _assert_applying_conf_test_command(mocked_exec):
1002999
conf.refresh_from_db()
10031000
self.assertEqual(conf.status, "modified")
10041001

1005-
conf._delete_config_modified_timeout_cache()
10061002
with self.subTest("openwisp_config < 0.6.0a: exit_code 1"):
10071003
conf.config = '{"radios": []}'
10081004
conf.full_clean()

0 commit comments

Comments
 (0)