From ba23d94b5811738d3141ac9881fb87932da702f2 Mon Sep 17 00:00:00 2001 From: Arthur Date: Wed, 26 Mar 2025 08:36:05 -0700 Subject: [PATCH] 18981 fix tests --- .../migrations/0203_device_role_nested.py | 21 +++++++++++++------ netbox/dcim/models/devices.py | 13 ++---------- netbox/dcim/tests/test_api.py | 4 +++- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/netbox/dcim/migrations/0203_device_role_nested.py b/netbox/dcim/migrations/0203_device_role_nested.py index c935f789f..dccaab0f9 100644 --- a/netbox/dcim/migrations/0203_device_role_nested.py +++ b/netbox/dcim/migrations/0203_device_role_nested.py @@ -12,12 +12,6 @@ class Migration(migrations.Migration): ] operations = [ - migrations.AlterModelManagers( - name='devicerole', - managers=[ - ('_tree_manager', django.db.models.manager.Manager()), - ], - ), migrations.AddField( model_name='devicerole', name='level', @@ -53,4 +47,19 @@ class Migration(migrations.Migration): to='dcim.devicerole', ), ), + migrations.AddField( + model_name='devicerole', + name='comments', + field=models.TextField(blank=True), + ), + migrations.AlterField( + model_name='devicerole', + name='name', + field=models.CharField(max_length=100), + ), + migrations.AlterField( + model_name='devicerole', + name='slug', + field=models.SlugField(max_length=100), + ), ] diff --git a/netbox/dcim/models/devices.py b/netbox/dcim/models/devices.py index 601eb770d..fb391f3c3 100644 --- a/netbox/dcim/models/devices.py +++ b/netbox/dcim/models/devices.py @@ -21,10 +21,9 @@ from dcim.constants import * from dcim.fields import MACAddressField from extras.models import ConfigContextModel, CustomField from extras.querysets import ConfigContextModelQuerySet -from mptt.models import MPTTModel, TreeForeignKey from netbox.choices import ColorChoices from netbox.config import ConfigItem -from netbox.models import OrganizationalModel, PrimaryModel +from netbox.models import NestedGroupModel, OrganizationalModel, PrimaryModel from netbox.models.mixins import WeightMixin from netbox.models.features import ContactsMixin, ImageAttachmentsMixin from utilities.fields import ColorField, CounterCacheField @@ -469,20 +468,12 @@ class ModuleType(ImageAttachmentsMixin, PrimaryModel, WeightMixin): # Devices # -class DeviceRole(OrganizationalModel, MPTTModel): +class DeviceRole(NestedGroupModel): """ Devices are organized by functional role; for example, "Core Switch" or "File Server". Each DeviceRole is assigned a color to be used when displaying rack elevations. The vm_role field determines whether the role is applicable to virtual machines as well. """ - parent = TreeForeignKey( - to='self', - on_delete=models.CASCADE, - related_name='children', - blank=True, - null=True, - db_index=True - ) color = ColorField( verbose_name=_('color'), default=ColorChoices.COLOR_GREY diff --git a/netbox/dcim/tests/test_api.py b/netbox/dcim/tests/test_api.py index d27d3128c..c2a7660c6 100644 --- a/netbox/dcim/tests/test_api.py +++ b/netbox/dcim/tests/test_api.py @@ -1149,7 +1149,9 @@ class InventoryItemTemplateTest(APIViewTestCases.APIViewTestCase): class DeviceRoleTest(APIViewTestCases.APIViewTestCase): model = DeviceRole - brief_fields = ['description', 'device_count', 'display', 'id', 'name', 'slug', 'url', 'virtualmachine_count'] + brief_fields = [ + '_depth', 'description', 'device_count', 'display', 'id', 'name', 'slug', 'url', 'virtualmachine_count' + ] create_data = [ { 'name': 'Device Role 4',