content: from django.test import TestCase
  
  from circuits.models import Circuit, CircuitTermination, CircuitType, Provider
  from dcim.choices import *
  from dcim.filtersets import *
  from dcim.models import *
  from ipam.choices import VLANQinQRoleChoices
  from ipam.models import ASN, IPAddress, RIR, VLAN, VLANTranslationPolicy, VRF
  from netbox.choices import ColorChoices, WeightUnitChoices
  from tenancy.models import Tenant, TenantGroup
  from users.models import User
  from utilities.testing import ChangeLoggedFilterSetTests, create_test_device, create_test_virtualmachine
  from virtualization.models import Cluster, ClusterGroup, ClusterType, VirtualMachine, VMInterface
  from wireless.choices import WirelessChannelChoices, WirelessRoleChoices
  from wireless.models import WirelessLink
  
  
  class DeviceComponentFilterSetTests:
  
      def test_q(self):
          params = {'q': 'First'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
  
      def test_description(self):
          params = {'description': ['First', 'Second']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_device_type(self):
          device_types = DeviceType.objects.all()[:2]
          params = {'device_type_id': [device_types[0].pk, device_types[1].pk]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
          params = {'device_type': [device_types[0].model, device_types[1].model]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_device_role(self):
          role = DeviceRole.objects.all()[:2]
          params = {'device_role_id': [role[0].pk, role[1].pk]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
          params = {'device_role': [role[0].slug, role[1].slug]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_device_status(self):
          params = {'device_status': ['active', 'planned']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_tenant(self):
          tenants = Tenant.objects.all()[:2]
          params = {'tenant_id': [tenants[0].pk, tenants[1].pk]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
          params = {'tenant': [tenants[0].slug, tenants[1].slug]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
  
  class DeviceComponentTemplateFilterSetTests:
  
      def test_q(self):
          params = {'q': 'foobar1'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
  
      def test_description(self):
          params = {'description': ['foobar1', 'foobar2']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_device_type_id(self):
          device_types = DeviceType.objects.all()[:2]
          params = {'device_type_id': [device_types[0].pk, device_types[1].pk]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
  
  class RegionTestCase(TestCase, ChangeLoggedFilterSetTests):
      queryset = Region.objects.all()
      filterset = RegionFilterSet
  
      @classmethod
      def setUpTestData(cls):
  
          parent_regions = (
              Region(
                  name='Region 1', slug='region-1', description='foobar1', comments="There's nothing that",
              ),
              Region(
                  name='Region 2', slug='region-2', description='foobar2', comments='a hundred men or more',
              ),
              Region(
                  name='Region 3', slug='region-3', description='foobar3', comments='could ever do'
              ),
          )
          for region in parent_regions:
              region.save()
  
          regions = (
              Region(name='Region 1A', slug='region-1a', parent=parent_regions[0]),
              Region(name='Region 1B', slug='region-1b', parent=parent_regions[0]),
              Region(name='Region 2A', slug='region-2a', parent=parent_regions[1]),
              Region(name='Region 2B', slug='region-2b', parent=parent_regions[1]),
              Region(name='Region 3A', slug='region-3a', parent=parent_regions[2]),
              Region(name='Region 3B', slug='region-3b', parent=parent_regions[2]),
          )
          for region in regions:
              region.save()
  
          child_regions = (
              Region(name='Region 1A1', slug='region-1a1', parent=regions[0]),
              Region(name='Region 1B1', slug='region-1b1', parent=regions[1]),
              Region(name='Region 2A1', slug='region-2a1', parent=regions[2]),
              Region(name='Region 2B1', slug='region-2b1', parent=regions[3]),
              Region(name='Region 3A1', slug='region-3a1', parent=regions[4]),
              Region(name='Region 3B1', slug='region-3b1', parent=regions[5]),
          )
          for region in child_regions:
              region.save()
  
      def test_q(self):
          params = {'q': 'foobar1'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
  
      def test_q_comments(self):
          params = {'q': 'there'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
  
          params = {'q': 'hundred men could'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 0)
  
      def test_name(self):
          params = {'name': ['Region 1', 'Region 2']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_slug(self):
          params = {'slug': ['region-1', 'region-2']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_description(self):
          params = {'description': ['foobar1', 'foobar2']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_parent(self):
          regions = Region.objects.filter(parent__isnull=True)[:2]
          params = {'parent_id': [regions[0].pk, regions[1].pk]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
          params = {'parent': [regions[0].slug, regions[1].slug]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
  
      def test_ancestor(self):
          regions = Region.objects.filter(parent__isnull=True)[:2]
          params = {'ancestor_id': [regions[0].pk, regions[1].pk]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 8)
          params = {'ancestor': [regions[0].slug, regions[1].slug]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 8)
  
  
  class SiteGroupTestCase(TestCase, ChangeLoggedFilterSetTests):
      queryset = SiteGroup.objects.all()
      filterset = SiteGroupFilterSet
  
      @classmethod
      def setUpTestData(cls):
  
          parent_groups = (
              SiteGroup(name='Site Group 1', slug='site-group-1', description='foobar1'),
              SiteGroup(name='Site Group 2', slug='site-group-2', description='foobar2'),
              SiteGroup(name='Site Group 3', slug='site-group-3', description='foobar3'),
          )
          for site_group in parent_groups:
              site_group.save()
  
          groups = (
              SiteGroup(name='Site Group 1A', slug='site-group-1a', parent=parent_groups[0]),
              SiteGroup(name='Site Group 1B', slug='site-group-1b', parent=parent_groups[0]),
              SiteGroup(name='Site Group 2A', slug='site-group-2a', parent=parent_groups[1]),
              SiteGroup(name='Site Group 2B', slug='site-group-2b', parent=parent_groups[1]),
              SiteGroup(name='Site Group 3A', slug='site-group-3a', parent=parent_groups[2]),
              SiteGroup(
                  name='Site Group 3B', slug='site-group-3b', parent=parent_groups[2], comments='this is a parent group',
              ),
          )
          for site_group in groups:
              site_group.save()
  
          child_groups = (
              SiteGroup(
                  name='Site Group 1A1', slug='site-group-1a1', parent=groups[0], comments='this is a child group',
              ),
              SiteGroup(name='Site Group 1B1', slug='site-group-1b1', parent=groups[1]),
              SiteGroup(name='Site Group 2A1', slug='site-group-2a1', parent=groups[2]),
              SiteGroup(name='Site Group 2B1', slug='site-group-2b1', parent=groups[3]),
              SiteGroup(name='Site Group 3A1', slug='site-group-3a1', parent=groups[4]),
              SiteGroup(name='Site Group 3B1', slug='site-group-3b1', parent=groups[5]),
          )
          for site_group in child_groups:
              site_group.save()
  
      def test_q(self):
          params = {'q': 'foobar1'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
  
      def test_q_comments(self):
          params = {'q': 'this'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
          params = {'q': 'child'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
  
      def test_name(self):
          params = {'name': ['Site Group 1', 'Site Group 2']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_slug(self):
          params = {'slug': ['site-group-1', 'site-group-2']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_description(self):
          params = {'description': ['foobar1', 'foobar2']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_parent(self):
          site_groups = SiteGroup.objects.filter(parent__isnull=True)[:2]
          params = {'parent_id': [site_groups[0].pk, site_groups[1].pk]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
          params = {'parent': [site_groups[0].slug, site_groups[1].slug]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
  
      def test_ancestor(self):
          site_groups = SiteGroup.objects.filter(parent__isnull=True)[:2]
          params = {'ancestor_id': [site_groups[0].pk, site_groups[1].pk]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 8)
          params = {'ancestor': [site_groups[0].slug, site_groups[1].slug]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 8)
  
  
  class SiteTestCase(TestCase, ChangeLoggedFilterSetTests):
      queryset = Site.objects.all()
      filterset = SiteFilterSet
      ignore_fields = ('physical_address', 'shipping_address')
  
      @classmethod
      def setUpTestData(cls):
  
          regions = (
              Region(name='Region 1', slug='region-1'),
              Region(name='Region 2', slug='region-2'),
              Region(name='Region 3', slug='region-3'),
          )
          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'),
              SiteGroup(name='Site Group 3', slug='site-group-3'),
          )
          for group in groups:
              group.save()
  
          tenant_groups = (
              TenantGroup(name='Tenant group 1', slug='tenant-group-1'),
              TenantGroup(name='Tenant group 2', slug='tenant-group-2'),
              TenantGroup(name='Tenant group 3', slug='tenant-group-3'),
          )
          for tenantgroup in tenant_groups:
              tenantgroup.save()
  
          tenants = (
              Tenant(name='Tenant 1', slug='tenant-1', group=tenant_groups[0]),
              Tenant(name='Tenant 2', slug='tenant-2', group=tenant_groups[1]),
              Tenant(name='Tenant 3', slug='tenant-3', group=tenant_groups[2]),
          )
          Tenant.objects.bulk_create(tenants)
  
          rir = RIR.objects.create(name='RFC 6996', is_private=True)
          asns = (
              ASN(asn=64512, rir=rir, tenant=tenants[0]),
              ASN(asn=64513, rir=rir, tenant=tenants[0]),
              ASN(asn=64514, rir=rir, tenant=tenants[0]),
          )
          ASN.objects.bulk_create(asns)
  
          sites = (
              Site(
                  name='Site 1',
                  slug='site-1',
                  region=regions[0],
                  group=groups[0],
                  tenant=tenants[0],
                  status=SiteStatusChoices.STATUS_ACTIVE,
                  facility='Facility 1',
                  latitude=10,
                  longitude=10,
                  description='foobar1',
              ),
              Site(
                  name='Site 2',
                  slug='site-2',
                  region=regions[1],
                  group=groups[1],
                  tenant=tenants[1],
                  status=SiteStatusChoices.STATUS_PLANNED,
                  facility='Facility 2',
                  latitude=20,
                  longitude=20,
                  description='foobar2',
              ),
              Site(
                  name='Site 3',
                  slug='site-3',
                  region=regions[2],
                  group=groups[2],
                  tenant=tenants[2],
                  status=SiteStatusChoices.STATUS_RETIRED,
                  facility='Facility 3',
                  latitude=30,
                  longitude=30,
              ),
          )
          Site.objects.bulk_create(sites)
          sites[0].asns.set([asns[0]])
          sites[1].asns.set([asns[1]])
          sites[2].asns.set([asns[2]])
  
      def test_q(self):
          params = {'q': 'foobar1'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
  
      def test_name(self):
          params = {'name': ['Site 1', 'Site 2']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_slug(self):
          params = {'slug': ['site-1', 'site-2']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_facility(self):
          params = {'facility': ['Facility 1', 'Facility 2']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_asn(self):
          params = {'asn': ['64512', '64513']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_asn_id(self):
          asns = ASN.objects.all()[:2]
          params = {'asn_id': [asns[0].pk, asns[1].pk]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_latitude(self):
          params = {'latitude': [10, 20]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_longitude(self):
          params = {'longitude': [10, 20]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_description(self):
          params = {'description': ['foobar1', 'foobar2']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_status(self):
          params = {'status': [SiteStatusChoices.STATUS_ACTIVE, SiteStatusChoices.STATUS_PLANNED]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_region(self):
          regions = Region.objects.all()[:2]
          params = {'region_id': [regions[0].pk, regions[1].pk]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
          params = {'region': [regions[0].slug, regions[1].slug]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_site_group(self):
          groups = SiteGroup.objects.all()[:2]
          params = {'group_id': [groups[0].pk, groups[1].pk]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
          params = {'group': [groups[0].slug, groups[1].slug]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_tenant(self):
          tenants = Tenant.objects.all()[:2]
          params = {'tenant_id': [tenants[0].pk, tenants[1].pk]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
          params = {'tenant': [tenants[0].slug, tenants[1].slug]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_tenant_group(self):
          tenant_groups = TenantGroup.objects.all()[:2]
          params = {'tenant_group_id': [tenant_groups[0].pk, tenant_groups[1].pk]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
          params = {'tenant_group': [tenant_groups[0].slug, tenant_groups[1].slug]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
  
  class LocationTestCase(TestCase, ChangeLoggedFilterSetTests):
      queryset = Location.objects.all()
      filterset = LocationFilterSet
  
      @classmethod
      def setUpTestData(cls):
  
          regions = (
              Region(name='Region 1', slug='region-1'),
              Region(name='Region 2', slug='region-2'),
              Region(name='Region 3', slug='region-3'),
          )
          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'),
              SiteGroup(name='Site Group 3', slug='site-group-3'),
          )
          for group in groups:
              group.save()
  
          sites = (
              Site(name='Site 1', slug='site-1', region=regions[0], group=groups[0]),
              Site(name='Site 2', slug='site-2', region=regions[1], group=groups[1]),
              Site(name='Site 3', slug='site-3', region=regions[2], group=groups[2]),
          )
          Site.objects.bulk_create(sites)
  
          parent_locations = (
              Location(name='Location 1', slug='location-1', site=sites[0]),
              Location(name='Location 2', slug='location-2', site=sites[1]),
              Location(name='Location 3', slug='location-3', site=sites[2]),
          )
          for location in parent_locations:
              location.save()
  
          locations = (
              Location(
                  name='Location 1A',
                  slug='location-1a',
                  site=sites[0],
                  parent=parent_locations[0],
                  status=LocationStatusChoices.STATUS_PLANNED,
                  facility='Facility 1',
                  description='foobar1',
                  comments='',
              ),
              Location(
                  name='Location 2A',
                  slug='location-2a',
                  site=sites[1],
                  parent=parent_locations[1],
                  status=LocationStatusChoices.STATUS_STAGING,
                  facility='Facility 2',
                  description='foobar2',
                  comments='First comment!',
              ),
              Location(
                  name='Location 3A',
                  slug='location-3a',
                  site=sites[2],
                  parent=parent_locations[2],
                  status=LocationStatusChoices.STATUS_DECOMMISSIONING,
                  facility='Facility 3',
                  description='foobar3',
                  comments='_This_ is a **bold comment**',
              ),
          )
          for location in locations:
              location.save()
  
          child_locations = (
              Location(name='Location 1A1', slug='location-1a1', site=sites[0], parent=locations[0]),
              Location(name='Location 2A1', slug='location-2a1', site=sites[1], parent=locations[1]),
              Location(name='Location 3A1', slug='location-3a1', site=sites[2], parent=locations[2]),
          )
          for location in child_locations:
              location.save()
  
      def test_q(self):
          params = {'q': 'foobar1'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
  
      def test_q_comments(self):
          params = {'q': 'this'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
  
          params = {'q': 'comment'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_name(self):
          params = {'name': ['Location 1', 'Location 2']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_slug(self):
          params = {'slug': ['location-1', 'location-2']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_status(self):
          params = {'status': [LocationStatusChoices.STATUS_PLANNED, LocationStatusChoices.STATUS_STAGING]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_facility(self):
          params = {'facility': ['Facility 1', 'Facility 2']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_description(self):
          params = {'description': ['foobar1', 'foobar2']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_region(self):
          regions = Region.objects.all()[:2]
          params = {'region_id': [regions[0].pk, regions[1].pk]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 6)
          params = {'region': [regions[0].slug, regions[1].slug]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 6)
  
      def test_site_group(self):
          site_groups = SiteGroup.objects.all()[:2]
          params = {'site_group_id': [site_groups[0].pk, site_groups[1].pk]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 6)
          params = {'site_group': [site_groups[0].slug, site_groups[1].slug]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 6)
  
      def test_site(self):
          sites = Site.objects.all()[:2]
          params = {'site_id': [sites[0].pk, sites[1].pk]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 6)
          params = {'site': [sites[0].slug, sites[1].slug]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 6)
  
      def test_parent(self):
          locations = Location.objects.filter(parent__isnull=True)[:2]
          params = {'parent_id': [locations[0].pk, locations[1].pk]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
          params = {'parent': [locations[0].slug, locations[1].slug]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_ancestor(self):
          locations = Location.objects.filter(parent__isnull=True)[:2]
          params = {'ancestor_id': [locations[0].pk, locations[1].pk]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
          params = {'ancestor': [locations[0].slug, locations[1].slug]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
  
  
  class RackRoleTestCase(TestCase, ChangeLoggedFilterSetTests):
      queryset = RackRole.objects.all()
      filterset = RackRoleFilterSet
  
      @classmethod
      def setUpTestData(cls):
  
          rack_roles = (
              RackRole(name='Rack Role 1', slug='rack-role-1', color='ff0000', description='foobar1'),
              RackRole(name='Rack Role 2', slug='rack-role-2', color='00ff00', description='foobar2'),
              RackRole(name='Rack Role 3', slug='rack-role-3', color='0000ff'),
          )
          RackRole.objects.bulk_create(rack_roles)
  
      def test_q(self):
          params = {'q': 'foobar1'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
  
      def test_name(self):
          params = {'name': ['Rack Role 1', 'Rack Role 2']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_slug(self):
          params = {'slug': ['rack-role-1', 'rack-role-2']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_color(self):
          params = {'color': ['ff0000', '00ff00']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_description(self):
          params = {'description': ['foobar1', 'foobar2']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
  
  class RackTypeTestCase(TestCase, ChangeLoggedFilterSetTests):
      queryset = RackType.objects.all()
      filterset = RackTypeFilterSet
  
      @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)
  
          racks = (
              RackType(
                  manufacturer=manufacturers[0],
                  model='RackType 1',
                  slug='rack-type-1',
                  form_factor=RackFormFactorChoices.TYPE_2POST,
                  width=RackWidthChoices.WIDTH_19IN,
                  u_height=42,
                  starting_unit=1,
                  desc_units=False,
                  outer_width=100,
                  outer_height=100,
                  outer_depth=100,
                  outer_unit=RackDimensionUnitChoices.UNIT_MILLIMETER,
                  mounting_depth=100,
                  weight=10,
                  max_weight=1000,
                  weight_unit=WeightUnitChoices.UNIT_POUND,
                  description='foobar1',
              ),
              RackType(
                  manufacturer=manufacturers[1],
                  model='RackType 2',
                  slug='rack-type-2',
                  form_factor=RackFormFactorChoices.TYPE_4POST,
                  width=RackWidthChoices.WIDTH_21IN,
                  u_height=43,
                  starting_unit=2,
                  desc_units=False,
                  outer_width=200,
                  outer_height=200,
                  outer_depth=200,
                  outer_unit=RackDimensionUnitChoices.UNIT_MILLIMETER,
                  mounting_depth=200,
                  weight=20,
                  max_weight=2000,
                  weight_unit=WeightUnitChoices.UNIT_POUND,
                  description='foobar2',
              ),
              RackType(
                  manufacturer=manufacturers[2],
                  model='RackType 3',
                  slug='rack-type-3',
                  form_factor=RackFormFactorChoices.TYPE_CABINET,
                  width=RackWidthChoices.WIDTH_23IN,
                  u_height=44,
                  starting_unit=3,
                  desc_units=True,
                  outer_width=300,
                  outer_height=300,
                  outer_depth=300,
                  outer_unit=RackDimensionUnitChoices.UNIT_INCH,
                  mounting_depth=300,
                  weight=30,
                  max_weight=3000,
                  weight_unit=WeightUnitChoices.UNIT_KILOGRAM,
                  description='foobar3'
              ),
          )
          RackType.objects.bulk_create(racks)
  
      def test_q(self):
          params = {'q': 'foobar1'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
  
      def test_manufacturer(self):
          manufacturers = Manufacturer.objects.all()[:2]
          params = {'manufacturer_id': [manufacturers[0].pk, manufacturers[1].pk]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
          params = {'manufacturer': [manufacturers[0].slug, manufacturers[1].slug]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_model(self):
          params = {'model': ['RackType 1', 'RackType 2']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_slug(self):
          params = {'slug': ['rack-type-1', 'rack-type-2']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_description(self):
          params = {'description': ['foobar1', 'foobar2']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_form_factor(self):
          params = {'form_factor': [RackFormFactorChoices.TYPE_2POST, RackFormFactorChoices.TYPE_4POST]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_width(self):
          params = {'width': [RackWidthChoices.WIDTH_19IN, RackWidthChoices.WIDTH_21IN]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_u_height(self):
          params = {'u_height': [42, 43]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_starting_unit(self):
          params = {'starting_unit': [1, 2]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_desc_units(self):
          params = {'desc_units': 'true'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
          params = {'desc_units': 'false'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_outer_width(self):
          params = {'outer_width': [100, 200]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_outer_height(self):
          params = {'outer_height': [100, 200]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_outer_depth(self):
          params = {'outer_depth': [100, 200]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_outer_unit(self):
          self.assertEqual(RackType.objects.filter(outer_unit__isnull=False).count(), 3)
          params = {'outer_unit': RackDimensionUnitChoices.UNIT_MILLIMETER}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_mounting_depth(self):
          params = {'mounting_depth': [100, 200]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_weight(self):
          params = {'weight': [10, 20]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_max_weight(self):
          params = {'max_weight': [1000, 2000]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_weight_unit(self):
          params = {'weight_unit': WeightUnitChoices.UNIT_POUND}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
  
  class RackTestCase(TestCase, ChangeLoggedFilterSetTests):
      queryset = Rack.objects.all()
      filterset = RackFilterSet
      ignore_fields = ('units',)
  
      @classmethod
      def setUpTestData(cls):
  
          regions = (
              Region(name='Region 1', slug='region-1'),
              Region(name='Region 2', slug='region-2'),
              Region(name='Region 3', slug='region-3'),
          )
          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'),
              SiteGroup(name='Site Group 3', slug='site-group-3'),
          )
          for group in groups:
              group.save()
  
          sites = (
              Site(name='Site 1', slug='site-1', region=regions[0], group=groups[0]),
              Site(name='Site 2', slug='site-2', region=regions[1], group=groups[1]),
              Site(name='Site 3', slug='site-3', region=regions[2], group=groups[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]),
              Location(name='Location 3', slug='location-3', site=sites[2]),
          )
          for location in locations:
              location.save()
  
          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)
  
          rack_types = (
              RackType(
                  manufacturer=manufacturers[0],
                  model='RackType 1',
                  slug='rack-type-1',
                  form_factor=RackFormFactorChoices.TYPE_2POST,
                  width=RackWidthChoices.WIDTH_19IN,
                  u_height=42,
                  starting_unit=1,
                  desc_units=False,
                  outer_width=100,
                  outer_height=100,
                  outer_depth=100,
                  outer_unit=RackDimensionUnitChoices.UNIT_MILLIMETER,
                  mounting_depth=100,
                  weight=10,
                  max_weight=1000,
                  weight_unit=WeightUnitChoices.UNIT_POUND,
                  description='foobar1'
              ),
              RackType(
                  manufacturer=manufacturers[1],
                  model='RackType 2',
                  slug='rack-type-2',
                  form_factor=RackFormFactorChoices.TYPE_4POST,
                  width=RackWidthChoices.WIDTH_21IN,
                  u_height=43,
                  starting_unit=2,
                  desc_units=False,
                  outer_width=200,
                  outer_height=200,
                  outer_depth=200,
                  outer_unit=RackDimensionUnitChoices.UNIT_MILLIMETER,
                  mounting_depth=200,
  