content: import json
  
  from django.test import override_settings, tag
  from django.urls import reverse
  from django.utils.translation import gettext as _
  from rest_framework import status
  
  from dcim.choices import *
  from dcim.constants import *
  from dcim.models import *
  from extras.models import ConfigTemplate
  from ipam.choices import VLANQinQRoleChoices
  from ipam.models import ASN, RIR, VLAN, VRF
  from netbox.api.serializers import GenericObjectSerializer
  from tenancy.models import Tenant
  from users.models import User
  from utilities.testing import APITestCase, APIViewTestCases, create_test_device, disable_logging
  from virtualization.models import Cluster, ClusterType
  from wireless.choices import WirelessChannelChoices
  from wireless.models import WirelessLAN
  
  
  class AppTest(APITestCase):
  
      def test_root(self):
  
          url = reverse('dcim-api:api-root')
          response = self.client.get('{}?format=api'.format(url), **self.header)
  
          self.assertEqual(response.status_code, 200)
  
  
  class Mixins:
  
      class ComponentTraceMixin(APITestCase):
          peer_termination_type = None
  
          def test_trace(self):
              """
              Test tracing a device component's attached cable.
              """
              obj = self.model.objects.first()
              peer_device = Device.objects.create(
                  site=Site.objects.first(),
                  device_type=DeviceType.objects.first(),
                  role=DeviceRole.objects.first(),
                  name='Peer Device'
              )
              if self.peer_termination_type is None:
                  raise NotImplementedError(_("Test case must set peer_termination_type"))
              peer_obj = self.peer_termination_type.objects.create(
                  device=peer_device,
                  name='Peer Termination'
              )
              cable = Cable(a_terminations=[obj], b_terminations=[peer_obj], label='Cable 1')
              cable.save()
  
              self.add_permissions(f'dcim.view_{self.model._meta.model_name}')
              url = reverse(f'dcim-api:{self.model._meta.model_name}-trace', kwargs={'pk': obj.pk})
              response = self.client.get(url, **self.header)
  
              self.assertHttpStatus(response, status.HTTP_200_OK)
              self.assertEqual(len(response.data), 1)
              segment1 = response.data[0]
              self.assertEqual(segment1[0][0]['name'], obj.name)
              self.assertEqual(segment1[1]['label'], cable.label)
              self.assertEqual(segment1[2][0]['name'], peer_obj.name)
  
  
  class RegionTest(APIViewTestCases.APIViewTestCase):
      model = Region
      brief_fields = ['_depth', 'description', 'display', 'id', 'name', 'site_count', 'slug', 'url']
      create_data = [
          {
              'name': 'Region 4',
              'slug': 'region-4',
              'comments': 'this is region 4, not region 5',
          },
          {
              'name': 'Region 5',
              'slug': 'region-5',
          },
          {
              'name': 'Region 6',
              'slug': 'region-6',
          },
      ]
      bulk_update_data = {
          'description': 'New description',
          'comments': 'New comments',
      }
  
      @classmethod
      def setUpTestData(cls):
  
          Region.objects.create(name='Region 1', slug='region-1')
          Region.objects.create(name='Region 2', slug='region-2', comments='what in the world is happening?')
          Region.objects.create(name='Region 3', slug='region-3')
  
  
  class SiteGroupTest(APIViewTestCases.APIViewTestCase):
      model = SiteGroup
      brief_fields = ['_depth', 'description', 'display', 'id', 'name', 'site_count', 'slug', 'url']
      create_data = [
          {
              'name': 'Site Group 4',
              'slug': 'site-group-4',
              'comments': '',
          },
          {
              'name': 'Site Group 5',
              'slug': 'site-group-5',
              'comments': 'not actually empty',
          },
          {
              'name': 'Site Group 6',
              'slug': 'site-group-6',
              'comments': 'Do I really exist?',
          },
      ]
      bulk_update_data = {
          'description': 'New description',
          'comments': 'I do exist!',
      }
  
      @classmethod
      def setUpTestData(cls):
  
          SiteGroup.objects.create(name='Site Group 1', slug='site-group-1')
          SiteGroup.objects.create(name='Site Group 2', slug='site-group-2', comments='')
          SiteGroup.objects.create(name='Site Group 3', slug='site-group-3', comments='Hi!')
  
  
  class SiteTest(APIViewTestCases.APIViewTestCase):
      model = Site
      brief_fields = ['description', 'display', 'id', 'name', 'slug', 'url']
      bulk_update_data = {
          'status': 'planned',
      }
  
      @classmethod
      def setUpTestData(cls):
  
          regions = (
              Region.objects.create(name='Region 1', slug='region-1'),
              Region.objects.create(name='Region 2', slug='region-2'),
          )
  
          groups = (
              SiteGroup.objects.create(name='Site Group 1', slug='site-group-1'),
              SiteGroup.objects.create(name='Site Group 2', slug='site-group-2'),
          )
  
          sites = (
              Site(region=regions[0], group=groups[0], name='Site 1', slug='site-1'),
              Site(region=regions[0], group=groups[0], name='Site 2', slug='site-2'),
              Site(region=regions[0], group=groups[0], name='Site 3', slug='site-3'),
          )
          Site.objects.bulk_create(sites)
  
          rir = RIR.objects.create(name='RFC 6996', is_private=True)
          tenant = Tenant.objects.create(name='Tenant 1', slug='tenant-1')
  
          asns = [
              ASN(asn=65000 + i, rir=rir) for i in range(8)
          ]
          ASN.objects.bulk_create(asns)
  
          cls.create_data = [
              {
                  'name': 'Site 4',
                  'slug': 'site-4',
                  'region': regions[1].pk,
                  'group': groups[1].pk,
                  'status': SiteStatusChoices.STATUS_ACTIVE,
                  'asns': [asns[0].pk, asns[1].pk],
                  'tenant': tenant.pk,
              },
              {
                  'name': 'Site 5',
                  'slug': 'site-5',
                  'region': regions[1].pk,
                  'group': groups[1].pk,
                  'status': SiteStatusChoices.STATUS_ACTIVE,
                  'asns': [asns[2].pk, asns[3].pk],
              },
              {
                  'name': 'Site 6',
                  'slug': 'site-6',
                  'region': regions[1].pk,
                  'group': groups[1].pk,
                  'status': SiteStatusChoices.STATUS_ACTIVE,
                  'asns': [asns[4].pk, asns[5].pk],
              },
          ]
  
  
  class LocationTest(APIViewTestCases.APIViewTestCase):
      model = Location
      brief_fields = ['_depth', 'description', 'display', 'id', 'name', 'rack_count', 'slug', 'url']
      bulk_update_data = {
          'description': 'New description',
      }
      user_permissions = ('dcim.view_site',)
  
      @classmethod
      def setUpTestData(cls):
  
          sites = (
              Site(name='Site 1', slug='site-1'),
              Site(name='Site 2', slug='site-2'),
          )
          Site.objects.bulk_create(sites)
  
          parent_locations = (
              Location.objects.create(
                  site=sites[0],
                  name='Parent Location 1',
                  slug='parent-location-1',
                  status=LocationStatusChoices.STATUS_ACTIVE,
                  comments='First!'
              ),
              Location.objects.create(
                  site=sites[1],
                  name='Parent Location 2',
                  slug='parent-location-2',
                  status=LocationStatusChoices.STATUS_ACTIVE,
                  comments='Second!'
              ),
          )
  
          Location.objects.create(
              site=sites[0],
              name='Location 1',
              slug='location-1',
              parent=parent_locations[0],
              status=LocationStatusChoices.STATUS_ACTIVE,
              comments='Third!'
          )
          Location.objects.create(
              site=sites[0],
              name='Location 2',
              slug='location-2',
              parent=parent_locations[0],
              status=LocationStatusChoices.STATUS_ACTIVE,
          )
          Location.objects.create(
              site=sites[0],
              name='Location 3',
              slug='location-3',
              parent=parent_locations[0],
              status=LocationStatusChoices.STATUS_ACTIVE,
          )
  
          cls.create_data = [
              {
                  'name': 'Test Location 4',
                  'slug': 'test-location-4',
                  'site': sites[1].pk,
                  'parent': parent_locations[1].pk,
                  'status': LocationStatusChoices.STATUS_PLANNED,
                  'comments': '',
              },
              {
                  'name': 'Test Location 5',
                  'slug': 'test-location-5',
                  'site': sites[1].pk,
                  'parent': parent_locations[1].pk,
                  'status': LocationStatusChoices.STATUS_PLANNED,
                  'comments': 'Somebody should check on this location',
              },
              {
                  'name': 'Test Location 6',
                  'slug': 'test-location-6',
                  'site': sites[1].pk,
                  # Omit parent to test uniqueness constraint
                  'status': LocationStatusChoices.STATUS_PLANNED,
              },
          ]
  
  
  class RackRoleTest(APIViewTestCases.APIViewTestCase):
      model = RackRole
      brief_fields = ['description', 'display', 'id', 'name', 'rack_count', 'slug', 'url']
      create_data = [
          {
              'name': 'Rack Role 4',
              'slug': 'rack-role-4',
              'color': 'ffff00',
          },
          {
              'name': 'Rack Role 5',
              'slug': 'rack-role-5',
              'color': 'ffff00',
          },
          {
              'name': 'Rack Role 6',
              'slug': 'rack-role-6',
              'color': 'ffff00',
          },
      ]
      bulk_update_data = {
          'description': 'New description',
      }
  
      @classmethod
      def setUpTestData(cls):
  
          rack_roles = (
              RackRole(name='Rack Role 1', slug='rack-role-1', color='ff0000'),
              RackRole(name='Rack Role 2', slug='rack-role-2', color='00ff00'),
              RackRole(name='Rack Role 3', slug='rack-role-3', color='0000ff'),
          )
          RackRole.objects.bulk_create(rack_roles)
  
  
  class RackTypeTest(APIViewTestCases.APIViewTestCase):
      model = RackType
      brief_fields = ['description', 'display', 'id', 'manufacturer', 'model', 'slug', 'url']
      bulk_update_data = {
          'description': 'new description',
      }
      user_permissions = ('dcim.view_manufacturer',)
  
      @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='Rack Type 1',
                  slug='rack-type-1',
                  form_factor=RackFormFactorChoices.TYPE_CABINET,
              ),
              RackType(
                  manufacturer=manufacturers[0],
                  model='Rack Type 2',
                  slug='rack-type-2',
                  form_factor=RackFormFactorChoices.TYPE_CABINET,
              ),
              RackType(
                  manufacturer=manufacturers[0],
                  model='Rack Type 3',
                  slug='rack-type-3',
                  form_factor=RackFormFactorChoices.TYPE_CABINET,
              ),
          )
          RackType.objects.bulk_create(rack_types)
  
          cls.create_data = [
              {
                  'manufacturer': manufacturers[1].pk,
                  'model': 'Rack Type 4',
                  'slug': 'rack-type-4',
                  'form_factor': RackFormFactorChoices.TYPE_CABINET,
              },
              {
                  'manufacturer': manufacturers[1].pk,
                  'model': 'Rack Type 5',
                  'slug': 'rack-type-5',
                  'form_factor': RackFormFactorChoices.TYPE_CABINET,
              },
              {
                  'manufacturer': manufacturers[1].pk,
                  'model': 'Rack Type 6',
                  'slug': 'rack-type-6',
                  'form_factor': RackFormFactorChoices.TYPE_CABINET,
              },
          ]
  
  
  class RackTest(APIViewTestCases.APIViewTestCase):
      model = Rack
      brief_fields = ['description', 'device_count', 'display', 'id', 'name', 'url']
      bulk_update_data = {
          'status': 'planned',
      }
      user_permissions = ('dcim.view_site', )
  
      @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.objects.create(site=sites[0], name='Location 1', slug='location-1'),
              Location.objects.create(site=sites[1], name='Location 2', slug='location-2'),
          )
  
          rack_roles = (
              RackRole(name='Rack Role 1', slug='rack-role-1', color='ff0000'),
              RackRole(name='Rack Role 2', slug='rack-role-2', color='00ff00'),
          )
          RackRole.objects.bulk_create(rack_roles)
  
          racks = (
              Rack(site=sites[0], location=locations[0], role=rack_roles[0], name='Rack 1'),
              Rack(site=sites[0], location=locations[0], role=rack_roles[0], name='Rack 2'),
              Rack(site=sites[0], location=locations[0], role=rack_roles[0], name='Rack 3'),
          )
          Rack.objects.bulk_create(racks)
  
          cls.create_data = [
              {
                  'name': 'Test Rack 4',
                  'site': sites[1].pk,
                  'location': locations[1].pk,
                  'role': rack_roles[1].pk,
              },
              {
                  'name': 'Test Rack 5',
                  'site': sites[1].pk,
                  'location': locations[1].pk,
                  'role': rack_roles[1].pk,
              },
              {
                  'name': 'Test Rack 6',
                  'site': sites[1].pk,
                  'location': locations[1].pk,
                  'role': rack_roles[1].pk,
              },
          ]
  
      def test_get_rack_elevation(self):
          """
          GET a single rack elevation.
          """
          rack = Rack.objects.first()
          self.add_permissions('dcim.view_rack')
          url = reverse('dcim-api:rack-elevation', kwargs={'pk': rack.pk})
  
          # Retrieve all units
          response = self.client.get(url, **self.header)
          self.assertEqual(response.data['count'], 84)
  
          # Search for specific units
          response = self.client.get(f'{url}?q=3', **self.header)
          self.assertEqual(response.data['count'], 26)
          response = self.client.get(f'{url}?q=U3', **self.header)
          self.assertEqual(response.data['count'], 22)
          response = self.client.get(f'{url}?q=U10', **self.header)
          self.assertEqual(response.data['count'], 2)
  
      def test_get_rack_elevation_svg(self):
          """
          GET a single rack elevation in SVG format.
          """
          rack = Rack.objects.first()
          self.add_permissions('dcim.view_rack')
          url = '{}?render=svg'.format(reverse('dcim-api:rack-elevation', kwargs={'pk': rack.pk}))
  
          response = self.client.get(url, **self.header)
          self.assertHttpStatus(response, status.HTTP_200_OK)
          self.assertEqual(response.get('Content-Type'), 'image/svg+xml')
  
  
  class RackReservationTest(APIViewTestCases.APIViewTestCase):
      model = RackReservation
      brief_fields = ['description', 'display', 'id', 'status', 'units', 'url', 'user']
      bulk_update_data = {
          'description': 'New description',
      }
      user_permissions = ('dcim.view_rack', 'users.view_user')
  
      @classmethod
      def setUpTestData(cls):
          user = User.objects.create(username='user1', is_active=True)
          site = Site.objects.create(name='Test Site 1', slug='test-site-1')
  
          racks = (
              Rack(site=site, name='Rack 1'),
              Rack(site=site, name='Rack 2'),
          )
          Rack.objects.bulk_create(racks)
  
          rack_reservations = (
              RackReservation(
                  rack=racks[0],
                  units=[1, 2, 3],
                  user=user,
                  description='Reservation #1',
              ),
              RackReservation(
                  rack=racks[0],
                  units=[4, 5, 6],
                  user=user,
                  description='Reservation #2'
              ),
              RackReservation(
                  rack=racks[0],
                  units=[7, 8, 9],
                  user=user,
                  description='Reservation #3',
              ),
          )
          RackReservation.objects.bulk_create(rack_reservations)
  
          cls.create_data = [
              {
                  'rack': racks[1].pk,
                  'units': [10, 11, 12],
                  'status': RackReservationStatusChoices.STATUS_ACTIVE,
                  'user': user.pk,
                  'description': 'Reservation #4',
              },
              {
                  'rack': racks[1].pk,
                  'units': [13, 14, 15],
                  'status': RackReservationStatusChoices.STATUS_PENDING,
                  'user': user.pk,
                  'description': 'Reservation #5',
              },
              {
                  'rack': racks[1].pk,
                  'units': [16, 17, 18],
                  'status': RackReservationStatusChoices.STATUS_STALE,
                  'user': user.pk,
                  'description': 'Reservation #6',
              },
          ]
  
  
  class ManufacturerTest(APIViewTestCases.APIViewTestCase):
      model = Manufacturer
      brief_fields = ['description', 'display', 'id', 'name', 'slug', 'url']
      create_data = [
          {
              'name': 'Manufacturer 4',
              'slug': 'manufacturer-4',
          },
          {
              'name': 'Manufacturer 5',
              'slug': 'manufacturer-5',
          },
          {
              'name': 'Manufacturer 6',
              'slug': 'manufacturer-6',
          },
      ]
      bulk_update_data = {
          'description': 'New description',
      }
  
      @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)
  
  
  class DeviceTypeTest(APIViewTestCases.APIViewTestCase):
      model = DeviceType
      brief_fields = ['description', 'device_count', 'display', 'id', 'manufacturer', 'model', 'slug', 'url']
      bulk_update_data = {
          'part_number': 'ABC123',
      }
      user_permissions = ('dcim.view_manufacturer', )
  
      @classmethod
      def setUpTestData(cls):
  
          manufacturers = (
              Manufacturer(name='Manufacturer 1', slug='manufacturer-1'),
              Manufacturer(name='Manufacturer 2', slug='manufacturer-2'),
          )
          Manufacturer.objects.bulk_create(manufacturers)
  
          device_types = (
              DeviceType(manufacturer=manufacturers[0], model='Device Type 1', slug='device-type-1'),
              DeviceType(manufacturer=manufacturers[0], model='Device Type 2', slug='device-type-2'),
              DeviceType(manufacturer=manufacturers[0], model='Device Type 3', slug='device-type-3'),
          )
          DeviceType.objects.bulk_create(device_types)
  
          cls.create_data = [
              {
                  'manufacturer': manufacturers[1].pk,
                  'model': 'Device Type 4',
                  'slug': 'device-type-4',
                  'u_height': 0,
              },
              {
                  'manufacturer': manufacturers[1].pk,
                  'model': 'Device Type 5',
                  'slug': 'device-type-5',
                  'u_height': 0.5,
              },
              {
                  'manufacturer': manufacturers[1].pk,
                  'model': 'Device Type 6',
                  'slug': 'device-type-6',
                  'u_height': 1,
              },
          ]
  
  
  class ModuleTypeTest(APIViewTestCases.APIViewTestCase):
      model = ModuleType
      brief_fields = ['description', 'display', 'id', 'manufacturer', 'model', 'profile', 'url']
      bulk_update_data = {
          'part_number': 'ABC123',
      }
      user_permissions = ('dcim.view_manufacturer', )
  
      @classmethod
      def setUpTestData(cls):
  
          manufacturers = (
              Manufacturer(name='Manufacturer 1', slug='manufacturer-1'),
              Manufacturer(name='Manufacturer 2', slug='manufacturer-2'),
          )
          Manufacturer.objects.bulk_create(manufacturers)
  
          module_types = (
              ModuleType(manufacturer=manufacturers[0], model='Module Type 1'),
              ModuleType(manufacturer=manufacturers[0], model='Module Type 2'),
              ModuleType(manufacturer=manufacturers[0], model='Module Type 3'),
          )
          ModuleType.objects.bulk_create(module_types)
  
          cls.create_data = [
              {
                  'manufacturer': manufacturers[1].pk,
                  'model': 'Module Type 4',
              },
              {
                  'manufacturer': manufacturers[1].pk,
                  'model': 'Module Type 5',
              },
              {
                  'manufacturer': manufacturers[1].pk,
                  'model': 'Module Type 6',
              },
          ]
  
  
  class ModuleTypeProfileTest(APIViewTestCases.APIViewTestCase):
      model = ModuleTypeProfile
      brief_fields = ['description', 'display', 'id', 'name', 'url']
      SCHEMAS = [
          {
              "properties": {
                  "foo": {
                      "type": "string"
                  }
              }
          },
          {
              "properties": {
                  "foo": {
                      "type": "integer"
                  }
              }
          },
          {
              "properties": {
                  "foo": {
                      "type": "boolean"
                  }
              }
          },
      ]
      create_data = [
          {
              'name': 'Module Type Profile 4',
              'schema': SCHEMAS[0],
          },
          {
              'name': 'Module Type Profile 5',
              'schema': SCHEMAS[1],
          },
          {
              'name': 'Module Type Profile 6',
              'schema': SCHEMAS[2],
          },
      ]
      bulk_update_data = {
          'description': 'New description',
          'comments': 'New comments',
      }
  
      @classmethod
      def setUpTestData(cls):
          module_type_profiles = (
              ModuleTypeProfile(
                  name='Module Type Profile 1',
                  schema=cls.SCHEMAS[0]
              ),
              ModuleTypeProfile(
                  name='Module Type Profile 2',
                  schema=cls.SCHEMAS[1]
              ),
              ModuleTypeProfile(
                  name='Module Type Profile 3',
                  schema=cls.SCHEMAS[2]
              ),
          )
          ModuleTypeProfile.objects.bulk_create(module_type_profiles)
  
  
  class ConsolePortTemplateTest(APIViewTestCases.APIViewTestCase):
      model = ConsolePortTemplate
      brief_fields = ['description', 'display', 'id', 'name', 'url']
      bulk_update_data = {
          'description': 'New description',
      }
  
      @classmethod
      def setUpTestData(cls):
          manufacturer = Manufacturer.objects.create(name='Test Manufacturer 1', slug='test-manufacturer-1')
          devicetype = DeviceType.objects.create(
              manufacturer=manufacturer, model='Device Type 1', slug='device-type-1'
          )
          moduletype = ModuleType.objects.create(
              manufacturer=manufacturer, model='Module Type 1'
          )
  
          console_port_templates = (
              ConsolePortTemplate(device_type=devicetype, name='Console Port Template 1'),
              ConsolePortTemplate(device_type=devicetype, name='Console Port Template 2'),
              ConsolePortTemplate(device_type=devicetype, name='Console Port Template 3'),
          )
          ConsolePortTemplate.objects.bulk_create(console_port_templates)
  
          cls.create_data = [
              {
                  'device_type': devicetype.pk,
                  'name': 'Console Port Template 4',
              },
              {
                  'device_type': devicetype.pk,
                  'name': 'Console Port Template 5',
              },
              {
                  'module_type': moduletype.pk,
                  'name': 'Console Port Template 6',
              },
              {
                  'module_type': moduletype.pk,
                  'name': 'Console Port Template 7',
              },
          ]
  
  
  class ConsoleServerPortTemplateTest(APIViewTestCases.APIViewTestCase):
      model = ConsoleServerPortTemplate
      brief_fields = ['description', 'display', 'id', 'name', 'url']
      bulk_update_data = {
          'description': 'New description',
      }
  
      @classmethod
      def setUpTestData(cls):
          manufacturer = Manufacturer.objects.create(name='Test Manufacturer 1', slug='test-manufacturer-1')
          devicetype = DeviceType.objects.create(
              manufacturer=manufacturer, model='Device Type 1', slug='device-type-1'
          )
          moduletype = ModuleType.objects.create(
              manufacturer=manufacturer, model='Module Type 1'
          )
  
          console_server_port_templates = (
              ConsoleServerPortTemplate(device_type=devicetype, name='Console Server Port Template 1'),
              ConsoleServerPortTemplate(device_type=devicetype, name='Console Server Port Template 2'),
              ConsoleServerPortTemplate(device_type=devicetype, name='Console Server Port Template 3'),
          )
          ConsoleServerPortTemplate.objects.bulk_create(console_server_port_templates)
  
          cls.create_data = [
              {
                  'device_type': devicetype.pk,
                  'name': 'Console Server Port Template 4',
              },
              {
                  'device_type': devicetype.pk,
                  'name': 'Console Server Port Template 5',
              },
              {
                  'module_type': moduletype.pk,
                  'name': 'Console Server Port Template 6',
              },
              {
                  'module_type': moduletype.pk,
                  'name': 'Console Server Port Template 7',
              },
          ]
  
  
  class PowerPortTemplateTest(APIViewTestCases.APIViewTestCase):
      model = PowerPortTemplate
      brief_fields = ['description', 'display', 'id', 'name', 'url']
      bulk_update_data = {
          'description': 'New description',
      }
  
      @classmethod
      def setUpTestData(cls):
          manufacturer = Manufacturer.objects.create(name='Test Manufacturer 1', slug='test-manufacturer-1')
          devicetype = DeviceType.objects.create(
              manufacturer=manufacturer, model='Device Type 1', slug='device-type-1'
          )
          moduletype = ModuleType.objects.create(
              manufacturer=manufacturer, model='Module Type 1'
          )
  
          power_port_templates = (
              PowerPortTemplate(device_type=devicetype, name='Power Port Template 1'),
              PowerPortTemplate(device_type=devicetype, name='Power Port Template 2'),
              PowerPortTemplate(device_type=devicetype, name='Power Port Template 3'),
          )
          PowerPortTemplate.objects.bulk_create(power_port_templates)
  
          cls.create_data = [
              {
                  'device_type': devicetype.pk,
                  'name': 'Power Port Template 4',
              },
              {
                  'device_type': devicetype.pk,
                  'name': 'Power Port Template 5',
              },
              {
                  'module_type': moduletype.pk,
                  'name': 'Power Port Template 6',
              },
              {
                  'module_type': moduletype.pk,
                  'name': 'Power Port Template 7',
              },
          ]
  
  
  class PowerOutletTemplateTest(APIViewTestCases.APIViewTestCase):
      model = PowerOutletTemplate
      brief_fields = ['description', 'display', 'id', 'name', 'url']
      bulk_update_data = {
          'description': 'New description',
      }
      user_permissions = ('dcim.view_devicetype', )
  
      @classmethod
      def setUpTestData(cls):
          manufacturer = Manufacturer.objects.create(name='Test Manufacturer 1', slug='test-manufacturer-1')
          devicetype = DeviceType.objects.create(
              manufacturer=manufacturer, model='Device Type 1', slug='device-type-1'
          )
          moduletype = ModuleType.objects.create(
              manufacturer=manufacturer, model='Module Type 1'
          )
  
          power_port_templates = (
              PowerPortTemplate(device_type=devicetype, name='Power Port Template 1'),
              PowerPortTemplate(device_type=devicetype, name='Power Port Template 2'),
          )
          PowerPortTemplate.objects.bulk_create(power_port_templates)
  
          power_outlet_templates = (
              PowerOutletTemplate(device_type=devicetype, name='Power Outlet Template 1'),
              PowerOutletTemplate(device_type=devicetype, name='Power Outlet Template 2'),
              PowerOutletTemplate(device_type=devicetype, name='Power Outlet Template 3'),
          )
          PowerOutletTemplate.objects.bulk_create(power_outlet_templates)
  
          cls.create_data = [
              {
                  'device_type': devicetype.pk,
                  'name': 'Power Outlet Template 4',
                  'power_port': power_port_templates[0].pk,
              },
              {
                  'device_type': devicetype.pk,
                  'name': 'Power Outlet Template 5',
                  'power_port': power_port_templates[1].pk,
              },
              {
                  'device_type': devicetype.pk,
                  'name': 'Power Outlet Template 6',
                  'power_port': None,
              },
              {
                  'module_type': moduletype.pk,
                  'name': 'Power Outlet Template 7',
              },
              {
                  'module_type': moduletype.pk,
                  'name': 'Power Outlet Template 8',
              },
          ]
  
  
  class InterfaceTemplateTest(APIViewTestCases.APIViewTestCase):
      model = InterfaceTemplate
      brief_fields = ['description', 'display', 'id', 'name', 'url']
      bulk_update_data = {
          'description': 'New description',
      }
  
      @classmethod
      def setUpTestData(cls):
          manufacturer = Manufacturer.objects.create(name='Test Manufacturer 1', slug='test-manufacturer-1')
          devicetype = DeviceType.objects.create(
              manufacturer=manufacturer, model='Device Type 1', slug='device-type-1'
          )
          moduletype = ModuleType.objects.create(
              manufacturer=manufacturer, model='Module Type 1'
          )
  
          interface_templates = (
              InterfaceTemplate(device_type=devicetype, name='Interface Template 1', type='1000base-t'),
              InterfaceTemplate(device_type=devicetype, name='Interface Template 2', type='1000base-t'),
              InterfaceTemplate(device_type=devicetype, name='Interface Template 3', type='1000base-t'),
          )
          InterfaceTemplate.objects.bulk_create(interface_templates)
  
          cls.create_data = [
              {
                  'device_type': devicetype.pk,
                  'name': 'Interface Template 4',
                  'type': '1000base-t',
              },
              {
                  'device_type': devicetype.pk,
                  'name': 'Interface Template 5',
                  'type': '1000base-t',
              },
              {
                  'module_type': moduletype.pk,
                  'name': 'Interface Template 6',
                  'type': '1000base-t',
              },
              {
                  'module_type': moduletype.pk,
                  'name': 'Interface Template 7',
                  'type': '1000base-t',
              },
          ]
  
  
  class FrontPortTemplateTest(APIViewTestCases.APIViewTestCase):
      model = FrontPortTemplate
      brief_fields = ['description', 'display', 'id', 'name', 'url']
      bulk_update_data = {
          'description': 'New description',
      }
      user_permissions = ('dcim.view_rearporttemplate', )
  
      @classmethod
      def setUpTestData(cls):
          manufacturer = Manufacturer.objects.create(name='Test Manufacturer 1', slug='test-manufacturer-1')
          devicetype = DeviceType.objects.create(
              manufacturer=manufacturer, model='Device Type 1', slug='device-type-1'
          )
          moduletype = ModuleType.objects.create(
              manufacturer=manufacturer, model='Module Type 1'
          )
  
          rear_port_templates = (
              RearPortTemplate(device_type=devicetype, name='Rear Port Template 1', type=PortTypeChoices.TYPE_8P8C),
              RearPortTemplate(device_type=devicetype, name='Rear Port Template 2', type=PortTypeChoices.TYPE_8P8C),
  