content: import json
  from decimal import Decimal
  from zoneinfo import ZoneInfo
  
  import yaml
  from django.test import override_settings, tag
  from django.urls import reverse
  from netaddr import EUI
  
  from core.models import ObjectType
  from dcim.choices import *
  from dcim.constants import *
  from dcim.models import *
  from ipam.models import ASN, RIR, VLAN, VRF
  from netbox.choices import CSVDelimiterChoices, ImportFormatChoices, WeightUnitChoices
  from tenancy.models import Tenant
  from users.models import ObjectPermission, User
  from utilities.testing import ViewTestCases, create_tags, create_test_device, post_data
  from wireless.models import WirelessLAN
  
  
  class RegionTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
      model = Region
  
      @classmethod
      def setUpTestData(cls):
  
          # Create three Regions
          regions = (
              Region(name='Region 1', slug='region-1', comments=''),
              Region(
                  name='Region 2', slug='region-2', comments="It's going to take a lot to drag me away from you"
              ),
              Region(name='Region 3', slug='region-3'),
          )
          for region in regions:
              region.save()
  
          tags = create_tags('Alpha', 'Bravo', 'Charlie')
  
          cls.form_data = {
              'name': 'Region X',
              'slug': 'region-x',
              'parent': regions[2].pk,
              'description': 'A new region',
              'tags': [t.pk for t in tags],
              'comments': 'This comment is really exciting!',
          }
  
          cls.csv_data = (
              "name,slug,description,comments",
              "Region 4,region-4,Fourth region,",
              "Region 5,region-5,Fifth region,hi guys",
              "Region 6,region-6,Sixth region,bye guys",
          )
  
          cls.csv_update_data = (
              "id,name,description",
              f"{regions[0].pk},Region 7,Fourth region7",
              f"{regions[1].pk},Region 8,Fifth region8",
              f"{regions[2].pk},Region 0,Sixth region9",
          )
  
          cls.bulk_edit_data = {
              'description': 'New description',
              'comments': 'This comment is super exciting!!!',
          }
  
  
  class SiteGroupTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
      model = SiteGroup
  
      @classmethod
      def setUpTestData(cls):
  
          # Create three SiteGroups
          sitegroups = (
              SiteGroup(name='Site Group 1', slug='site-group-1', comments='Still here'),
              SiteGroup(name='Site Group 2', slug='site-group-2'),
              SiteGroup(name='Site Group 3', slug='site-group-3'),
          )
          for sitegroup in sitegroups:
              sitegroup.save()
  
          tags = create_tags('Alpha', 'Bravo', 'Charlie')
  
          cls.form_data = {
              'name': 'Site Group X',
              'slug': 'site-group-x',
              'parent': sitegroups[2].pk,
              'description': 'A new site group',
              'tags': [t.pk for t in tags],
              'comments': 'still here',
          }
  
          cls.csv_data = (
              "name,slug,description,comments",
              "Site Group 4,site-group-4,Fourth site group,",
              "Site Group 5,site-group-5,Fifth site group,still hear",
              "Site Group 6,site-group-6,Sixth site group,"
          )
  
          cls.csv_update_data = (
              "id,name,description,comments",
              f"{sitegroups[0].pk},Site Group 7,Fourth site group7,",
              f"{sitegroups[1].pk},Site Group 8,Fifth site group8,when will it end",
              f"{sitegroups[2].pk},Site Group 0,Sixth site group9,",
          )
  
          cls.bulk_edit_data = {
              'description': 'New description',
              'comments': 'the end',
          }
  
  
  class SiteTestCase(ViewTestCases.PrimaryObjectViewTestCase):
      model = Site
  
      @classmethod
      def setUpTestData(cls):
  
          regions = (
              Region(name='Region 1', slug='region-1'),
              Region(name='Region 2', slug='region-2'),
          )
          for region in regions:
              region.save()
  
          groups = (
              SiteGroup(name='Site Group 1', slug='site-group-1'),
              SiteGroup(name='Site Group 2', slug='site-group-2'),
          )
          for group in groups:
              group.save()
  
          rir = RIR.objects.create(name='RFC 6996', is_private=True)
  
          asns = [
              ASN(asn=65000 + i, rir=rir) for i in range(8)
          ]
          ASN.objects.bulk_create(asns)
  
          sites = Site.objects.bulk_create([
              Site(name='Site 1', slug='site-1', region=regions[0], group=groups[1]),
              Site(name='Site 2', slug='site-2', region=regions[0], group=groups[1]),
              Site(name='Site 3', slug='site-3', region=regions[0], group=groups[1]),
          ])
          sites[0].asns.set([asns[0], asns[1]])
          sites[1].asns.set([asns[2], asns[3]])
          sites[2].asns.set([asns[4], asns[5]])
  
          tags = create_tags('Alpha', 'Bravo', 'Charlie')
  
          cls.form_data = {
              'name': 'Site X',
              'slug': 'site-x',
              'status': SiteStatusChoices.STATUS_PLANNED,
              'region': regions[1].pk,
              'group': groups[1].pk,
              'tenant': None,
              'facility': 'Facility X',
              'asns': [asns[6].pk, asns[7].pk],
              'time_zone': ZoneInfo('UTC'),
              'description': 'Site description',
              'physical_address': '742 Evergreen Terrace, Springfield, USA',
              'shipping_address': '742 Evergreen Terrace, Springfield, USA',
              'latitude': Decimal('35.780000'),
              'longitude': Decimal('-78.642000'),
              'comments': 'Test site',
              'tags': [t.pk for t in tags],
          }
  
          cls.csv_data = (
              "name,slug,status",
              "Site 4,site-4,planned",
              "Site 5,site-5,active",
              "Site 6,site-6,staging",
          )
  
          cls.csv_update_data = (
              "id,name,status",
              f"{sites[0].pk},Site 7,staging",
              f"{sites[1].pk},Site 8,planned",
              f"{sites[2].pk},Site 9,active",
          )
  
          cls.bulk_edit_data = {
              'status': SiteStatusChoices.STATUS_PLANNED,
              'region': regions[1].pk,
              'group': groups[1].pk,
              'tenant': None,
              'time_zone': ZoneInfo('US/Eastern'),
              'description': 'New description',
          }
  
  
  class LocationTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
      model = Location
  
      @classmethod
      def setUpTestData(cls):
  
          site = Site.objects.create(name='Site 1', slug='site-1')
          tenant = Tenant.objects.create(name='Tenant 1', slug='tenant-1')
  
          locations = (
              Location(
                  name='Location 1',
                  slug='location-1',
                  site=site,
                  status=LocationStatusChoices.STATUS_ACTIVE,
                  tenant=tenant,
                  comments='',
              ),
              Location(
                  name='Location 2',
                  slug='location-2',
                  site=site,
                  status=LocationStatusChoices.STATUS_ACTIVE,
                  tenant=tenant,
                  comments='First comment!',
              ),
              Location(
                  name='Location 3',
                  slug='location-3',
                  site=site,
                  status=LocationStatusChoices.STATUS_ACTIVE,
                  tenant=tenant,
                  comments='_This_ is a **bold comment**',
              ),
          )
          for location in locations:
              location.save()
  
          tags = create_tags('Alpha', 'Bravo', 'Charlie')
  
          cls.form_data = {
              'name': 'Location X',
              'slug': 'location-x',
              'site': site.pk,
              'status': LocationStatusChoices.STATUS_PLANNED,
              'facility': 'Facility X',
              'tenant': tenant.pk,
              'description': 'A new location',
              'tags': [t.pk for t in tags],
              'comments': 'This comment is really boring',
          }
  
          cls.csv_data = (
              "site,tenant,name,slug,status,description,comments",
              "Site 1,Tenant 1,Location 4,location-4,planned,Fourth location,",
              "Site 1,Tenant 1,Location 5,location-5,planned,Fifth location,",
              "Site 1,Tenant 1,Location 6,location-6,planned,Sixth location,hi!",
          )
  
          cls.csv_update_data = (
              "id,name,description,comments",
              f"{locations[0].pk},Location 7,Fourth location7,Useful comment",
              f"{locations[1].pk},Location 8,Fifth location8,unuseful comment",
              f"{locations[2].pk},Location 0,Sixth location9,",
          )
  
          cls.bulk_edit_data = {
              'description': 'New description',
              'comments': 'This comment is also really boring',
          }
  
  
  class RackRoleTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
      model = RackRole
  
      @classmethod
      def setUpTestData(cls):
  
          rack_roles = (
              RackRole(name='Rack Role 1', slug='rack-role-1'),
              RackRole(name='Rack Role 2', slug='rack-role-2'),
              RackRole(name='Rack Role 3', slug='rack-role-3'),
          )
          RackRole.objects.bulk_create(rack_roles)
  
          tags = create_tags('Alpha', 'Bravo', 'Charlie')
  
          cls.form_data = {
              'name': 'Rack Role X',
              'slug': 'rack-role-x',
              'color': 'c0c0c0',
              'description': 'New role',
              'tags': [t.pk for t in tags],
          }
  
          cls.csv_data = (
              "name,slug,color",
              "Rack Role 4,rack-role-4,ff0000",
              "Rack Role 5,rack-role-5,00ff00",
              "Rack Role 6,rack-role-6,0000ff",
          )
  
          cls.csv_update_data = (
              "id,name,description",
              f"{rack_roles[0].pk},Rack Role 7,New description7",
              f"{rack_roles[1].pk},Rack Role 8,New description8",
              f"{rack_roles[2].pk},Rack Role 9,New description9",
          )
  
          cls.bulk_edit_data = {
              'color': '00ff00',
              'description': 'New description',
          }
  
  
  class RackReservationTestCase(ViewTestCases.PrimaryObjectViewTestCase):
      model = RackReservation
  
      @classmethod
      def setUpTestData(cls):
  
          user2 = User.objects.create_user(username='testuser2')
          user3 = User.objects.create_user(username='testuser3')
  
          site = Site.objects.create(name='Site 1', slug='site-1')
  
          location = Location(name='Location 1', slug='location-1', site=site)
          location.save()
  
          rack = Rack(name='Rack 1', site=site, location=location)
          rack.save()
  
          rack_reservations = (
              RackReservation(rack=rack, user=user2, units=[1, 2, 3], description='Reservation 1'),
              RackReservation(rack=rack, user=user2, units=[4, 5, 6], description='Reservation 2'),
              RackReservation(rack=rack, user=user2, units=[7, 8, 9], description='Reservation 3'),
          )
          RackReservation.objects.bulk_create(rack_reservations)
  
          tags = create_tags('Alpha', 'Bravo', 'Charlie')
  
          cls.form_data = {
              'rack': rack.pk,
              'units': "10,11,12",
              'status': RackReservationStatusChoices.STATUS_PENDING,
              'user': user3.pk,
              'tenant': None,
              'description': 'Rack reservation',
              'tags': [t.pk for t in tags],
          }
  
          cls.csv_data = (
              'site,location,rack,units,status,description',
              'Site 1,Location 1,Rack 1,"10,11,12",active,Reservation 1',
              'Site 1,Location 1,Rack 1,"13,14,15",pending,Reservation 2',
              'Site 1,Location 1,Rack 1,"16,17,18",stale,Reservation 3',
          )
  
          cls.csv_update_data = (
              'id,description',
              f'{rack_reservations[0].pk},New description1',
              f'{rack_reservations[1].pk},New description2',
              f'{rack_reservations[2].pk},New description3',
          )
  
          cls.bulk_edit_data = {
              'status': RackReservationStatusChoices.STATUS_STALE,
              'user': user3.pk,
              'tenant': None,
              'description': 'New description',
          }
  
  
  class RackTypeTestCase(ViewTestCases.PrimaryObjectViewTestCase):
      model = RackType
  
      @classmethod
      def setUpTestData(cls):
          manufacturers = (
              Manufacturer(name='Manufacturer 1', slug='manufacturer-1'),
              Manufacturer(name='Manufacturer 2', slug='manufacturer-2'),
          )
          Manufacturer.objects.bulk_create(manufacturers)
  
          rack_types = (
              RackType(
                  manufacturer=manufacturers[0],
                  model='RackType 1',
                  slug='rack-type-1',
                  form_factor=RackFormFactorChoices.TYPE_CABINET,
              ),
              RackType(
                  manufacturer=manufacturers[0],
                  model='RackType 2',
                  slug='rack-type-2',
                  form_factor=RackFormFactorChoices.TYPE_CABINET,
              ),
              RackType(
                  manufacturer=manufacturers[0],
                  model='RackType 3',
                  slug='rack-type-3',
                  form_factor=RackFormFactorChoices.TYPE_CABINET,
              ),
          )
          RackType.objects.bulk_create(rack_types)
  
          tags = create_tags('Alpha', 'Bravo', 'Charlie')
  
          cls.form_data = {
              'manufacturer': manufacturers[1].pk,
              'model': 'RackType X',
              'slug': 'rack-type-x',
              'type': RackFormFactorChoices.TYPE_CABINET,
              'width': RackWidthChoices.WIDTH_19IN,
              'u_height': 48,
              'desc_units': False,
              'outer_width': 500,
              'outer_depth': 500,
              'outer_unit': RackDimensionUnitChoices.UNIT_MILLIMETER,
              'starting_unit': 1,
              'weight': 100,
              'max_weight': 2000,
              'weight_unit': WeightUnitChoices.UNIT_POUND,
              'form_factor': RackFormFactorChoices.TYPE_CABINET,
              'comments': 'Some comments',
              'tags': [t.pk for t in tags],
          }
  
          cls.csv_data = (
              "manufacturer,model,slug,width,u_height,weight,max_weight,weight_unit",
              "Manufacturer 1,RackType 4,rack-type-4,19,42,100,2000,kg",
              "Manufacturer 1,RackType 5,rack-type-5,19,42,100,2000,kg",
              "Manufacturer 1,RackType 6,rack-type-6,19,42,100,2000,kg",
          )
  
          cls.csv_update_data = (
              "id,model",
              f"{rack_types[0].pk},RackType 7",
              f"{rack_types[1].pk},RackType 8",
              f"{rack_types[2].pk},RackType 9",
          )
  
          cls.bulk_edit_data = {
              'manufacturer': manufacturers[1].pk,
              'type': RackFormFactorChoices.TYPE_4POST,
              'width': RackWidthChoices.WIDTH_23IN,
              'u_height': 49,
              'desc_units': True,
              'outer_width': 30,
              'outer_depth': 30,
              'outer_unit': RackDimensionUnitChoices.UNIT_INCH,
              'weight': 200,
              'max_weight': 4000,
              'weight_unit': WeightUnitChoices.UNIT_POUND,
              'comments': 'New comments',
          }
  
  
  class RackTestCase(ViewTestCases.PrimaryObjectViewTestCase):
      model = Rack
  
      @classmethod
      def setUpTestData(cls):
  
          sites = (
              Site(name='Site 1', slug='site-1'),
              Site(name='Site 2', slug='site-2'),
          )
          Site.objects.bulk_create(sites)
  
          locations = (
              Location(name='Location 1', slug='location-1', site=sites[0]),
              Location(name='Location 2', slug='location-2', site=sites[1])
          )
          for location in locations:
              location.save()
  
          rackroles = (
              RackRole(name='Rack Role 1', slug='rack-role-1'),
              RackRole(name='Rack Role 2', slug='rack-role-2'),
          )
          RackRole.objects.bulk_create(rackroles)
  
          racks = (
              Rack(name='Rack 1', site=sites[0]),
              Rack(name='Rack 2', site=sites[0]),
              Rack(name='Rack 3', site=sites[0]),
          )
          Rack.objects.bulk_create(racks)
  
          tags = create_tags('Alpha', 'Bravo', 'Charlie')
  
          cls.form_data = {
              'name': 'Rack X',
              'facility_id': 'Facility X',
              'site': sites[1].pk,
              'location': locations[1].pk,
              'tenant': None,
              'status': RackStatusChoices.STATUS_PLANNED,
              'role': rackroles[1].pk,
              'serial': '123456',
              'asset_tag': 'ABCDEF',
              'form_factor': RackFormFactorChoices.TYPE_CABINET,
              'width': RackWidthChoices.WIDTH_19IN,
              'u_height': 48,
              'desc_units': False,
              'outer_width': 500,
              'outer_depth': 500,
              'outer_unit': RackDimensionUnitChoices.UNIT_MILLIMETER,
              'starting_unit': 1,
              'weight': 100,
              'max_weight': 2000,
              'weight_unit': WeightUnitChoices.UNIT_POUND,
              'comments': 'Some comments',
              'tags': [t.pk for t in tags],
          }
  
          cls.csv_data = (
              "site,location,name,status,width,u_height,weight,max_weight,weight_unit",
              "Site 1,,Rack 4,active,19,42,100,2000,kg",
              "Site 1,Location 1,Rack 5,active,19,42,100,2000,kg",
              "Site 2,Location 2,Rack 6,active,19,42,100,2000,kg",
          )
  
          cls.csv_update_data = (
              "id,name,status",
              f"{racks[0].pk},Rack 7,{RackStatusChoices.STATUS_DEPRECATED}",
              f"{racks[1].pk},Rack 8,{RackStatusChoices.STATUS_DEPRECATED}",
              f"{racks[2].pk},Rack 9,{RackStatusChoices.STATUS_DEPRECATED}",
          )
  
          cls.bulk_edit_data = {
              'site': sites[1].pk,
              'location': locations[1].pk,
              'tenant': None,
              'status': RackStatusChoices.STATUS_DEPRECATED,
              'role': rackroles[1].pk,
              'serial': '654321',
              'form_factor': RackFormFactorChoices.TYPE_4POST,
              'width': RackWidthChoices.WIDTH_23IN,
              'u_height': 49,
              'desc_units': True,
              'outer_width': 30,
              'outer_depth': 30,
              'outer_unit': RackDimensionUnitChoices.UNIT_INCH,
              'weight': 200,
              'max_weight': 4000,
              'weight_unit': WeightUnitChoices.UNIT_POUND,
              'comments': 'New comments',
          }
  
      @override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
      def test_list_rack_elevations(self):
          """
          Test viewing the list of rack elevations.
          """
          response = self.client.get(reverse('dcim:rack_elevation_list'))
          self.assertHttpStatus(response, 200)
  
  
  class ManufacturerTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
      model = Manufacturer
  
      @classmethod
      def setUpTestData(cls):
  
          manufacturers = (
              Manufacturer(name='Manufacturer 1', slug='manufacturer-1'),
              Manufacturer(name='Manufacturer 2', slug='manufacturer-2'),
              Manufacturer(name='Manufacturer 3', slug='manufacturer-3'),
          )
          Manufacturer.objects.bulk_create(manufacturers)
  
          tags = create_tags('Alpha', 'Bravo', 'Charlie')
  
          cls.form_data = {
              'name': 'Manufacturer X',
              'slug': 'manufacturer-x',
              'description': 'A new manufacturer',
              'tags': [t.pk for t in tags],
          }
  
          cls.csv_data = (
              "name,slug,description",
              "Manufacturer 4,manufacturer-4,Fourth manufacturer",
              "Manufacturer 5,manufacturer-5,Fifth manufacturer",
              "Manufacturer 6,manufacturer-6,Sixth manufacturer",
          )
  
          cls.csv_update_data = (
              "id,name,description",
              f"{manufacturers[0].pk},Manufacturer 7,Fourth manufacturer7",
              f"{manufacturers[1].pk},Manufacturer 8,Fifth manufacturer8",
              f"{manufacturers[2].pk},Manufacturer 9,Sixth manufacturer9",
          )
  
          cls.bulk_edit_data = {
              'description': 'New description',
          }
  
  
  # TODO: Change base class to PrimaryObjectViewTestCase
  # Blocked by absence of bulk import view for DeviceTypes
  class DeviceTypeTestCase(
      ViewTestCases.GetObjectViewTestCase,
      ViewTestCases.GetObjectChangelogViewTestCase,
      ViewTestCases.CreateObjectViewTestCase,
      ViewTestCases.EditObjectViewTestCase,
      ViewTestCases.DeleteObjectViewTestCase,
      ViewTestCases.ListObjectsViewTestCase,
      ViewTestCases.BulkEditObjectsViewTestCase,
      ViewTestCases.BulkDeleteObjectsViewTestCase
  ):
      model = DeviceType
  
      @classmethod
      def setUpTestData(cls):
  
          manufacturers = (
              Manufacturer(name='Manufacturer 1', slug='manufacturer-1'),
              Manufacturer(name='Manufacturer 2', slug='manufacturer-2')
          )
          Manufacturer.objects.bulk_create(manufacturers)
  
          platforms = (
              Platform(name='Platform 1', slug='platform-1', manufacturer=manufacturers[0]),
              Platform(name='Platform 2', slug='platform-3', manufacturer=manufacturers[1]),
          )
          for platform in platforms:
              platform.save()
  
          DeviceType.objects.bulk_create([
              DeviceType(model='Device Type 1', slug='device-type-1', manufacturer=manufacturers[0]),
              DeviceType(model='Device Type 2', slug='device-type-2', manufacturer=manufacturers[0]),
              DeviceType(model='Device Type 3', slug='device-type-3', manufacturer=manufacturers[0]),
          ])
  
          tags = create_tags('Alpha', 'Bravo', 'Charlie')
  
          cls.form_data = {
              'manufacturer': manufacturers[1].pk,
              'default_platform': platforms[0].pk,
              'model': 'Device Type X',
              'slug': 'device-type-x',
              'part_number': '123ABC',
              'u_height': 2,
              'is_full_depth': True,
              'subdevice_role': None,
              'comments': 'Some comments',
              'tags': [t.pk for t in tags],
          }
  
          cls.bulk_edit_data = {
              'manufacturer': manufacturers[1].pk,
              'default_platform': platforms[1].pk,
              'u_height': 3,
              'is_full_depth': False,
          }
  
      @override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
      def test_devicetype_consoleports(self):
          devicetype = DeviceType.objects.first()
          console_ports = (
              ConsolePortTemplate(device_type=devicetype, name='Console Port 1'),
              ConsolePortTemplate(device_type=devicetype, name='Console Port 2'),
              ConsolePortTemplate(device_type=devicetype, name='Console Port 3'),
          )
          ConsolePortTemplate.objects.bulk_create(console_ports)
  
          url = reverse('dcim:devicetype_consoleports', kwargs={'pk': devicetype.pk})
          self.assertHttpStatus(self.client.get(url), 200)
  
      @override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
      def test_devicetype_consoleserverports(self):
          devicetype = DeviceType.objects.first()
          console_server_ports = (
              ConsoleServerPortTemplate(device_type=devicetype, name='Console Server Port 1'),
              ConsoleServerPortTemplate(device_type=devicetype, name='Console Server Port 2'),
              ConsoleServerPortTemplate(device_type=devicetype, name='Console Server Port 3'),
          )
          ConsoleServerPortTemplate.objects.bulk_create(console_server_ports)
  
          url = reverse('dcim:devicetype_consoleserverports', kwargs={'pk': devicetype.pk})
          self.assertHttpStatus(self.client.get(url), 200)
  
      @override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
      def test_devicetype_powerports(self):
          devicetype = DeviceType.objects.first()
          power_ports = (
              PowerPortTemplate(device_type=devicetype, name='Power Port 1'),
              PowerPortTemplate(device_type=devicetype, name='Power Port 2'),
              PowerPortTemplate(device_type=devicetype, name='Power Port 3'),
          )
          PowerPortTemplate.objects.bulk_create(power_ports)
  
          url = reverse('dcim:devicetype_powerports', kwargs={'pk': devicetype.pk})
          self.assertHttpStatus(self.client.get(url), 200)
  
      @override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
      def test_devicetype_poweroutlets(self):
          devicetype = DeviceType.objects.first()
          power_outlets = (
              PowerOutletTemplate(device_type=devicetype, name='Power Outlet 1'),
              PowerOutletTemplate(device_type=devicetype, name='Power Outlet 2'),
              PowerOutletTemplate(device_type=devicetype, name='Power Outlet 3'),
          )
          PowerOutletTemplate.objects.bulk_create(power_outlets)
  
          url = reverse('dcim:devicetype_poweroutlets', kwargs={'pk': devicetype.pk})
          self.assertHttpStatus(self.client.get(url), 200)
  
      @override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
      def test_devicetype_interfaces(self):
          devicetype = DeviceType.objects.first()
          interfaces = (
              InterfaceTemplate(device_type=devicetype, name='Interface 1'),
              InterfaceTemplate(device_type=devicetype, name='Interface 2'),
              InterfaceTemplate(device_type=devicetype, name='Interface 3'),
          )
          InterfaceTemplate.objects.bulk_create(interfaces)
  
          url = reverse('dcim:devicetype_interfaces', kwargs={'pk': devicetype.pk})
          self.assertHttpStatus(self.client.get(url), 200)
  
      @override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
      def test_devicetype_rearports(self):
          devicetype = DeviceType.objects.first()
          rear_ports = (
              RearPortTemplate(device_type=devicetype, name='Rear Port 1'),
              RearPortTemplate(device_type=devicetype, name='Rear Port 2'),
              RearPortTemplate(device_type=devicetype, name='Rear Port 3'),
          )
          RearPortTemplate.objects.bulk_create(rear_ports)
  
          url = reverse('dcim:devicetype_rearports', kwargs={'pk': devicetype.pk})
          self.assertHttpStatus(self.client.get(url), 200)
  
      @override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
      def test_devicetype_frontports(self):
          devicetype = DeviceType.objects.first()
          rear_ports = (
              RearPortTemplate(device_type=devicetype, name='Rear Port 1'),
              RearPortTemplate(device_type=devicetype, name='Rear Port 2'),
              RearPortTemplate(device_type=devicetype, name='Rear Port 3'),
          )
          RearPortTemplate.objects.bulk_create(rear_ports)
          front_ports = (
              FrontPortTemplate(
                  device_type=devicetype, name='Front Port 1', rear_port=rear_ports[0], rear_port_position=1
              ),
              FrontPortTemplate(
                  device_type=devicetype, name='Front Port 2', rear_port=rear_ports[1], rear_port_position=1
              ),
              FrontPortTemplate(
                  device_type=devicetype, name='Front Port 3', rear_port=rear_ports[2], rear_port_position=1
              ),
          )
          FrontPortTemplate.objects.bulk_create(front_ports)
  
          url = reverse('dcim:devicetype_frontports', kwargs={'pk': devicetype.pk})
          self.assertHttpStatus(self.client.get(url), 200)
  
      @override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
      def test_devicetype_modulebays(self):
          devicetype = DeviceType.objects.first()
          module_bays = (
              ModuleBayTemplate(device_type=devicetype, name='Module Bay 1'),
              ModuleBayTemplate(device_type=devicetype, name='Module Bay 2'),
              ModuleBayTemplate(device_type=devicetype, name='Module Bay 3'),
          )
          ModuleBayTemplate.objects.bulk_create(module_bays)
  
          url = reverse('dcim:devicetype_modulebays', kwargs={'pk': devicetype.pk})
          self.assertHttpStatus(self.client.get(url), 200)
  
      @override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
      def test_devicetype_devicebays(self):
          devicetype = DeviceType.objects.first()
          device_bays = (
              DeviceBayTemplate(device_type=devicetype, name='Device Bay 1'),
              DeviceBayTemplate(device_type=devicetype, name='Device Bay 2'),
              DeviceBayTemplate(device_type=devicetype, name='Device Bay 3'),
          )
          DeviceBayTemplate.objects.bulk_create(device_bays)
  
          url = reverse('dcim:devicetype_devicebays', kwargs={'pk': devicetype.pk})
          self.assertHttpStatus(self.client.get(url), 200)
  
      @override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
      def test_devicetype_inventoryitems(self):
          devicetype = DeviceType.objects.first()
          inventory_items = (
              DeviceBayTemplate(device_type=devicetype, name='Device Bay 1'),
              DeviceBayTemplate(device_type=devicetype, name='Device Bay 2'),
              DeviceBayTemplate(device_type=devicetype, name='Device Bay 3'),
          )
          for inventory_item in inventory_items:
              inventory_item.save()
  
          url = reverse('dcim:devicetype_inventoryitems', kwargs={'pk': devicetype.pk})
          self.assertHttpStatus(self.client.get(url), 200)
  
      @override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
      def test_import_objects(self):
          """
          Custom import test for YAML-based imports (versus CSV)
          """
          IMPORT_DATA = """
  manufacturer: Generic
  model: TEST-1000
  slug: test-1000
  default_platform: Platform
  u_height: 2
  is_full_depth: false
  airflow: front-to-rear
  subdevice_role: parent
  weight: 10
  weight_unit: kg
  comments: Test comment
  console-ports:
    - name: Console Port 1
      type: de-9
    - name: Console Port 2
      type: de-9
    - name: Console Port 3
      type: de-9
  console-server-ports:
    - name: Console Server Port 1
      type: rj-45
    - name: Console Server Port 2
      type: rj-45
    - name: Console Server Port 3
      type: rj-45
  power-ports:
    - name: Power Port 1
      type: iec-60320-c14
    - name: Power Port 2
      type: iec-60320-c14
    - name: Power Port 3
      type: iec-60320-c14
  power-outlets:
    - name: Power Outlet 1
      type: iec-60320-c13
      power_port: Power Port 1
      feed_leg: A
    - name: Power Outlet 2
      type: iec-60320-c13
      power_port: Power Port 1
      feed_leg: A
    - name: Power Outlet 3
      type: iec-60320-c13
      power_port: Power Port 1
      feed_leg: A
  interfaces:
    - name: Interface 1
      type: 1000base-t
      mgmt_only: true
    - name: Interface 2
      type: 1000base-t
      enabled: false
    - name: Interface 3
      type: 1000base-t
  rear-ports:
    - name: Rear Port 1
      type: 8p8c
    - name: Rear Port 2
      type: 8p8c
    - name: Rear Port 3
      type: 8p8c
  front-ports:
    - name: Front Port 1
      type: 8p8c
      rear_port: Rear Port 1
    - name: Front Port 2
      type: 8p8c
      rear_port: Rear Port 2
    - name: Front Port 3
      type: 8p8c
      rear_port: Rear Port 3
  module-bays:
    - name: Module Bay 1
    - name: Module Bay 2
    - name: Module Bay 3
  device-bays:
    - name: Device Bay 1
    - name: Device Bay 2
    - name: Device Bay 3
  inventory-items:
    - name: Inventory Item 1
      manufacturer: Generic
    - name: Inventory Item 2
      manufacturer: Generic
    - name: Inventory Item 3
      manufacturer: Generic
  """
  
          # Create the manufacturer and platform
          manufacturer = Manufacturer(name='Generic', slug='generic')
          manufacturer.save()
          platform = Platform(name='Platform', slug='test-platform', manufacturer=manufacturer)
          platform.save()
  
          # Add all required permissions to the test user
          self.add_permissions(
              'dcim.view_devicetype',
              'dcim.add_devicetype',
              'dcim.add_consoleporttemplate',
              'dcim.add_consoleserverporttemplate',
              'dcim.add_powerporttemplate',
              'dcim.add_poweroutlettemplate',
              'dcim.add_interfacetemplate',
              'dcim.add_frontporttemplate',
              'dcim.add_rearporttemplate',
              'dcim.add_modulebaytemplate',
              'dcim.add_devicebaytemplate',
              'dcim.add_inventoryitemtemplate',
          )
  
          form_data = {
              'data': IMPORT_DATA,
              'format': 'yaml'
          }
          response = self.client.post(reverse('dcim:devicetype_bulk_import'), data=form_data, follow=True)
          self.assertHttpStatus(response, 200)
  
          device_type = DeviceType.objects.get(model='TEST-1000')
          self.assertEqual(device_type.manufacturer.pk, manufacturer.pk)
          self.assertEqual(device_type.default_platform.pk, platform.pk)
          self.assertEqual(device_type.slug, 'test-1000')
          self.assertEqual(device_type.u_height, 2)
          self.assertFalse(device_type.is_full_depth)
          self.assertEqual(device_type.airflow, DeviceAirflowChoices.AIRFLOW_FRONT_TO_REAR)
          self.assertEqual(device_type.subdevice_role, SubdeviceRoleChoices.ROLE_PARENT)
          self.assertEqual(device_type.weight, 10)
          self.assertEqual(device_type.weight_unit, WeightUnitChoices.UNIT_KILOGRAM)
          self.assertEqual(device_type.comments, 'Test comment')
  
  