#9816: Add TunnelGroup

This commit is contained in:
Jeremy Stretch
2023-12-04 15:44:52 -05:00
parent 9f1283f0fa
commit 8db1093fdc
26 changed files with 669 additions and 160 deletions

View File

@@ -17,6 +17,38 @@ class AppTest(APITestCase):
self.assertEqual(response.status_code, 200)
class TunnelGroupTest(APIViewTestCases.APIViewTestCase):
model = TunnelGroup
brief_fields = ['display', 'id', 'name', 'slug', 'tunnel_count', 'url']
create_data = (
{
'name': 'Tunnel Group 4',
'slug': 'tunnel-group-4',
},
{
'name': 'Tunnel Group 5',
'slug': 'tunnel-group-5',
},
{
'name': 'Tunnel Group 6',
'slug': 'tunnel-group-6',
},
)
bulk_update_data = {
'description': 'New description',
}
@classmethod
def setUpTestData(cls):
tunnel_groups = (
TunnelGroup(name='Tunnel Group 1', slug='tunnel-group-1'),
TunnelGroup(name='Tunnel Group 2', slug='tunnel-group-2'),
TunnelGroup(name='Tunnel Group 3', slug='tunnel-group-3'),
)
TunnelGroup.objects.bulk_create(tunnel_groups)
class TunnelTest(APIViewTestCases.APIViewTestCase):
model = Tunnel
brief_fields = ['display', 'id', 'name', 'url']
@@ -29,20 +61,29 @@ class TunnelTest(APIViewTestCases.APIViewTestCase):
@classmethod
def setUpTestData(cls):
tunnel_groups = (
TunnelGroup(name='Tunnel Group 1', slug='tunnel-group-1'),
TunnelGroup(name='Tunnel Group 2', slug='tunnel-group-2'),
)
TunnelGroup.objects.bulk_create(tunnel_groups)
tunnels = (
Tunnel(
name='Tunnel 1',
status=TunnelStatusChoices.STATUS_ACTIVE,
group=tunnel_groups[0],
encapsulation=TunnelEncapsulationChoices.ENCAP_IP_IP
),
Tunnel(
name='Tunnel 2',
status=TunnelStatusChoices.STATUS_ACTIVE,
group=tunnel_groups[0],
encapsulation=TunnelEncapsulationChoices.ENCAP_IP_IP
),
Tunnel(
name='Tunnel 3',
status=TunnelStatusChoices.STATUS_ACTIVE,
group=tunnel_groups[0],
encapsulation=TunnelEncapsulationChoices.ENCAP_IP_IP
),
)
@@ -52,16 +93,19 @@ class TunnelTest(APIViewTestCases.APIViewTestCase):
{
'name': 'Tunnel 4',
'status': TunnelStatusChoices.STATUS_DISABLED,
'group': tunnel_groups[1].pk,
'encapsulation': TunnelEncapsulationChoices.ENCAP_GRE,
},
{
'name': 'Tunnel 5',
'status': TunnelStatusChoices.STATUS_DISABLED,
'group': tunnel_groups[1].pk,
'encapsulation': TunnelEncapsulationChoices.ENCAP_GRE,
},
{
'name': 'Tunnel 6',
'status': TunnelStatusChoices.STATUS_DISABLED,
'group': tunnel_groups[1].pk,
'encapsulation': TunnelEncapsulationChoices.ENCAP_GRE,
},
]

View File

@@ -11,6 +11,32 @@ from vpn.filtersets import *
from vpn.models import *
class TunnelGroupTestCase(TestCase, ChangeLoggedFilterSetTests):
queryset = TunnelGroup.objects.all()
filterset = TunnelGroupFilterSet
@classmethod
def setUpTestData(cls):
TunnelGroup.objects.bulk_create((
TunnelGroup(name='Tunnel Group 1', slug='tunnel-group-1', description='foobar1'),
TunnelGroup(name='Tunnel Group 2', slug='tunnel-group-2', description='foobar2'),
TunnelGroup(name='Tunnel Group 3', slug='tunnel-group-3'),
))
def test_name(self):
params = {'name': ['Tunnel Group 1']}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
def test_slug(self):
params = {'slug': ['tunnel-group-1']}
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)
class TunnelTestCase(TestCase, ChangeLoggedFilterSetTests):
queryset = Tunnel.objects.all()
filterset = TunnelFilterSet
@@ -56,10 +82,18 @@ class TunnelTestCase(TestCase, ChangeLoggedFilterSetTests):
)
IPSecProfile.objects.bulk_create(ipsec_profiles)
tunnel_groups = (
TunnelGroup(name='Tunnel Group 1', slug='tunnel-group-1'),
TunnelGroup(name='Tunnel Group 2', slug='tunnel-group-2'),
TunnelGroup(name='Tunnel Group 3', slug='tunnel-group-3'),
)
TunnelGroup.objects.bulk_create(tunnel_groups)
tunnels = (
Tunnel(
name='Tunnel 1',
status=TunnelStatusChoices.STATUS_ACTIVE,
group=tunnel_groups[0],
encapsulation=TunnelEncapsulationChoices.ENCAP_GRE,
ipsec_profile=ipsec_profiles[0],
tunnel_id=100
@@ -67,6 +101,7 @@ class TunnelTestCase(TestCase, ChangeLoggedFilterSetTests):
Tunnel(
name='Tunnel 2',
status=TunnelStatusChoices.STATUS_PLANNED,
group=tunnel_groups[1],
encapsulation=TunnelEncapsulationChoices.ENCAP_IP_IP,
ipsec_profile=ipsec_profiles[0],
tunnel_id=200
@@ -74,6 +109,7 @@ class TunnelTestCase(TestCase, ChangeLoggedFilterSetTests):
Tunnel(
name='Tunnel 3',
status=TunnelStatusChoices.STATUS_DISABLED,
group=tunnel_groups[2],
encapsulation=TunnelEncapsulationChoices.ENCAP_IPSEC_TUNNEL,
ipsec_profile=None,
tunnel_id=300
@@ -89,6 +125,13 @@ class TunnelTestCase(TestCase, ChangeLoggedFilterSetTests):
params = {'status': [TunnelStatusChoices.STATUS_ACTIVE, TunnelStatusChoices.STATUS_PLANNED]}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
def test_group(self):
tunnel_groups = TunnelGroup.objects.all()[:2]
params = {'group_id': [tunnel_groups[0].pk, tunnel_groups[1].pk]}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
params = {'group': [tunnel_groups[0].slug, tunnel_groups[1].slug]}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
def test_encapsulation(self):
params = {'encapsulation': [TunnelEncapsulationChoices.ENCAP_GRE, TunnelEncapsulationChoices.ENCAP_IP_IP]}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)

View File

@@ -6,26 +6,78 @@ from vpn.choices import *
from vpn.models import *
class TunnelGroupTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
model = TunnelGroup
@classmethod
def setUpTestData(cls):
tunnel_groups = (
TunnelGroup(name='Tunnel Group 1', slug='tunnel-group-1'),
TunnelGroup(name='Tunnel Group 2', slug='tunnel-group-2'),
TunnelGroup(name='Tunnel Group 3', slug='tunnel-group-3'),
)
TunnelGroup.objects.bulk_create(tunnel_groups)
tags = create_tags('Alpha', 'Bravo', 'Charlie')
cls.form_data = {
'name': 'Tunnel Group X',
'slug': 'tunnel-group-x',
'description': 'A new Tunnel Group',
'tags': [t.pk for t in tags],
}
cls.csv_data = (
"name,slug",
"Tunnel Group 4,tunnel-group-4",
"Tunnel Group 5,tunnel-group-5",
"Tunnel Group 6,tunnel-group-6",
)
cls.csv_update_data = (
"id,name,description",
f"{tunnel_groups[0].pk},Tunnel Group 7,New description7",
f"{tunnel_groups[1].pk},Tunnel Group 8,New description8",
f"{tunnel_groups[2].pk},Tunnel Group 9,New description9",
)
cls.bulk_edit_data = {
'description': 'Foo',
}
class TunnelTestCase(ViewTestCases.PrimaryObjectViewTestCase):
model = Tunnel
@classmethod
def setUpTestData(cls):
tunnel_groups = (
TunnelGroup(name='Tunnel Group 1', slug='tunnel-group-1'),
TunnelGroup(name='Tunnel Group 2', slug='tunnel-group-2'),
TunnelGroup(name='Tunnel Group 3', slug='tunnel-group-3'),
TunnelGroup(name='Tunnel Group 4', slug='tunnel-group-4'),
)
TunnelGroup.objects.bulk_create(tunnel_groups)
tunnels = (
Tunnel(
name='Tunnel 1',
status=TunnelStatusChoices.STATUS_ACTIVE,
group=tunnel_groups[0],
encapsulation=TunnelEncapsulationChoices.ENCAP_IP_IP
),
Tunnel(
name='Tunnel 2',
status=TunnelStatusChoices.STATUS_ACTIVE,
group=tunnel_groups[1],
encapsulation=TunnelEncapsulationChoices.ENCAP_IP_IP
),
Tunnel(
name='Tunnel 3',
status=TunnelStatusChoices.STATUS_ACTIVE,
group=tunnel_groups[2],
encapsulation=TunnelEncapsulationChoices.ENCAP_IP_IP
),
)
@@ -37,26 +89,28 @@ class TunnelTestCase(ViewTestCases.PrimaryObjectViewTestCase):
'name': 'Tunnel X',
'description': 'New tunnel',
'status': TunnelStatusChoices.STATUS_PLANNED,
'group': tunnel_groups[3].pk,
'encapsulation': TunnelEncapsulationChoices.ENCAP_GRE,
'tags': [t.pk for t in tags],
}
cls.csv_data = (
"name,status,encapsulation",
"Tunnel 4,planned,gre",
"Tunnel 5,planned,gre",
"Tunnel 6,planned,gre",
"name,status,group,encapsulation",
"Tunnel 4,planned,Tunnel Group 1,gre",
"Tunnel 5,planned,Tunnel Group 2,gre",
"Tunnel 6,planned,Tunnel Group 3,gre",
)
cls.csv_update_data = (
"id,status,encapsulation",
f"{tunnels[0].pk},active,ip-ip",
f"{tunnels[1].pk},active,ip-ip",
f"{tunnels[2].pk},active,ip-ip",
"id,status,group,encapsulation",
f"{tunnels[0].pk},active,Tunnel Group 4,ip-ip",
f"{tunnels[1].pk},active,Tunnel Group 4,ip-ip",
f"{tunnels[2].pk},active,Tunnel Group 4,ip-ip",
)
cls.bulk_edit_data = {
'description': 'New description',
'group': tunnel_groups[3].pk,
'status': TunnelStatusChoices.STATUS_DISABLED,
'encapsulation': TunnelEncapsulationChoices.ENCAP_GRE,
}