|
@@ -1,58 +1,59 @@
|
|
|
-import urllib.parse
|
|
|
|
|
-
|
|
|
|
|
-from django.urls import reverse
|
|
|
|
|
|
|
+import datetime
|
|
|
|
|
|
|
|
|
|
+from circuits.choices import *
|
|
|
from circuits.models import Circuit, CircuitType, Provider
|
|
from circuits.models import Circuit, CircuitType, Provider
|
|
|
-from utilities.testing import TestCase
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-class ProviderTestCase(TestCase):
|
|
|
|
|
- user_permissions = (
|
|
|
|
|
- 'circuits.view_provider',
|
|
|
|
|
|
|
+from utilities.testing import ViewTestCase
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+class ProviderTestCase(ViewTestCase):
|
|
|
|
|
+ model = Provider
|
|
|
|
|
+ form_data = {
|
|
|
|
|
+ 'name': 'Provider X',
|
|
|
|
|
+ 'slug': 'provider-x',
|
|
|
|
|
+ 'asn': 65123,
|
|
|
|
|
+ 'account': '1234',
|
|
|
|
|
+ 'portal_url': 'http://example.com/portal',
|
|
|
|
|
+ 'noc_contact': 'noc@example.com',
|
|
|
|
|
+ 'admin_contact': 'admin@example.com',
|
|
|
|
|
+ 'comments': 'Another provider',
|
|
|
|
|
+ 'tags': 'Alpha,Bravo,Charlie',
|
|
|
|
|
+ }
|
|
|
|
|
+ csv_data = (
|
|
|
|
|
+ "name,slug",
|
|
|
|
|
+ "Provider 4,provider-4",
|
|
|
|
|
+ "Provider 5,provider-5",
|
|
|
|
|
+ "Provider 6,provider-6",
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
|
def setUpTestData(cls):
|
|
def setUpTestData(cls):
|
|
|
|
|
+
|
|
|
Provider.objects.bulk_create([
|
|
Provider.objects.bulk_create([
|
|
|
Provider(name='Provider 1', slug='provider-1', asn=65001),
|
|
Provider(name='Provider 1', slug='provider-1', asn=65001),
|
|
|
Provider(name='Provider 2', slug='provider-2', asn=65002),
|
|
Provider(name='Provider 2', slug='provider-2', asn=65002),
|
|
|
Provider(name='Provider 3', slug='provider-3', asn=65003),
|
|
Provider(name='Provider 3', slug='provider-3', asn=65003),
|
|
|
])
|
|
])
|
|
|
|
|
|
|
|
- def test_provider_list(self):
|
|
|
|
|
- url = reverse('circuits:provider_list')
|
|
|
|
|
- params = {
|
|
|
|
|
- "q": "test",
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- response = self.client.get('{}?{}'.format(url, urllib.parse.urlencode(params)))
|
|
|
|
|
- self.assertHttpStatus(response, 200)
|
|
|
|
|
-
|
|
|
|
|
- def test_provider(self):
|
|
|
|
|
- provider = Provider.objects.first()
|
|
|
|
|
- response = self.client.get(provider.get_absolute_url())
|
|
|
|
|
- self.assertHttpStatus(response, 200)
|
|
|
|
|
-
|
|
|
|
|
- def test_provider_import(self):
|
|
|
|
|
- self.add_permissions('circuits.add_provider')
|
|
|
|
|
- csv_data = (
|
|
|
|
|
- "name,slug",
|
|
|
|
|
- "Provider 4,provider-4",
|
|
|
|
|
- "Provider 5,provider-5",
|
|
|
|
|
- "Provider 6,provider-6",
|
|
|
|
|
- )
|
|
|
|
|
|
|
|
|
|
- response = self.client.post(reverse('circuits:provider_import'), {'csv': '\n'.join(csv_data)})
|
|
|
|
|
-
|
|
|
|
|
- self.assertHttpStatus(response, 200)
|
|
|
|
|
- self.assertEqual(Provider.objects.count(), 6)
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-class CircuitTypeTestCase(TestCase):
|
|
|
|
|
- user_permissions = (
|
|
|
|
|
- 'circuits.view_circuittype',
|
|
|
|
|
|
|
+class CircuitTypeTestCase(ViewTestCase):
|
|
|
|
|
+ model = CircuitType
|
|
|
|
|
+ views = ('list', 'add', 'edit', 'import')
|
|
|
|
|
+ form_data = {
|
|
|
|
|
+ 'name': 'Circuit Type X',
|
|
|
|
|
+ 'slug': 'circuit-type-x',
|
|
|
|
|
+ 'description': 'A new circuit type',
|
|
|
|
|
+ }
|
|
|
|
|
+ csv_data = (
|
|
|
|
|
+ "name,slug",
|
|
|
|
|
+ "Circuit Type 4,circuit-type-4",
|
|
|
|
|
+ "Circuit Type 5,circuit-type-5",
|
|
|
|
|
+ "Circuit Type 6,circuit-type-6",
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+ # Disable inapplicable tests
|
|
|
|
|
+ test_get_object = None
|
|
|
|
|
+ test_delete_object = None
|
|
|
|
|
+
|
|
|
@classmethod
|
|
@classmethod
|
|
|
def setUpTestData(cls):
|
|
def setUpTestData(cls):
|
|
|
|
|
|
|
@@ -62,32 +63,26 @@ class CircuitTypeTestCase(TestCase):
|
|
|
CircuitType(name='Circuit Type 3', slug='circuit-type-3'),
|
|
CircuitType(name='Circuit Type 3', slug='circuit-type-3'),
|
|
|
])
|
|
])
|
|
|
|
|
|
|
|
- def test_circuittype_list(self):
|
|
|
|
|
-
|
|
|
|
|
- url = reverse('circuits:circuittype_list')
|
|
|
|
|
-
|
|
|
|
|
- response = self.client.get(url)
|
|
|
|
|
- self.assertHttpStatus(response, 200)
|
|
|
|
|
-
|
|
|
|
|
- def test_circuittype_import(self):
|
|
|
|
|
- self.add_permissions('circuits.add_circuittype')
|
|
|
|
|
|
|
|
|
|
- csv_data = (
|
|
|
|
|
- "name,slug",
|
|
|
|
|
- "Circuit Type 4,circuit-type-4",
|
|
|
|
|
- "Circuit Type 5,circuit-type-5",
|
|
|
|
|
- "Circuit Type 6,circuit-type-6",
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- response = self.client.post(reverse('circuits:circuittype_import'), {'csv': '\n'.join(csv_data)})
|
|
|
|
|
-
|
|
|
|
|
- self.assertHttpStatus(response, 200)
|
|
|
|
|
- self.assertEqual(CircuitType.objects.count(), 6)
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-class CircuitTestCase(TestCase):
|
|
|
|
|
- user_permissions = (
|
|
|
|
|
- 'circuits.view_circuit',
|
|
|
|
|
|
|
+class CircuitTestCase(ViewTestCase):
|
|
|
|
|
+ model = Circuit
|
|
|
|
|
+ # TODO: Determine how to lazily resolve related objects
|
|
|
|
|
+ form_data = {
|
|
|
|
|
+ 'cid': 'Circuit X',
|
|
|
|
|
+ 'provider': Provider.objects.first(),
|
|
|
|
|
+ 'type': CircuitType.objects.first(),
|
|
|
|
|
+ 'status': CircuitStatusChoices.STATUS_ACTIVE,
|
|
|
|
|
+ 'tenant': None,
|
|
|
|
|
+ 'install_date': datetime.date(2020, 1, 1),
|
|
|
|
|
+ 'commit_rate': 1000,
|
|
|
|
|
+ 'description': 'A new circuit',
|
|
|
|
|
+ 'comments': 'Some comments',
|
|
|
|
|
+ }
|
|
|
|
|
+ csv_data = (
|
|
|
|
|
+ "cid,provider,type",
|
|
|
|
|
+ "Circuit 4,Provider 1,Circuit Type 1",
|
|
|
|
|
+ "Circuit 5,Provider 1,Circuit Type 1",
|
|
|
|
|
+ "Circuit 6,Provider 1,Circuit Type 1",
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
@@ -104,35 +99,3 @@ class CircuitTestCase(TestCase):
|
|
|
Circuit(cid='Circuit 2', provider=provider, type=circuittype),
|
|
Circuit(cid='Circuit 2', provider=provider, type=circuittype),
|
|
|
Circuit(cid='Circuit 3', provider=provider, type=circuittype),
|
|
Circuit(cid='Circuit 3', provider=provider, type=circuittype),
|
|
|
])
|
|
])
|
|
|
-
|
|
|
|
|
- def test_circuit_list(self):
|
|
|
|
|
-
|
|
|
|
|
- url = reverse('circuits:circuit_list')
|
|
|
|
|
- params = {
|
|
|
|
|
- "provider": Provider.objects.first().slug,
|
|
|
|
|
- "type": CircuitType.objects.first().slug,
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- response = self.client.get('{}?{}'.format(url, urllib.parse.urlencode(params)))
|
|
|
|
|
- self.assertHttpStatus(response, 200)
|
|
|
|
|
-
|
|
|
|
|
- def test_circuit(self):
|
|
|
|
|
-
|
|
|
|
|
- circuit = Circuit.objects.first()
|
|
|
|
|
- response = self.client.get(circuit.get_absolute_url())
|
|
|
|
|
- self.assertHttpStatus(response, 200)
|
|
|
|
|
-
|
|
|
|
|
- def test_circuit_import(self):
|
|
|
|
|
- self.add_permissions('circuits.add_circuit')
|
|
|
|
|
-
|
|
|
|
|
- csv_data = (
|
|
|
|
|
- "cid,provider,type",
|
|
|
|
|
- "Circuit 4,Provider 1,Circuit Type 1",
|
|
|
|
|
- "Circuit 5,Provider 1,Circuit Type 1",
|
|
|
|
|
- "Circuit 6,Provider 1,Circuit Type 1",
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- response = self.client.post(reverse('circuits:circuit_import'), {'csv': '\n'.join(csv_data)})
|
|
|
|
|
-
|
|
|
|
|
- self.assertHttpStatus(response, 200)
|
|
|
|
|
- self.assertEqual(Circuit.objects.count(), 6)
|
|
|