@@ -671,9 +671,12 @@ def test_device_import_with_group_apply_templates(self):
671671 self .assertIn ("confirm_form" , response .context )
672672 confirm_form = response .context ["confirm_form" ]
673673 data = confirm_form .initial
674- response = self .client .post (
675- reverse (f"admin:{ self .app_label } _device_process_import" ), data , follow = True
676- )
674+ with self .captureOnCommitCallbacks (execute = True ):
675+ response = self .client .post (
676+ reverse (f"admin:{ self .app_label } _device_process_import" ),
677+ data ,
678+ follow = True ,
679+ )
677680 self .assertEqual (response .status_code , 200 )
678681 device = Device .objects .first ()
679682 self .assertIsNotNone (device )
@@ -746,9 +749,10 @@ def test_add_device_with_group_templates(self):
746749 with catch_signal (post_save ) as mock_post_save , catch_signal (
747750 device_group_changed
748751 ) as device_group_changed_mock :
749- self .client .post (
750- reverse (f"admin:{ self .app_label } _device_add" ), data , follow = True
751- )
752+ with self .captureOnCommitCallbacks (execute = True ):
753+ self .client .post (
754+ reverse (f"admin:{ self .app_label } _device_add" ), data , follow = True
755+ )
752756 device = Device .objects .first ()
753757 mock_post_save .assert_any_call (
754758 signal = post_save ,
@@ -767,7 +771,8 @@ def test_unassigning_group_removes_old_templates(self):
767771 template = self ._create_template (name = "template" )
768772 dg = self ._create_device_group (name = "test-group" , organization = org )
769773 dg .templates .add (template )
770- device = self ._create_device (organization = org , group = dg )
774+ with self .captureOnCommitCallbacks (execute = True ):
775+ device = self ._create_device (organization = org , group = dg )
771776 self .assertIn (template , device .config .templates .all ())
772777 path = reverse (f"admin:{ self .app_label } _device_change" , args = [device .pk ])
773778 params = self ._get_device_params (org = org )
@@ -780,7 +785,8 @@ def test_unassigning_group_removes_old_templates(self):
780785 "group" : "" ,
781786 }
782787 )
783- response = self .client .post (path , params , follow = True )
788+ with self .captureOnCommitCallbacks (execute = True ):
789+ response = self .client .post (path , params , follow = True )
784790 self .assertNotContains (response , "errors" , status_code = 200 )
785791 device .refresh_from_db ()
786792 self .assertIsNone (device .group )
@@ -791,7 +797,8 @@ def test_group_templates_are_not_forced(self):
791797 t = self ._create_template (name = "t" )
792798 dg = self ._create_device_group (name = "test-group" , organization = o )
793799 dg .templates .add (t )
794- d = self ._create_device (organization = o , group = dg )
800+ with self .captureOnCommitCallbacks (execute = True ):
801+ d = self ._create_device (organization = o , group = dg )
795802 self .assertIn (t , d .config .templates .all ())
796803 path = reverse (f"admin:{ self .app_label } _device_change" , args = [d .pk ])
797804 params = self ._get_device_params (org = o )
0 commit comments