mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-23 04:22:01 -06:00
#6732 - Fix ASN tests
This commit is contained in:
parent
ada81e31c9
commit
3c261b05d9
@ -4,7 +4,7 @@ from django.test import TestCase
|
|||||||
from dcim.choices import *
|
from dcim.choices import *
|
||||||
from dcim.filtersets import *
|
from dcim.filtersets import *
|
||||||
from dcim.models import *
|
from dcim.models import *
|
||||||
from ipam.models import IPAddress
|
from ipam.models import IPAddress, RIR, ASN
|
||||||
from tenancy.models import Tenant, TenantGroup
|
from tenancy.models import Tenant, TenantGroup
|
||||||
from utilities.choices import ColorChoices
|
from utilities.choices import ColorChoices
|
||||||
from utilities.testing import ChangeLoggedFilterSetTests
|
from utilities.testing import ChangeLoggedFilterSetTests
|
||||||
@ -148,6 +148,23 @@ class SiteTestCase(TestCase, ChangeLoggedFilterSetTests):
|
|||||||
)
|
)
|
||||||
Site.objects.bulk_create(sites)
|
Site.objects.bulk_create(sites)
|
||||||
|
|
||||||
|
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(asn=65001, rir=rir, tenant=tenants[0]),
|
||||||
|
ASN(asn=65002, rir=rir, tenant=tenants[0])
|
||||||
|
)
|
||||||
|
ASN.objects.bulk_create(asns)
|
||||||
|
|
||||||
|
asns[0].sites.set([sites[0]])
|
||||||
|
asns[1].sites.set([sites[1]])
|
||||||
|
asns[2].sites.set([sites[2]])
|
||||||
|
asns[3].sites.set([sites[2]])
|
||||||
|
asns[4].sites.set([sites[1]])
|
||||||
|
|
||||||
def test_name(self):
|
def test_name(self):
|
||||||
params = {'name': ['Site 1', 'Site 2']}
|
params = {'name': ['Site 1', 'Site 2']}
|
||||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||||
|
@ -11,7 +11,7 @@ from netaddr import EUI
|
|||||||
from dcim.choices import *
|
from dcim.choices import *
|
||||||
from dcim.constants import *
|
from dcim.constants import *
|
||||||
from dcim.models import *
|
from dcim.models import *
|
||||||
from ipam.models import VLAN
|
from ipam.models import VLAN, ASN, RIR
|
||||||
from tenancy.models import Tenant
|
from tenancy.models import Tenant
|
||||||
from utilities.testing import ViewTestCases, create_tags, create_test_device
|
from utilities.testing import ViewTestCases, create_tags, create_test_device
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ class SiteTestCase(ViewTestCases.PrimaryObjectViewTestCase):
|
|||||||
for group in groups:
|
for group in groups:
|
||||||
group.save()
|
group.save()
|
||||||
|
|
||||||
Site.objects.bulk_create([
|
sites = Site.objects.bulk_create([
|
||||||
Site(name='Site 1', slug='site-1', region=regions[0], group=groups[1]),
|
Site(name='Site 1', slug='site-1', region=regions[0], group=groups[1]),
|
||||||
Site(name='Site 2', slug='site-2', region=regions[0], group=groups[1]),
|
Site(name='Site 2', slug='site-2', region=regions[0], group=groups[1]),
|
||||||
Site(name='Site 3', slug='site-3', region=regions[0], group=groups[1]),
|
Site(name='Site 3', slug='site-3', region=regions[0], group=groups[1]),
|
||||||
@ -112,6 +112,33 @@ class SiteTestCase(ViewTestCases.PrimaryObjectViewTestCase):
|
|||||||
|
|
||||||
tags = create_tags('Alpha', 'Bravo', 'Charlie')
|
tags = create_tags('Alpha', 'Bravo', 'Charlie')
|
||||||
|
|
||||||
|
rir = RIR.objects.create(name='RFC 6996', is_private=True)
|
||||||
|
|
||||||
|
asns = [
|
||||||
|
ASN(asn=65000, rir=rir),
|
||||||
|
ASN(asn=65001, rir=rir),
|
||||||
|
ASN(asn=65002, rir=rir),
|
||||||
|
ASN(asn=65003, rir=rir),
|
||||||
|
ASN(asn=65004, rir=rir),
|
||||||
|
ASN(asn=65005, rir=rir),
|
||||||
|
ASN(asn=65006, rir=rir),
|
||||||
|
ASN(asn=65007, rir=rir),
|
||||||
|
ASN(asn=65008, rir=rir),
|
||||||
|
ASN(asn=65009, rir=rir),
|
||||||
|
ASN(asn=65010, rir=rir),
|
||||||
|
]
|
||||||
|
ASN.objects.bulk_create(asns)
|
||||||
|
|
||||||
|
asns[0].sites.set([sites[0]])
|
||||||
|
asns[2].sites.set([sites[0]])
|
||||||
|
asns[3].sites.set([sites[1]])
|
||||||
|
asns[4].sites.set([sites[2]])
|
||||||
|
asns[5].sites.set([sites[1]])
|
||||||
|
asns[6].sites.set([sites[2]])
|
||||||
|
asns[7].sites.set([sites[2]])
|
||||||
|
asns[8].sites.set([sites[2]])
|
||||||
|
asns[10].sites.set([sites[0]])
|
||||||
|
|
||||||
cls.form_data = {
|
cls.form_data = {
|
||||||
'name': 'Site X',
|
'name': 'Site X',
|
||||||
'slug': 'site-x',
|
'slug': 'site-x',
|
||||||
@ -120,7 +147,6 @@ class SiteTestCase(ViewTestCases.PrimaryObjectViewTestCase):
|
|||||||
'group': groups[1].pk,
|
'group': groups[1].pk,
|
||||||
'tenant': None,
|
'tenant': None,
|
||||||
'facility': 'Facility X',
|
'facility': 'Facility X',
|
||||||
'asn': 65001,
|
|
||||||
'time_zone': pytz.UTC,
|
'time_zone': pytz.UTC,
|
||||||
'description': 'Site description',
|
'description': 'Site description',
|
||||||
'physical_address': '742 Evergreen Terrace, Springfield, USA',
|
'physical_address': '742 Evergreen Terrace, Springfield, USA',
|
||||||
@ -146,7 +172,6 @@ class SiteTestCase(ViewTestCases.PrimaryObjectViewTestCase):
|
|||||||
'region': regions[1].pk,
|
'region': regions[1].pk,
|
||||||
'group': groups[1].pk,
|
'group': groups[1].pk,
|
||||||
'tenant': None,
|
'tenant': None,
|
||||||
'asn': 65009,
|
|
||||||
'time_zone': pytz.timezone('US/Eastern'),
|
'time_zone': pytz.timezone('US/Eastern'),
|
||||||
'description': 'New description',
|
'description': 'New description',
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ class AppTest(APITestCase):
|
|||||||
|
|
||||||
class ASNTest(APIViewTestCases.APIViewTestCase):
|
class ASNTest(APIViewTestCases.APIViewTestCase):
|
||||||
model = ASN
|
model = ASN
|
||||||
brief_fields = ['display', 'id', 'name', 'prefix_count', 'rd', 'url']
|
brief_fields = ['asn', 'display', 'id', 'url']
|
||||||
bulk_update_data = {
|
bulk_update_data = {
|
||||||
'description': 'New description',
|
'description': 'New description',
|
||||||
}
|
}
|
||||||
|
@ -34,29 +34,31 @@ class ASNTestCase(TestCase, ChangeLoggedFilterSetTests):
|
|||||||
]
|
]
|
||||||
|
|
||||||
asns = (
|
asns = (
|
||||||
|
ASN(asn=64512, rir=rirs[0], tenant=tenants[0]),
|
||||||
ASN(asn=64513, rir=rirs[0], tenant=tenants[0]),
|
ASN(asn=64513, rir=rirs[0], tenant=tenants[0]),
|
||||||
ASN(asn=64514, rir=rirs[0], tenant=tenants[1]),
|
ASN(asn=64514, rir=rirs[0], tenant=tenants[1]),
|
||||||
ASN(asn=64515, rir=rirs[0], tenant=tenants[2]),
|
ASN(asn=64515, rir=rirs[0], tenant=tenants[2]),
|
||||||
ASN(asn=64516, rir=rirs[0], tenant=tenants[3]),
|
ASN(asn=64516, rir=rirs[0], tenant=tenants[3]),
|
||||||
ASN(asn=65535, rir=rirs[1], tenant=tenants[5]),
|
ASN(asn=65535, rir=rirs[1], tenant=tenants[4]),
|
||||||
ASN(asn=4200000000, rir=rirs[0], tenant=tenants[0]),
|
ASN(asn=4200000000, rir=rirs[0], tenant=tenants[0]),
|
||||||
ASN(asn=4200000001, rir=rirs[0], tenant=tenants[1]),
|
ASN(asn=4200000001, rir=rirs[0], tenant=tenants[1]),
|
||||||
ASN(asn=4200000002, rir=rirs[0], tenant=tenants[2]),
|
ASN(asn=4200000002, rir=rirs[0], tenant=tenants[2]),
|
||||||
ASN(asn=4200000003, rir=rirs[0], tenant=tenants[3]),
|
ASN(asn=4200000003, rir=rirs[0], tenant=tenants[3]),
|
||||||
ASN(asn=4200002301, rir=rirs[1], tenant=tenants[5]),
|
ASN(asn=4200002301, rir=rirs[1], tenant=tenants[4]),
|
||||||
)
|
)
|
||||||
ASN.objects.bulk_create(asns)
|
ASN.objects.bulk_create(asns)
|
||||||
|
|
||||||
asns[0].sites.set([sites[0]])
|
asns[0].sites.set([sites[0]])
|
||||||
asns[1].sites.set([sites[1]])
|
asns[1].sites.set([sites[0]])
|
||||||
asns[2].sites.set([sites[2]])
|
asns[2].sites.set([sites[1]])
|
||||||
asns[3].sites.set([sites[0]])
|
asns[3].sites.set([sites[2]])
|
||||||
asns[4].sites.set([sites[1]])
|
asns[4].sites.set([sites[0]])
|
||||||
asns[5].sites.set([sites[0]])
|
asns[5].sites.set([sites[1]])
|
||||||
asns[6].sites.set([sites[1]])
|
asns[6].sites.set([sites[0]])
|
||||||
asns[7].sites.set([sites[2]])
|
asns[7].sites.set([sites[1]])
|
||||||
asns[8].sites.set([sites[0]])
|
asns[8].sites.set([sites[2]])
|
||||||
asns[9].sites.set([sites[1]])
|
asns[9].sites.set([sites[0]])
|
||||||
|
asns[10].sites.set([sites[1]])
|
||||||
|
|
||||||
def test_asn(self):
|
def test_asn(self):
|
||||||
params = {'asn': ['64512', '65535']}
|
params = {'asn': ['64512', '65535']}
|
||||||
@ -65,23 +67,23 @@ class ASNTestCase(TestCase, ChangeLoggedFilterSetTests):
|
|||||||
def test_tenant(self):
|
def test_tenant(self):
|
||||||
tenants = Tenant.objects.all()[:2]
|
tenants = Tenant.objects.all()[:2]
|
||||||
params = {'tenant_id': [tenants[0].pk, tenants[1].pk]}
|
params = {'tenant_id': [tenants[0].pk, tenants[1].pk]}
|
||||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 5)
|
||||||
params = {'tenant': [tenants[0].slug, tenants[1].slug]}
|
params = {'tenant': [tenants[0].slug, tenants[1].slug]}
|
||||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 5)
|
||||||
|
|
||||||
def test_rir(self):
|
def test_rir(self):
|
||||||
rirs = RIR.objects.all()[:1]
|
rirs = RIR.objects.all()[:1]
|
||||||
params = {'rir_id': [rirs[0].pk, rirs[1].pk]}
|
params = {'rir_id': [rirs[0].pk]}
|
||||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 9)
|
||||||
params = {'rir': [rirs[0].slug, rirs[1].slug]}
|
params = {'rir': [rirs[0].slug]}
|
||||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 9)
|
||||||
|
|
||||||
def test_site(self):
|
def test_site(self):
|
||||||
sites = Site.objects.all()[:2]
|
sites = Site.objects.all()[:2]
|
||||||
params = {'site_id': [sites[0].pk, sites[1].pk]}
|
params = {'site_id': [sites[0].pk, sites[1].pk]}
|
||||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 8)
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 9)
|
||||||
params = {'site': [sites[0].slug, sites[1].slug]}
|
params = {'site': [sites[0].slug, sites[1].slug]}
|
||||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 8)
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 9)
|
||||||
|
|
||||||
|
|
||||||
class VRFTestCase(TestCase, ChangeLoggedFilterSetTests):
|
class VRFTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||||
|
@ -46,8 +46,8 @@ class ASNTestCase(ViewTestCases.PrimaryObjectViewTestCase):
|
|||||||
cls.form_data = {
|
cls.form_data = {
|
||||||
'asn': 64512,
|
'asn': 64512,
|
||||||
'rir': rirs[0].pk,
|
'rir': rirs[0].pk,
|
||||||
'tenant': tenants[0],
|
'tenant': tenants[0].pk,
|
||||||
'site': sites[0],
|
'site': sites[0].pk,
|
||||||
'description': 'A new ASN',
|
'description': 'A new ASN',
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ class ASNTestCase(ViewTestCases.PrimaryObjectViewTestCase):
|
|||||||
"asn,rir",
|
"asn,rir",
|
||||||
"64533,RFC 6996",
|
"64533,RFC 6996",
|
||||||
"64523,RFC 6996",
|
"64523,RFC 6996",
|
||||||
"64513,RFC 6996",
|
"4200000002,RFC 6996",
|
||||||
)
|
)
|
||||||
|
|
||||||
cls.bulk_edit_data = {
|
cls.bulk_edit_data = {
|
||||||
|
Loading…
Reference in New Issue
Block a user