From 09a6257a52ea22d51b8c47450a3c3763e8df0198 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Mon, 24 Jul 2023 16:04:16 -0400 Subject: [PATCH] Add test for moving a child model to a new parent --- netbox/utilities/tests/test_counters.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/netbox/utilities/tests/test_counters.py b/netbox/utilities/tests/test_counters.py index 5c2547b8b..cde2d8a75 100644 --- a/netbox/utilities/tests/test_counters.py +++ b/netbox/utilities/tests/test_counters.py @@ -21,7 +21,7 @@ class CountersTest(TestCase): Interface.objects.create(device=device2, name='Interface 3') Interface.objects.create(device=device2, name='Interface 4') - def test_interface_count_addition(self): + def test_interface_count_creation(self): """ When a tracked object (Interface) is added the tracking counter should be updated. """ @@ -50,3 +50,20 @@ class CountersTest(TestCase): device2.refresh_from_db() self.assertEqual(device1._interface_count, 1) self.assertEqual(device2._interface_count, 1) + + def test_interface_count_move(self): + """ + When a tracked object (Interface) is moved the tracking counter should be updated. + """ + device1, device2 = Device.objects.all() + self.assertEqual(device1._interface_count, 2) + self.assertEqual(device2._interface_count, 2) + + interface1 = Interface.objects.get(name='Interface 1') + interface1.device = device2 + interface1.save() + + device1.refresh_from_db() + device2.refresh_from_db() + self.assertEqual(device1._interface_count, 1) + self.assertEqual(device2._interface_count, 3)