content: from django.contrib.contenttypes.models import ContentType
  from django.db.backends.postgresql.psycopg_any import NumericRange
  from django.test import TestCase
  from netaddr import IPNetwork
  
  from circuits.models import Provider
  from dcim.choices import InterfaceTypeChoices
  from dcim.models import Device, DeviceRole, DeviceType, Interface, Location, Manufacturer, Rack, Region, Site, SiteGroup
  from ipam.choices import *
  from ipam.filtersets import *
  from ipam.models import *
  from tenancy.models import Tenant, TenantGroup
  from utilities.testing import ChangeLoggedFilterSetTests, create_test_device, create_test_virtualmachine
  from virtualization.models import Cluster, ClusterGroup, ClusterType, VirtualMachine, VMInterface
  from vpn.choices import L2VPNTypeChoices
  from vpn.models import L2VPN
  
  
  class ASNRangeTestCase(TestCase, ChangeLoggedFilterSetTests):
      queryset = ASNRange.objects.all()
      filterset = ASNRangeFilterSet
  
      @classmethod
      def setUpTestData(cls):
          rirs = [
              RIR(name='RIR 1', slug='rir-1'),
              RIR(name='RIR 2', slug='rir-2'),
              RIR(name='RIR 3', slug='rir-3'),
          ]
          RIR.objects.bulk_create(rirs)
  
          tenants = [
              Tenant(name='Tenant 1', slug='tenant-1'),
              Tenant(name='Tenant 2', slug='tenant-2'),
          ]
          Tenant.objects.bulk_create(tenants)
  
          asn_ranges = (
              ASNRange(
                  name='ASN Range 1',
                  slug='asn-range-1',
                  rir=rirs[0],
                  tenant=None,
                  start=65000,
                  end=65009,
                  description='foobar1'
              ),
              ASNRange(
                  name='ASN Range 2',
                  slug='asn-range-2',
                  rir=rirs[1],
                  tenant=tenants[0],
                  start=65010,
                  end=65019,
                  description='foobar2'
              ),
              ASNRange(
                  name='ASN Range 3',
                  slug='asn-range-3',
                  rir=rirs[2],
                  tenant=tenants[1],
                  start=65020,
                  end=65029,
                  description='foobar3'
              ),
          )
          ASNRange.objects.bulk_create(asn_ranges)
  
      def test_q(self):
          params = {'q': 'foobar1'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
  
      def test_name(self):
          params = {'name': ['ASN Range 1', 'ASN Range 2']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_rir(self):
          rirs = RIR.objects.all()[:2]
          params = {'rir_id': [rirs[0].pk, rirs[1].pk]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
          params = {'rir': [rirs[0].slug, rirs[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_start(self):
          params = {'start': [65000, 65010]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_end(self):
          params = {'end': [65009, 65019]}
          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 ASNTestCase(TestCase, ChangeLoggedFilterSetTests):
      queryset = ASN.objects.all()
      filterset = ASNFilterSet
  
      @classmethod
      def setUpTestData(cls):
          rirs = [
              RIR(name='RIR 1', slug='rir-1', is_private=True),
              RIR(name='RIR 2', slug='rir-2', is_private=True),
              RIR(name='RIR 3', slug='rir-3', is_private=True),
          ]
          RIR.objects.bulk_create(rirs)
  
          tenants = [
              Tenant(name='Tenant 1', slug='tenant-1'),
              Tenant(name='Tenant 2', slug='tenant-2'),
              Tenant(name='Tenant 3', slug='tenant-3'),
              Tenant(name='Tenant 4', slug='tenant-4'),
              Tenant(name='Tenant 5', slug='tenant-5'),
          ]
          Tenant.objects.bulk_create(tenants)
  
          asns = (
              ASN(asn=65001, rir=rirs[0], tenant=tenants[0], description='foobar1'),
              ASN(asn=65002, rir=rirs[1], tenant=tenants[1], description='foobar2'),
              ASN(asn=65003, rir=rirs[2], tenant=tenants[2], description='foobar3'),
              ASN(asn=4200000000, rir=rirs[0], tenant=tenants[0]),
              ASN(asn=4200000001, rir=rirs[1], tenant=tenants[1]),
              ASN(asn=4200000002, rir=rirs[2], tenant=tenants[2]),
          )
          ASN.objects.bulk_create(asns)
  
          site_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 site_group in site_groups:
              site_group.save()
  
          sites = [
              Site(name='Site 1', slug='site-1', group=site_groups[0]),
              Site(name='Site 2', slug='site-2', group=site_groups[1]),
              Site(name='Site 3', slug='site-3', group=site_groups[2]),
          ]
          Site.objects.bulk_create(sites)
          asns[0].sites.set([sites[0]])
          asns[1].sites.set([sites[1]])
          asns[2].sites.set([sites[2]])
          asns[3].sites.set([sites[0]])
          asns[4].sites.set([sites[1]])
          asns[5].sites.set([sites[2]])
  
          providers = (
              Provider(name='Provider 1', slug='provider-1'),
              Provider(name='Provider 2', slug='provider-2'),
              Provider(name='Provider 3', slug='provider-3'),
          )
          Provider.objects.bulk_create(providers)
          providers[0].asns.add(asns[0])
          providers[1].asns.add(asns[1])
          providers[2].asns.add(asns[2])
  
      def test_q(self):
          params = {'q': 'foobar1'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
  
      def test_asn(self):
          params = {'asn': [65001, 4200000000]}
          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(), 4)
          params = {'tenant': [tenants[0].slug, tenants[1].slug]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
  
      def test_rir(self):
          rirs = RIR.objects.all()[:2]
          params = {'rir_id': [rirs[0].pk, rirs[1].pk]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
          params = {'rir': [rirs[0].slug, rirs[1].slug]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
  
      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(), 4)
          params = {'site_group': [site_groups[0].slug, site_groups[1].slug]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
  
      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(), 4)
          params = {'site': [sites[0].slug, sites[1].slug]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
  
      def test_description(self):
          params = {'description': ['foobar1', 'foobar2']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_provider(self):
          providers = Provider.objects.all()[:2]
          params = {'provider_id': [providers[0].pk, providers[1].pk]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
  
  class VRFTestCase(TestCase, ChangeLoggedFilterSetTests):
      queryset = VRF.objects.all()
      filterset = VRFFilterSet
  
      def get_m2m_filter_name(self, field):
          # Override filter names for import & export RouteTargets
          if field.name == 'import_targets':
              return 'import_target'
          if field.name == 'export_targets':
              return 'export_target'
          return ChangeLoggedFilterSetTests.get_m2m_filter_name(field)
  
      @classmethod
      def setUpTestData(cls):
  
          route_targets = (
              RouteTarget(name='65000:1001'),
              RouteTarget(name='65000:1002'),
              RouteTarget(name='65000:1003'),
          )
          RouteTarget.objects.bulk_create(route_targets)
  
          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)
  
          vrfs = (
              VRF(name='VRF 1', rd='65000:100', tenant=tenants[0], enforce_unique=False, description='foobar1'),
              VRF(name='VRF 2', rd='65000:200', tenant=tenants[0], enforce_unique=False, description='foobar2'),
              VRF(name='VRF 3', rd='65000:300', tenant=tenants[1], enforce_unique=False),
              VRF(name='VRF 4', rd='65000:400', tenant=tenants[1], enforce_unique=True),
              VRF(name='VRF 5', rd='65000:500', tenant=tenants[2], enforce_unique=True),
              VRF(name='VRF 6', rd='65000:600', tenant=tenants[2], enforce_unique=True),
          )
          VRF.objects.bulk_create(vrfs)
          vrfs[0].import_targets.add(route_targets[0])
          vrfs[0].export_targets.add(route_targets[0])
          vrfs[1].import_targets.add(route_targets[1])
          vrfs[1].export_targets.add(route_targets[1])
          vrfs[2].import_targets.add(route_targets[2])
          vrfs[2].export_targets.add(route_targets[2])
  
      def test_q(self):
          params = {'q': 'foobar1'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
  
      def test_name(self):
          params = {'name': ['VRF 1', 'VRF 2']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_rd(self):
          params = {'rd': ['65000:100', '65000:200']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_enforce_unique(self):
          params = {'enforce_unique': 'true'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 3)
          params = {'enforce_unique': 'false'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 3)
  
      def test_import_target(self):
          route_targets = RouteTarget.objects.all()[:2]
          params = {'import_target_id': [route_targets[0].pk, route_targets[1].pk]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
          params = {'import_target': [route_targets[0].name, route_targets[1].name]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_export_target(self):
          route_targets = RouteTarget.objects.all()[:2]
          params = {'export_target_id': [route_targets[0].pk, route_targets[1].pk]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
          params = {'export_target': [route_targets[0].name, route_targets[1].name]}
          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(), 4)
          params = {'tenant': [tenants[0].slug, tenants[1].slug]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
  
      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(), 4)
          params = {'tenant_group': [tenant_groups[0].slug, tenant_groups[1].slug]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
  
      def test_description(self):
          params = {'description': ['foobar1', 'foobar2']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
  
  class RouteTargetTestCase(TestCase, ChangeLoggedFilterSetTests):
      queryset = RouteTarget.objects.all()
      filterset = RouteTargetFilterSet
  
      def get_m2m_filter_name(self, field):
          # Override filter names for import & export VRFs and L2VPNs
          if field.name == 'importing_vrfs':
              return 'importing_vrf'
          if field.name == 'exporting_vrfs':
              return 'exporting_vrf'
          if field.name == 'importing_l2vpns':
              return 'importing_l2vpn'
          if field.name == 'exporting_l2vpns':
              return 'exporting_l2vpn'
          return ChangeLoggedFilterSetTests.get_m2m_filter_name(field)
  
      @classmethod
      def setUpTestData(cls):
  
          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)
  
          route_targets = (
              RouteTarget(name='65000:1001', tenant=tenants[0], description='foobar1'),
              RouteTarget(name='65000:1002', tenant=tenants[0], description='foobar2'),
              RouteTarget(name='65000:1003', tenant=tenants[0]),
              RouteTarget(name='65000:1004', tenant=tenants[0]),
              RouteTarget(name='65000:2001', tenant=tenants[1]),
              RouteTarget(name='65000:2002', tenant=tenants[1]),
              RouteTarget(name='65000:2003', tenant=tenants[1]),
              RouteTarget(name='65000:2004', tenant=tenants[1]),
              RouteTarget(name='65000:3001', tenant=tenants[2]),
              RouteTarget(name='65000:3002', tenant=tenants[2]),
              RouteTarget(name='65000:3003', tenant=tenants[2]),
              RouteTarget(name='65000:3004', tenant=tenants[2]),
          )
          RouteTarget.objects.bulk_create(route_targets)
  
          vrfs = (
              VRF(name='VRF 1', rd='65000:100'),
              VRF(name='VRF 2', rd='65000:200'),
              VRF(name='VRF 3', rd='65000:300'),
          )
          VRF.objects.bulk_create(vrfs)
          vrfs[0].import_targets.add(route_targets[0], route_targets[1])
          vrfs[0].export_targets.add(route_targets[2], route_targets[3])
          vrfs[1].import_targets.add(route_targets[4], route_targets[5])
          vrfs[1].export_targets.add(route_targets[6], route_targets[7])
  
          l2vpns = (
              L2VPN(name='L2VPN 1', slug='l2vpn-1', type=L2VPNTypeChoices.TYPE_VXLAN, identifier=100),
              L2VPN(name='L2VPN 2', slug='l2vpn-2', type=L2VPNTypeChoices.TYPE_VXLAN, identifier=200),
              L2VPN(name='L2VPN 3', slug='l2vpn-3', type=L2VPNTypeChoices.TYPE_VXLAN, identifier=300),
          )
          L2VPN.objects.bulk_create(l2vpns)
          l2vpns[0].import_targets.add(route_targets[0], route_targets[1])
          l2vpns[0].export_targets.add(route_targets[2], route_targets[3])
          l2vpns[1].import_targets.add(route_targets[4], route_targets[5])
          l2vpns[1].export_targets.add(route_targets[6], route_targets[7])
  
      def test_q(self):
          params = {'q': 'foobar1'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
  
      def test_name(self):
          params = {'name': ['65000:1001', '65000:1002', '65000:1003']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 3)
  
      def test_importing_vrf(self):
          vrfs = VRF.objects.all()[:2]
          params = {'importing_vrf_id': [vrfs[0].pk, vrfs[1].pk]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
          params = {'importing_vrf': [vrfs[0].rd, vrfs[1].rd]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
  
      def test_exporting_vrf(self):
          vrfs = VRF.objects.all()[:2]
          params = {'exporting_vrf_id': [vrfs[0].pk, vrfs[1].pk]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
          params = {'exporting_vrf': [vrfs[0].rd, vrfs[1].rd]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
  
      def test_importing_l2vpn(self):
          l2vpns = L2VPN.objects.all()[:2]
          params = {'importing_l2vpn_id': [l2vpns[0].pk, l2vpns[1].pk]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
          params = {'importing_l2vpn': [l2vpns[0].identifier, l2vpns[1].identifier]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
  
      def test_exporting_l2vpn(self):
          l2vpns = L2VPN.objects.all()[:2]
          params = {'exporting_l2vpn_id': [l2vpns[0].pk, l2vpns[1].pk]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
          params = {'exporting_l2vpn': [l2vpns[0].identifier, l2vpns[1].identifier]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
  
      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(), 8)
          params = {'tenant': [tenants[0].slug, tenants[1].slug]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 8)
  
      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(), 8)
          params = {'tenant_group': [tenant_groups[0].slug, tenant_groups[1].slug]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 8)
  
      def test_description(self):
          params = {'description': ['foobar1', 'foobar2']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
  
  class RIRTestCase(TestCase, ChangeLoggedFilterSetTests):
      queryset = RIR.objects.all()
      filterset = RIRFilterSet
  
      @classmethod
      def setUpTestData(cls):
  
          rirs = (
              RIR(name='RIR 1', slug='rir-1', is_private=False, description='foobar1'),
              RIR(name='RIR 2', slug='rir-2', is_private=False, description='foobar2'),
              RIR(name='RIR 3', slug='rir-3', is_private=False, description='foobar3'),
              RIR(name='RIR 4', slug='rir-4', is_private=True),
              RIR(name='RIR 5', slug='rir-5', is_private=True),
              RIR(name='RIR 6', slug='rir-6', is_private=True),
          )
          RIR.objects.bulk_create(rirs)
  
      def test_q(self):
          params = {'q': 'foobar1'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
  
      def test_name(self):
          params = {'name': ['RIR 1', 'RIR 2']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_slug(self):
          params = {'slug': ['rir-1', 'rir-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_is_private(self):
          params = {'is_private': 'true'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 3)
          params = {'is_private': 'false'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 3)
  
  
  class AggregateTestCase(TestCase, ChangeLoggedFilterSetTests):
      queryset = Aggregate.objects.all()
      filterset = AggregateFilterSet
  
      @classmethod
      def setUpTestData(cls):
  
          rirs = (
              RIR(name='RIR 1', slug='rir-1'),
              RIR(name='RIR 2', slug='rir-2'),
              RIR(name='RIR 3', slug='rir-3'),
          )
          RIR.objects.bulk_create(rirs)
  
          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)
  
          aggregates = (
              Aggregate(
                  prefix='10.1.0.0/16', rir=rirs[0], tenant=tenants[0], date_added='2020-01-01', description='foobar1'
              ),
              Aggregate(
                  prefix='10.2.0.0/16', rir=rirs[0], tenant=tenants[1], date_added='2020-01-02', description='foobar2'
              ),
              Aggregate(prefix='10.3.0.0/16', rir=rirs[1], tenant=tenants[2], date_added='2020-01-03'),
              Aggregate(prefix='2001:db8:1::/48', rir=rirs[1], tenant=tenants[0], date_added='2020-01-04'),
              Aggregate(prefix='2001:db8:2::/48', rir=rirs[2], tenant=tenants[1], date_added='2020-01-05'),
              Aggregate(prefix='2001:db8:3::/48', rir=rirs[2], tenant=tenants[2], date_added='2020-01-06'),
          )
          Aggregate.objects.bulk_create(aggregates)
  
      def test_q(self):
          params = {'q': 'foobar1'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
  
      def test_family(self):
          params = {'family': '4'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 3)
  
      def test_date_added(self):
          params = {'date_added': ['2020-01-01', '2020-01-02']}
          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)
  
      # TODO: Test for multiple values
      def test_prefix(self):
          params = {'prefix': '10.1.0.0/16'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
  
      def test_rir(self):
          rirs = RIR.objects.all()[:2]
          params = {'rir_id': [rirs[0].pk, rirs[1].pk]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
          params = {'rir': [rirs[0].slug, rirs[1].slug]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
  
      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(), 4)
          params = {'tenant': [tenants[0].slug, tenants[1].slug]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
  
      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(), 4)
          params = {'tenant_group': [tenant_groups[0].slug, tenant_groups[1].slug]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
  
  
  class RoleTestCase(TestCase, ChangeLoggedFilterSetTests):
      queryset = Role.objects.all()
      filterset = RoleFilterSet
  
      @classmethod
      def setUpTestData(cls):
  
          roles = (
              Role(name='Role 1', slug='role-1', description='foobar1'),
              Role(name='Role 2', slug='role-2', description='foobar2'),
              Role(name='Role 3', slug='role-3'),
          )
          Role.objects.bulk_create(roles)
  
      def test_q(self):
          params = {'q': 'foobar1'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
  
      def test_name(self):
          params = {'name': ['Role 1', 'Role 2']}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_slug(self):
          params = {'slug': ['role-1', 'role-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)
  
  
  class PrefixTestCase(TestCase, ChangeLoggedFilterSetTests):
      queryset = Prefix.objects.all()
      filterset = PrefixFilterSet
  
      @classmethod
      def setUpTestData(cls):
  
          regions = (
              Region(name='Test Region 1', slug='test-region-1'),
              Region(name='Test Region 2', slug='test-region-2'),
              Region(name='Test Region 3', slug='test-region-3'),
          )
          for r in regions:
              r.save()
  
          site_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 site_group in site_groups:
              site_group.save()
  
          sites = (
              Site(name='Test Site 1', slug='test-site-1', region=regions[0], group=site_groups[0]),
              Site(name='Test Site 2', slug='test-site-2', region=regions[1], group=site_groups[1]),
              Site(name='Test Site 3', slug='test-site-3', region=regions[2], group=site_groups[2]),
          )
          Site.objects.bulk_create(sites)
  
          route_targets = (
              RouteTarget(name='65000:100'),
              RouteTarget(name='65000:200'),
              RouteTarget(name='65000:300'),
          )
          RouteTarget.objects.bulk_create(route_targets)
  
          vrfs = (
              VRF(name='VRF 1', rd='65000:100'),
              VRF(name='VRF 2', rd='65000:200'),
              VRF(name='VRF 3', rd='65000:300'),
          )
          VRF.objects.bulk_create(vrfs)
          vrfs[0].import_targets.add(route_targets[0], route_targets[1], route_targets[2])
          vrfs[1].export_targets.add(route_targets[1])
          vrfs[2].export_targets.add(route_targets[2])
  
          vlan_groups = (
              VLANGroup(name='VLAN Group 1', slug='vlan-group-1'),
              VLANGroup(name='VLAN Group 2', slug='vlan-group-2'),
          )
          for vlan_group in vlan_groups:
              vlan_group.save()
  
          vlans = (
              VLAN(vid=1, name='VLAN 1', group=vlan_groups[0]),
              VLAN(vid=2, name='VLAN 2', group=vlan_groups[1]),
              VLAN(vid=3, name='VLAN 3'),
          )
          VLAN.objects.bulk_create(vlans)
  
          roles = (
              Role(name='Role 1', slug='role-1'),
              Role(name='Role 2', slug='role-2'),
              Role(name='Role 3', slug='role-3'),
          )
          Role.objects.bulk_create(roles)
  
          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)
  
          prefixes = (
              Prefix(
                  prefix='10.0.0.0/24',
                  tenant=None,
                  scope=None,
                  vrf=None,
                  vlan=None,
                  role=None,
                  is_pool=True,
                  mark_utilized=True,
                  description='foobar1',
              ),
              Prefix(
                  prefix='10.0.1.0/24',
                  tenant=tenants[0],
                  scope=sites[0],
                  vrf=vrfs[0],
                  vlan=vlans[0],
                  role=roles[0],
                  description='foobar2',
              ),
              Prefix(
                  prefix='10.0.2.0/24',
                  tenant=tenants[1],
                  scope=sites[1],
                  vrf=vrfs[1],
                  vlan=vlans[1],
                  role=roles[1],
                  status=PrefixStatusChoices.STATUS_DEPRECATED,
              ),
              Prefix(
                  prefix='10.0.3.0/24',
                  tenant=tenants[2],
                  scope=sites[2],
                  vrf=vrfs[2],
                  vlan=vlans[2],
                  role=roles[2],
                  status=PrefixStatusChoices.STATUS_RESERVED,
              ),
              Prefix(
                  prefix='2001:db8::/64',
                  tenant=None,
                  scope=None,
                  vrf=None,
                  vlan=None,
                  role=None,
                  is_pool=True,
                  mark_utilized=True,
              ),
              Prefix(
                  prefix='2001:db8:0:1::/64',
                  tenant=tenants[0],
                  scope=sites[0],
                  vrf=vrfs[0],
                  vlan=vlans[0],
                  role=roles[0]
              ),
              Prefix(
                  prefix='2001:db8:0:2::/64',
                  tenant=tenants[1],
                  scope=sites[1],
                  vrf=vrfs[1],
                  vlan=vlans[1],
                  role=roles[1],
                  status=PrefixStatusChoices.STATUS_DEPRECATED,
              ),
              Prefix(
                  prefix='2001:db8:0:3::/64',
                  tenant=tenants[2],
                  scope=sites[2],
                  vrf=vrfs[2],
                  vlan=vlans[2],
                  role=roles[2],
                  status=PrefixStatusChoices.STATUS_RESERVED,
              ),
              Prefix(prefix='10.0.0.0/16'),
              Prefix(prefix='2001:db8::/32'),
          )
          for prefix in prefixes:
              prefix.save()
  
      def test_q(self):
          params = {'q': 'foobar1'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
  
      def test_family(self):
          params = {'family': '6'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 5)
  
      def test_prefix(self):
          prefixes = Prefix.objects.all()[:2]
          params = {'prefix': [prefixes[0].prefix, prefixes[1].prefix]}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_is_pool(self):
          params = {'is_pool': 'true'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
          params = {'is_pool': 'false'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 8)
  
      def test_mark_utilized(self):
          params = {'mark_utilized': 'true'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
          params = {'mark_utilized': 'false'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 8)
  
      def test_within(self):
          params = {'within': '10.0.0.0/16'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
  
      def test_within_include(self):
          params = {'within_include': '10.0.0.0/16'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 5)
  
      def test_contains(self):
          params = {'contains': '10.0.1.0/24'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
          params = {'contains': '2001:db8:0:1::/64'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
  
      def test_depth(self):
          params = {'depth': '0'}
          self.assertEqual(self.filterset(params, self.queryset).qs.count(), 8)
          params = {'depth__gt': '0'}
  