@@ -2669,83 +2669,83 @@ def test_config_modified_signal(self):
26692669 self .assertEqual (config .context ["ssid" ], "Updated" )
26702670 mocked_signal .assert_not_called ()
26712671
2672- # config._delete_config_modified_timeout_cache()
2673- # with self.subTest(
2674- # "Changing used context variable sends config_modified signal"
2675- # ):
2676- # with patch(
2677- # "openwisp_controller.config.signals.config_modified.send"
2678- # ) as mocked_signal:
2679- # params.update(
2680- # {
2681- # "config-0-context": json.dumps(
2682- # {"ssid": "Updated", "ifname": "eth2"}
2683- # )
2684- # }
2685- # )
2686- # response = self.client.post(path, data=params, follow=True)
2687- # self.assertEqual(response.status_code, 200)
2688-
2689- # config.refresh_from_db()
2690- # self.assertEqual(
2691- # config.context["ssid"],
2692- # "Updated",
2693- # )
2694- # self.assertEqual(config.status, "modified")
2695- # mocked_signal.assert_called_once()
2696-
2697- # config._delete_config_modified_timeout_cache()
2698- # with self.subTest("Changing device configuration sends config_modified signal"):
2699- # with patch(
2700- # "openwisp_controller.config.signals.config_modified.send"
2701- # ) as mocked_signal:
2702- # params.update(
2703- # {
2704- # "config-0-config": json.dumps(
2705- # {"interfaces": [{"name": "eth5", "type": "ethernet"}]}
2706- # )
2707- # }
2708- # )
2709- # response = self.client.post(path, data=params, follow=True)
2710- # self.assertEqual(response.status_code, 200)
2711- # config.refresh_from_db()
2712- # self.assertEqual(
2713- # config.config["interfaces"][0]["name"],
2714- # "eth5",
2715- # )
2716- # self.assertEqual(config.status, "modified")
2717- # mocked_signal.assert_called_once()
2718-
2719- # config._delete_config_modified_timeout_cache()
2720- # with self.subTest("Changing applied template sends config_modified signal"):
2721- # with patch(
2722- # "openwisp_controller.config.signals.config_modified.send"
2723- # ) as mocked_signal:
2724- # response = self.client.post(
2725- # reverse(
2726- # f"admin:{self.app_label}_template_change", args=[template2.pk]
2727- # ),
2728- # data={
2729- # "name": template2.name,
2730- # "organization": "",
2731- # "type": template2.type,
2732- # "backend": template2.backend,
2733- # "config": json.dumps(template2.config),
2734- # "default_values": json.dumps(
2735- # {
2736- # "ifname": "eth3",
2737- # }
2738- # ),
2739- # "required": False,
2740- # "default": True,
2741- # "_continue": True,
2742- # },
2743- # follow=True,
2744- # )
2745- # self.assertEqual(response.status_code, 200)
2746- # template2.refresh_from_db()
2747- # self.assertEqual(template2.default_values["ifname"], "eth3")
2748- # mocked_signal.assert_called_once()
2672+ config ._delete_config_modified_timeout_cache ()
2673+ with self .subTest (
2674+ "Changing used context variable sends config_modified signal"
2675+ ):
2676+ with patch (
2677+ "openwisp_controller.config.signals.config_modified.send"
2678+ ) as mocked_signal :
2679+ params .update (
2680+ {
2681+ "config-0-context" : json .dumps (
2682+ {"ssid" : "Updated" , "ifname" : "eth2" }
2683+ )
2684+ }
2685+ )
2686+ response = self .client .post (path , data = params , follow = True )
2687+ self .assertEqual (response .status_code , 200 )
2688+
2689+ config .refresh_from_db ()
2690+ self .assertEqual (
2691+ config .context ["ssid" ],
2692+ "Updated" ,
2693+ )
2694+ self .assertEqual (config .status , "modified" )
2695+ mocked_signal .assert_called_once ()
2696+
2697+ config ._delete_config_modified_timeout_cache ()
2698+ with self .subTest ("Changing device configuration sends config_modified signal" ):
2699+ with patch (
2700+ "openwisp_controller.config.signals.config_modified.send"
2701+ ) as mocked_signal :
2702+ params .update (
2703+ {
2704+ "config-0-config" : json .dumps (
2705+ {"interfaces" : [{"name" : "eth5" , "type" : "ethernet" }]}
2706+ )
2707+ }
2708+ )
2709+ response = self .client .post (path , data = params , follow = True )
2710+ self .assertEqual (response .status_code , 200 )
2711+ config .refresh_from_db ()
2712+ self .assertEqual (
2713+ config .config ["interfaces" ][0 ]["name" ],
2714+ "eth5" ,
2715+ )
2716+ self .assertEqual (config .status , "modified" )
2717+ mocked_signal .assert_called_once ()
2718+
2719+ config ._delete_config_modified_timeout_cache ()
2720+ with self .subTest ("Changing applied template sends config_modified signal" ):
2721+ with patch (
2722+ "openwisp_controller.config.signals.config_modified.send"
2723+ ) as mocked_signal :
2724+ response = self .client .post (
2725+ reverse (
2726+ f"admin:{ self .app_label } _template_change" , args = [template2 .pk ]
2727+ ),
2728+ data = {
2729+ "name" : template2 .name ,
2730+ "organization" : "" ,
2731+ "type" : template2 .type ,
2732+ "backend" : template2 .backend ,
2733+ "config" : json .dumps (template2 .config ),
2734+ "default_values" : json .dumps (
2735+ {
2736+ "ifname" : "eth3" ,
2737+ }
2738+ ),
2739+ "required" : False ,
2740+ "default" : True ,
2741+ "_continue" : True ,
2742+ },
2743+ follow = True ,
2744+ )
2745+ self .assertEqual (response .status_code , 200 )
2746+ template2 .refresh_from_db ()
2747+ self .assertEqual (template2 .default_values ["ifname" ], "eth3" )
2748+ mocked_signal .assert_called_once ()
27492749
27502750
27512751class TestDeviceGroupAdmin (
0 commit comments