|
|
@@ -1,3 +1,5 @@
|
|
|
+import json
|
|
|
+
|
|
|
from django.urls import reverse
|
|
|
from netaddr import IPNetwork
|
|
|
from rest_framework import status
|
|
|
@@ -870,6 +872,8 @@ class VLANTest(APITestCase):
|
|
|
self.vlan2 = VLAN.objects.create(vid=2, name='Test VLAN 2')
|
|
|
self.vlan3 = VLAN.objects.create(vid=3, name='Test VLAN 3')
|
|
|
|
|
|
+ self.prefix1 = Prefix.objects.create(prefix=IPNetwork('192.168.1.0/24'))
|
|
|
+
|
|
|
def test_get_vlan(self):
|
|
|
|
|
|
url = reverse('ipam-api:vlan-detail', kwargs={'pk': self.vlan1.pk})
|
|
|
@@ -960,6 +964,20 @@ class VLANTest(APITestCase):
|
|
|
self.assertHttpStatus(response, status.HTTP_204_NO_CONTENT)
|
|
|
self.assertEqual(VLAN.objects.count(), 2)
|
|
|
|
|
|
+ def test_delete_vlan_with_prefix(self):
|
|
|
+ self.prefix1.vlan = self.vlan1
|
|
|
+ self.prefix1.save()
|
|
|
+
|
|
|
+ url = reverse('ipam-api:vlan-detail', kwargs={'pk': self.vlan1.pk})
|
|
|
+ response = self.client.delete(url, **self.header)
|
|
|
+
|
|
|
+ # can't use assertHttpStatus here because we don't have response.data
|
|
|
+ self.assertEqual(response.status_code, 409)
|
|
|
+
|
|
|
+ content = json.loads(response.content.decode('utf-8'))
|
|
|
+ self.assertIn('detail', content)
|
|
|
+ self.assertTrue(content['detail'].startswith('You tried deleting a model that is protected by:'))
|
|
|
+
|
|
|
|
|
|
class ServiceTest(APITestCase):
|
|
|
|