| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- from django.urls import reverse
- from circuits.choices import *
- from circuits.models import *
- from dcim.models import Site
- from ipam.models import ASN, RIR
- from utilities.testing import APITestCase, APIViewTestCases
- class AppTest(APITestCase):
- def test_root(self):
- url = reverse('circuits-api:api-root')
- response = self.client.get('{}?format=api'.format(url), **self.header)
- self.assertEqual(response.status_code, 200)
- class ProviderTest(APIViewTestCases.APIViewTestCase):
- model = Provider
- brief_fields = ['circuit_count', 'description', 'display', 'id', 'name', 'slug', 'url']
- bulk_update_data = {
- 'comments': 'New comments',
- }
- @classmethod
- def setUpTestData(cls):
- rir = RIR.objects.create(name='RFC 6996', is_private=True)
- asns = [
- ASN(asn=65000 + i, rir=rir) for i in range(8)
- ]
- ASN.objects.bulk_create(asns)
- providers = (
- Provider(name='Provider 1', slug='provider-1'),
- Provider(name='Provider 2', slug='provider-2'),
- Provider(name='Provider 3', slug='provider-3'),
- )
- Provider.objects.bulk_create(providers)
- cls.create_data = [
- {
- 'name': 'Provider 4',
- 'slug': 'provider-4',
- 'asns': [asns[0].pk, asns[1].pk],
- },
- {
- 'name': 'Provider 5',
- 'slug': 'provider-5',
- 'asns': [asns[2].pk, asns[3].pk],
- },
- {
- 'name': 'Provider 6',
- 'slug': 'provider-6',
- 'asns': [asns[4].pk, asns[5].pk],
- },
- ]
- class CircuitTypeTest(APIViewTestCases.APIViewTestCase):
- model = CircuitType
- brief_fields = ['circuit_count', 'description', 'display', 'id', 'name', 'slug', 'url']
- create_data = (
- {
- 'name': 'Circuit Type 4',
- 'slug': 'circuit-type-4',
- },
- {
- 'name': 'Circuit Type 5',
- 'slug': 'circuit-type-5',
- },
- {
- 'name': 'Circuit Type 6',
- 'slug': 'circuit-type-6',
- },
- )
- bulk_update_data = {
- 'description': 'New description',
- }
- @classmethod
- def setUpTestData(cls):
- circuit_types = (
- 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'),
- )
- CircuitType.objects.bulk_create(circuit_types)
- class CircuitTest(APIViewTestCases.APIViewTestCase):
- model = Circuit
- brief_fields = ['cid', 'description', 'display', 'id', 'url']
- bulk_update_data = {
- 'status': 'planned',
- }
- @classmethod
- def setUpTestData(cls):
- providers = (
- Provider(name='Provider 1', slug='provider-1'),
- Provider(name='Provider 2', slug='provider-2'),
- )
- Provider.objects.bulk_create(providers)
- provider_accounts = (
- ProviderAccount(name='Provider Account 1', provider=providers[0], account='1234'),
- ProviderAccount(name='Provider Account 2', provider=providers[1], account='2345'),
- )
- ProviderAccount.objects.bulk_create(provider_accounts)
- circuit_types = (
- CircuitType(name='Circuit Type 1', slug='circuit-type-1'),
- CircuitType(name='Circuit Type 2', slug='circuit-type-2'),
- )
- CircuitType.objects.bulk_create(circuit_types)
- circuits = (
- Circuit(cid='Circuit 1', provider=providers[0], provider_account=provider_accounts[0], type=circuit_types[0]),
- Circuit(cid='Circuit 2', provider=providers[0], provider_account=provider_accounts[0], type=circuit_types[0]),
- Circuit(cid='Circuit 3', provider=providers[0], provider_account=provider_accounts[0], type=circuit_types[0]),
- )
- Circuit.objects.bulk_create(circuits)
- cls.create_data = [
- {
- 'cid': 'Circuit 4',
- 'provider': providers[1].pk,
- 'provider_account': provider_accounts[1].pk,
- 'type': circuit_types[1].pk,
- },
- {
- 'cid': 'Circuit 5',
- 'provider': providers[1].pk,
- 'provider_account': provider_accounts[1].pk,
- 'type': circuit_types[1].pk,
- },
- {
- 'cid': 'Circuit 6',
- 'provider': providers[1].pk,
- # Omit provider account to test uniqueness constraint
- 'type': circuit_types[1].pk,
- },
- ]
- class CircuitTerminationTest(APIViewTestCases.APIViewTestCase):
- model = CircuitTermination
- brief_fields = ['_occupied', 'cable', 'circuit', 'description', 'display', 'id', 'term_side', 'url']
- @classmethod
- def setUpTestData(cls):
- SIDE_A = CircuitTerminationSideChoices.SIDE_A
- SIDE_Z = CircuitTerminationSideChoices.SIDE_Z
- provider = Provider.objects.create(name='Provider 1', slug='provider-1')
- circuit_type = CircuitType.objects.create(name='Circuit Type 1', slug='circuit-type-1')
- sites = (
- Site(name='Site 1', slug='site-1'),
- Site(name='Site 2', slug='site-2'),
- )
- Site.objects.bulk_create(sites)
- provider_networks = (
- ProviderNetwork(provider=provider, name='Provider Network 1'),
- ProviderNetwork(provider=provider, name='Provider Network 2'),
- )
- ProviderNetwork.objects.bulk_create(provider_networks)
- circuits = (
- Circuit(cid='Circuit 1', provider=provider, type=circuit_type),
- Circuit(cid='Circuit 2', provider=provider, type=circuit_type),
- Circuit(cid='Circuit 3', provider=provider, type=circuit_type),
- )
- Circuit.objects.bulk_create(circuits)
- circuit_terminations = (
- CircuitTermination(circuit=circuits[0], term_side=SIDE_A, site=sites[0]),
- CircuitTermination(circuit=circuits[0], term_side=SIDE_Z, provider_network=provider_networks[0]),
- CircuitTermination(circuit=circuits[1], term_side=SIDE_A, site=sites[1]),
- CircuitTermination(circuit=circuits[1], term_side=SIDE_Z, provider_network=provider_networks[1]),
- )
- CircuitTermination.objects.bulk_create(circuit_terminations)
- cls.create_data = [
- {
- 'circuit': circuits[2].pk,
- 'term_side': SIDE_A,
- 'site': sites[0].pk,
- 'port_speed': 200000,
- },
- {
- 'circuit': circuits[2].pk,
- 'term_side': SIDE_Z,
- 'provider_network': provider_networks[0].pk,
- 'port_speed': 200000,
- },
- ]
- cls.bulk_update_data = {
- 'port_speed': 123456
- }
- class ProviderAccountTest(APIViewTestCases.APIViewTestCase):
- model = ProviderAccount
- brief_fields = ['account', 'description', 'display', 'id', 'name', 'url']
- @classmethod
- def setUpTestData(cls):
- providers = (
- Provider(name='Provider 1', slug='provider-1'),
- Provider(name='Provider 2', slug='provider-2'),
- )
- Provider.objects.bulk_create(providers)
- provider_accounts = (
- ProviderAccount(name='Provider Account 1', provider=providers[0], account='1234'),
- ProviderAccount(name='Provider Account 2', provider=providers[0], account='2345'),
- ProviderAccount(name='Provider Account 3', provider=providers[0], account='3456'),
- )
- ProviderAccount.objects.bulk_create(provider_accounts)
- cls.create_data = [
- {
- 'name': 'Provider Account 4',
- 'provider': providers[0].pk,
- 'account': '4567',
- },
- {
- 'name': 'Provider Account 5',
- 'provider': providers[0].pk,
- 'account': '5678',
- },
- {
- # Omit name to test uniqueness constraint
- 'provider': providers[0].pk,
- 'account': '6789',
- },
- ]
- cls.bulk_update_data = {
- 'provider': providers[1].pk,
- 'description': 'New description',
- }
- class ProviderNetworkTest(APIViewTestCases.APIViewTestCase):
- model = ProviderNetwork
- brief_fields = ['description', 'display', 'id', 'name', 'url']
- @classmethod
- def setUpTestData(cls):
- providers = (
- Provider(name='Provider 1', slug='provider-1'),
- Provider(name='Provider 2', slug='provider-2'),
- )
- Provider.objects.bulk_create(providers)
- provider_networks = (
- ProviderNetwork(name='Provider Network 1', provider=providers[0]),
- ProviderNetwork(name='Provider Network 2', provider=providers[0]),
- ProviderNetwork(name='Provider Network 3', provider=providers[0]),
- )
- ProviderNetwork.objects.bulk_create(provider_networks)
- cls.create_data = [
- {
- 'name': 'Provider Network 4',
- 'provider': providers[0].pk,
- },
- {
- 'name': 'Provider Network 5',
- 'provider': providers[0].pk,
- },
- {
- 'name': 'Provider Network 6',
- 'provider': providers[0].pk,
- },
- ]
- cls.bulk_update_data = {
- 'provider': providers[1].pk,
- 'description': 'New description',
- }
|