Skip to content

Commit 0ae82c2

Browse files
committed
[tests] Fix deactivation test to exercise correct code path #1221
test_deactivation_fires_post_delete_signals was calling device.config.templates.clear() directly without first setting the config status to deactivating. This meant the per-instance delete path guarded by is_deactivating_or_deactivated() in manage_vpn_clients was never exercised, defeating the purpose of the regression test. Replace templates.clear() with device.deactivate() which sets the status to deactivating before clearing templates, ensuring the post_clear handler takes the per-instance delete path. Also replace the conditional handler.assert_called() with an unconditional handler.assert_called_once() and add an IP release assertion.
1 parent d60ec13 commit 0ae82c2

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

openwisp_controller/config/tests/test_vpn.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -919,15 +919,15 @@ def test_deactivation_fires_post_delete_signals(self):
919919
initial_ip_count = IpAddress.objects.count()
920920

921921
with catch_signal(vpn_peers_changed) as handler:
922-
device.config.templates.clear()
923-
# post_clear with deactivating state deletes vpn clients
924-
# The signal should fire because per-instance delete is used
925-
if device.config.vpnclient_set.count() == 0:
926-
handler.assert_called()
922+
device.deactivate()
923+
handler.assert_called_once()
927924

928925
# Verify cleanup happened
929926
self.assertEqual(device.config.vpnclient_set.count(), 0)
930927

928+
with self.subTest("IP address released"):
929+
self.assertLess(IpAddress.objects.count(), initial_ip_count)
930+
931931

932932
class TestVxlan(BaseTestVpn, TestVxlanWireguardVpnMixin, TestCase):
933933
def test_vxlan_config_creation(self):

0 commit comments

Comments
 (0)