mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-16 16:52:17 -06:00
@@ -1,4 +1,5 @@
|
||||
from django.urls import reverse
|
||||
from rest_framework import status
|
||||
|
||||
from dcim.choices import InterfaceTypeChoices
|
||||
from dcim.models import Interface
|
||||
@@ -527,19 +528,22 @@ class L2VPNTest(APIViewTestCases.APIViewTestCase):
|
||||
'name': 'L2VPN 4',
|
||||
'slug': 'l2vpn-4',
|
||||
'type': 'vxlan',
|
||||
'identifier': 33343344
|
||||
'identifier': 33343344,
|
||||
'status': L2VPNStatusChoices.STATUS_ACTIVE,
|
||||
},
|
||||
{
|
||||
'name': 'L2VPN 5',
|
||||
'slug': 'l2vpn-5',
|
||||
'type': 'vxlan',
|
||||
'identifier': 33343345
|
||||
'identifier': 33343345,
|
||||
'status': L2VPNStatusChoices.STATUS_PLANNED,
|
||||
},
|
||||
{
|
||||
'name': 'L2VPN 6',
|
||||
'slug': 'l2vpn-6',
|
||||
'type': 'vpws',
|
||||
'identifier': 33343346
|
||||
'identifier': 33343346,
|
||||
'status': L2VPNStatusChoices.STATUS_DECOMMISSIONING,
|
||||
},
|
||||
]
|
||||
bulk_update_data = {
|
||||
@@ -550,12 +554,53 @@ class L2VPNTest(APIViewTestCases.APIViewTestCase):
|
||||
def setUpTestData(cls):
|
||||
|
||||
l2vpns = (
|
||||
L2VPN(name='L2VPN 1', slug='l2vpn-1', type='vxlan', identifier=650001),
|
||||
L2VPN(name='L2VPN 2', slug='l2vpn-2', type='vpws', identifier=650002),
|
||||
L2VPN(name='L2VPN 3', slug='l2vpn-3', type='vpls'), # No RD
|
||||
L2VPN(
|
||||
name='L2VPN 1', slug='l2vpn-1', type='vxlan', identifier=650001,
|
||||
status=L2VPNStatusChoices.STATUS_ACTIVE,
|
||||
),
|
||||
L2VPN(
|
||||
name='L2VPN 2', slug='l2vpn-2', type='vpws', identifier=650002,
|
||||
status=L2VPNStatusChoices.STATUS_PLANNED,
|
||||
),
|
||||
L2VPN(
|
||||
name='L2VPN 3', slug='l2vpn-3', type='vpls',
|
||||
status=L2VPNStatusChoices.STATUS_DECOMMISSIONING,
|
||||
), # No RD
|
||||
)
|
||||
L2VPN.objects.bulk_create(l2vpns)
|
||||
|
||||
def test_status_filter(self):
|
||||
url = reverse('vpn-api:l2vpn-list')
|
||||
|
||||
self.add_permissions('vpn.view_l2vpn')
|
||||
response = self.client.get(url, **self.header)
|
||||
response_data = response.json()
|
||||
|
||||
# all L2VPNs present with not filter
|
||||
self.assertHttpStatus(response, status.HTTP_200_OK)
|
||||
self.assertEqual(response_data['count'], 3)
|
||||
|
||||
# 1 L2VPN present with active status filter
|
||||
filter_url = f'{url}?status={L2VPNStatusChoices.STATUS_ACTIVE}'
|
||||
response = self.client.get(filter_url, **self.header)
|
||||
response_data = response.json()
|
||||
self.assertHttpStatus(response, status.HTTP_200_OK)
|
||||
self.assertEqual(response_data['count'], 1)
|
||||
|
||||
# 2 L2VPNs present with active and planned status filter
|
||||
filter_url = f'{filter_url}&status={L2VPNStatusChoices.STATUS_PLANNED}'
|
||||
response = self.client.get(filter_url, **self.header)
|
||||
response_data = response.json()
|
||||
self.assertHttpStatus(response, status.HTTP_200_OK)
|
||||
self.assertEqual(response_data['count'], 2)
|
||||
|
||||
# 1 L2VPN present with decommissioning status filter
|
||||
filter_url = f'{url}?status={L2VPNStatusChoices.STATUS_DECOMMISSIONING}'
|
||||
response = self.client.get(filter_url, **self.header)
|
||||
response_data = response.json()
|
||||
self.assertHttpStatus(response, status.HTTP_200_OK)
|
||||
self.assertEqual(response_data['count'], 1)
|
||||
|
||||
|
||||
class L2VPNTerminationTest(APIViewTestCases.APIViewTestCase):
|
||||
model = L2VPNTermination
|
||||
|
||||
@@ -769,6 +769,7 @@ class L2VPNTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
name='L2VPN 1',
|
||||
slug='l2vpn-1',
|
||||
type=L2VPNTypeChoices.TYPE_VXLAN,
|
||||
status=L2VPNStatusChoices.STATUS_ACTIVE,
|
||||
identifier=65001,
|
||||
description='foobar1'
|
||||
),
|
||||
@@ -776,6 +777,7 @@ class L2VPNTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
name='L2VPN 2',
|
||||
slug='l2vpn-2',
|
||||
type=L2VPNTypeChoices.TYPE_VPWS,
|
||||
status=L2VPNStatusChoices.STATUS_PLANNED,
|
||||
identifier=65002,
|
||||
description='foobar2'
|
||||
),
|
||||
@@ -783,6 +785,7 @@ class L2VPNTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
name='L2VPN 3',
|
||||
slug='l2vpn-3',
|
||||
type=L2VPNTypeChoices.TYPE_VPLS,
|
||||
status=L2VPNStatusChoices.STATUS_DECOMMISSIONING,
|
||||
description='foobar3'
|
||||
),
|
||||
)
|
||||
@@ -814,6 +817,15 @@ class L2VPNTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
params = {'type': [L2VPNTypeChoices.TYPE_VXLAN, L2VPNTypeChoices.TYPE_VPWS]}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_status(self):
|
||||
self.assertEqual(self.filterset({}, self.queryset).qs.count(), 3)
|
||||
|
||||
params = {'status': [L2VPNStatusChoices.STATUS_ACTIVE, L2VPNStatusChoices.STATUS_PLANNED]}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
params = {'status': [L2VPNStatusChoices.STATUS_DECOMMISSIONING]}
|
||||
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)
|
||||
|
||||
@@ -574,16 +574,25 @@ class L2VPNTestCase(ViewTestCases.PrimaryObjectViewTestCase):
|
||||
RouteTarget.objects.bulk_create(rts)
|
||||
|
||||
l2vpns = (
|
||||
L2VPN(name='L2VPN 1', slug='l2vpn-1', type=L2VPNTypeChoices.TYPE_VXLAN, identifier='650001'),
|
||||
L2VPN(name='L2VPN 2', slug='l2vpn-2', type=L2VPNTypeChoices.TYPE_VXLAN, identifier='650002'),
|
||||
L2VPN(name='L2VPN 3', slug='l2vpn-3', type=L2VPNTypeChoices.TYPE_VXLAN, identifier='650003')
|
||||
L2VPN(
|
||||
name='L2VPN 1', slug='l2vpn-1', status=L2VPNStatusChoices.STATUS_ACTIVE,
|
||||
type=L2VPNTypeChoices.TYPE_VXLAN, identifier='650001'
|
||||
),
|
||||
L2VPN(
|
||||
name='L2VPN 2', slug='l2vpn-2', status=L2VPNStatusChoices.STATUS_DECOMMISSIONING,
|
||||
type=L2VPNTypeChoices.TYPE_VXLAN, identifier='650002'
|
||||
),
|
||||
L2VPN(
|
||||
name='L2VPN 3', slug='l2vpn-3', status=L2VPNStatusChoices.STATUS_PLANNED,
|
||||
type=L2VPNTypeChoices.TYPE_VXLAN, identifier='650003'
|
||||
)
|
||||
)
|
||||
L2VPN.objects.bulk_create(l2vpns)
|
||||
|
||||
cls.csv_data = (
|
||||
'name,slug,type,identifier',
|
||||
'L2VPN 5,l2vpn-5,vxlan,456',
|
||||
'L2VPN 6,l2vpn-6,vxlan,444',
|
||||
'name,status,slug,type,identifier',
|
||||
'L2VPN 5,active,l2vpn-5,vxlan,456',
|
||||
'L2VPN 6,planned,l2vpn-6,vxlan,444',
|
||||
)
|
||||
|
||||
cls.csv_update_data = (
|
||||
@@ -594,12 +603,14 @@ class L2VPNTestCase(ViewTestCases.PrimaryObjectViewTestCase):
|
||||
|
||||
cls.bulk_edit_data = {
|
||||
'description': 'New Description',
|
||||
'status': L2VPNStatusChoices.STATUS_DECOMMISSIONING,
|
||||
}
|
||||
|
||||
cls.form_data = {
|
||||
'name': 'L2VPN 8',
|
||||
'slug': 'l2vpn-8',
|
||||
'type': L2VPNTypeChoices.TYPE_VXLAN,
|
||||
'status': L2VPNStatusChoices.STATUS_PLANNED,
|
||||
'identifier': 123,
|
||||
'description': 'Description',
|
||||
'import_targets': [rts[0].pk],
|
||||
|
||||
Reference in New Issue
Block a user