2019-02-15 17:02:18 -05:00
|
|
|
import urllib.parse
|
|
|
|
|
|
|
|
from django.test import Client, TestCase
|
|
|
|
from django.urls import reverse
|
|
|
|
|
|
|
|
from circuits.models import Circuit, CircuitType, Provider
|
2019-04-11 17:27:38 -04:00
|
|
|
from utilities.testing import create_test_user
|
2019-02-15 17:02:18 -05:00
|
|
|
|
|
|
|
|
|
|
|
class ProviderTestCase(TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
2019-12-12 10:08:49 -05:00
|
|
|
user = create_test_user(
|
|
|
|
permissions=[
|
|
|
|
'circuits.view_provider',
|
|
|
|
'circuits.add_provider',
|
|
|
|
]
|
|
|
|
)
|
2019-02-15 17:02:18 -05:00
|
|
|
self.client = Client()
|
2019-04-11 17:27:38 -04:00
|
|
|
self.client.force_login(user)
|
2019-02-15 17:02:18 -05:00
|
|
|
|
|
|
|
Provider.objects.bulk_create([
|
|
|
|
Provider(name='Provider 1', slug='provider-1', asn=65001),
|
|
|
|
Provider(name='Provider 2', slug='provider-2', asn=65002),
|
|
|
|
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.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
def test_provider(self):
|
|
|
|
|
|
|
|
provider = Provider.objects.first()
|
|
|
|
response = self.client.get(provider.get_absolute_url())
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2019-12-12 10:08:49 -05:00
|
|
|
def test_provider_import(self):
|
|
|
|
|
|
|
|
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.assertEqual(response.status_code, 200)
|
|
|
|
self.assertEqual(Provider.objects.count(), 6)
|
|
|
|
|
2019-02-15 17:02:18 -05:00
|
|
|
|
|
|
|
class CircuitTypeTestCase(TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
2019-12-12 10:08:49 -05:00
|
|
|
user = create_test_user(
|
|
|
|
permissions=[
|
|
|
|
'circuits.view_circuittype',
|
|
|
|
'circuits.add_circuittype',
|
|
|
|
]
|
|
|
|
)
|
2019-02-15 17:02:18 -05:00
|
|
|
self.client = Client()
|
2019-04-11 17:27:38 -04:00
|
|
|
self.client.force_login(user)
|
2019-02-15 17:02:18 -05:00
|
|
|
|
|
|
|
CircuitType.objects.bulk_create([
|
|
|
|
CircuitType(name='Circuit Type 1', slug='circuit-type-1'),
|
|
|
|
CircuitType(name='Circuit Type 2', slug='circuit-type-2'),
|
|
|
|
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.assertEqual(response.status_code, 200)
|
|
|
|
|
2019-12-12 10:08:49 -05:00
|
|
|
def test_circuittype_import(self):
|
|
|
|
|
|
|
|
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.assertEqual(response.status_code, 200)
|
|
|
|
self.assertEqual(CircuitType.objects.count(), 6)
|
|
|
|
|
2019-02-15 17:02:18 -05:00
|
|
|
|
|
|
|
class CircuitTestCase(TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
2019-12-12 10:08:49 -05:00
|
|
|
user = create_test_user(
|
|
|
|
permissions=[
|
|
|
|
'circuits.view_circuit',
|
|
|
|
'circuits.add_circuit',
|
|
|
|
]
|
|
|
|
)
|
2019-02-15 17:02:18 -05:00
|
|
|
self.client = Client()
|
2019-04-11 17:27:38 -04:00
|
|
|
self.client.force_login(user)
|
2019-02-15 17:02:18 -05:00
|
|
|
|
|
|
|
provider = Provider(name='Provider 1', slug='provider-1', asn=65001)
|
|
|
|
provider.save()
|
|
|
|
|
|
|
|
circuittype = CircuitType(name='Circuit Type 1', slug='circuit-type-1')
|
|
|
|
circuittype.save()
|
|
|
|
|
|
|
|
Circuit.objects.bulk_create([
|
|
|
|
Circuit(cid='Circuit 1', provider=provider, type=circuittype),
|
|
|
|
Circuit(cid='Circuit 2', 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.assertEqual(response.status_code, 200)
|
|
|
|
|
2019-04-11 17:27:38 -04:00
|
|
|
def test_circuit(self):
|
2019-02-15 17:02:18 -05:00
|
|
|
|
2019-04-11 17:27:38 -04:00
|
|
|
circuit = Circuit.objects.first()
|
|
|
|
response = self.client.get(circuit.get_absolute_url())
|
2019-02-15 17:02:18 -05:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2019-12-12 10:08:49 -05:00
|
|
|
|
|
|
|
def test_circuit_import(self):
|
|
|
|
|
|
|
|
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.assertEqual(response.status_code, 200)
|
|
|
|
self.assertEqual(Circuit.objects.count(), 6)
|