Skip to content

Commit 1ca080c

Browse files
committed
[tests] Fix API regression test: replace VPN template instead of clearing openwisp#1221
The test must send a non-empty templates list (replacing the VPN template with a generic one) so that the m2m post_add signal fires and triggers manage_vpn_clients to delete the stale VpnClient via per-instance delete. Sending an empty templates list hits only the post_clear path which skips deletion for non-deactivated devices. Co-Authored-By: mn-ram <mn-ram@users.noreply.github.com>
1 parent e6c24f5 commit 1ca080c

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

openwisp_controller/config/tests/test_api.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -520,14 +520,15 @@ def test_device_patch_with_templates_of_different_org(self):
520520
)
521521

522522
def test_device_patch_vpn_template_removal_triggers_post_delete(self):
523-
"""Regression test for #1221: removing a VPN template via PATCH API
524-
must trigger VpnClient.post_delete so peer cache is invalidated
525-
and the certificate is revoked."""
523+
"""Regression test for #1221: replacing a VPN template with a generic
524+
one via PATCH API must trigger VpnClient.post_delete so peer cache is
525+
invalidated and the certificate is revoked."""
526526
org = self._get_org()
527527
vpn = self._create_vpn(organization=org)
528528
t_vpn = self._create_template(
529529
name="vpn-test", type="vpn", vpn=vpn, auto_cert=True, organization=org
530530
)
531+
t_generic = self._create_template(name="generic-test", organization=org)
531532
device = self._create_device(organization=org)
532533
config = self._create_config(device=device)
533534
config.templates.add(t_vpn)
@@ -536,8 +537,8 @@ def test_device_patch_vpn_template_removal_triggers_post_delete(self):
536537
cert_pk = vpnclient.cert.pk
537538

538539
path = reverse("config_api:device_detail", args=[device.pk])
539-
# PATCH with empty templates list to remove the VPN template
540-
data = {"config": {"templates": []}}
540+
# PATCH replacing VPN template with a generic template
541+
data = {"config": {"templates": [str(t_generic.pk)]}}
541542
with patch.object(Vpn, "_invalidate_peer_cache") as mock_invalidate:
542543
response = self.client.patch(path, data, content_type="application/json")
543544
mock_invalidate.assert_called_once()

0 commit comments

Comments
 (0)