mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 01:48:38 -06:00
Remove tests for API _choices endpoints
This commit is contained in:
parent
ea9de37dd1
commit
a53f854187
@ -6,7 +6,7 @@ from circuits.choices import *
|
|||||||
from circuits.models import Circuit, CircuitTermination, CircuitType, Provider
|
from circuits.models import Circuit, CircuitTermination, CircuitType, Provider
|
||||||
from dcim.models import Site
|
from dcim.models import Site
|
||||||
from extras.models import Graph
|
from extras.models import Graph
|
||||||
from utilities.testing import APITestCase, choices_to_dict
|
from utilities.testing import APITestCase
|
||||||
|
|
||||||
|
|
||||||
class AppTest(APITestCase):
|
class AppTest(APITestCase):
|
||||||
@ -18,19 +18,6 @@ class AppTest(APITestCase):
|
|||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
def test_choices(self):
|
|
||||||
|
|
||||||
url = reverse('circuits-api:field-choice-list')
|
|
||||||
response = self.client.get(url, **self.header)
|
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
|
|
||||||
# Circuit
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('circuit:status')), CircuitStatusChoices.as_dict())
|
|
||||||
|
|
||||||
# CircuitTermination
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('circuit-termination:term_side')), CircuitTerminationSideChoices.as_dict())
|
|
||||||
|
|
||||||
|
|
||||||
class ProviderTest(APITestCase):
|
class ProviderTest(APITestCase):
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ from dcim.models import (
|
|||||||
)
|
)
|
||||||
from ipam.models import IPAddress, VLAN
|
from ipam.models import IPAddress, VLAN
|
||||||
from extras.models import Graph
|
from extras.models import Graph
|
||||||
from utilities.testing import APITestCase, choices_to_dict
|
from utilities.testing import APITestCase
|
||||||
from virtualization.models import Cluster, ClusterType
|
from virtualization.models import Cluster, ClusterType
|
||||||
|
|
||||||
|
|
||||||
@ -27,79 +27,6 @@ class AppTest(APITestCase):
|
|||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
def test_choices(self):
|
|
||||||
|
|
||||||
url = reverse('dcim-api:field-choice-list')
|
|
||||||
response = self.client.get(url, **self.header)
|
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
|
|
||||||
# Cable
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('cable:length_unit')), CableLengthUnitChoices.as_dict())
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('cable:status')), CableStatusChoices.as_dict())
|
|
||||||
content_types = ContentType.objects.filter(CABLE_TERMINATION_MODELS)
|
|
||||||
cable_termination_choices = {
|
|
||||||
"{}.{}".format(ct.app_label, ct.model): str(ct) for ct in content_types
|
|
||||||
}
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('cable:termination_a_type')), cable_termination_choices)
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('cable:termination_b_type')), cable_termination_choices)
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('cable:type')), CableTypeChoices.as_dict())
|
|
||||||
|
|
||||||
# Console ports
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('console-port:type')), ConsolePortTypeChoices.as_dict())
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('console-port:connection_status')), dict(CONNECTION_STATUS_CHOICES))
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('console-port-template:type')), ConsolePortTypeChoices.as_dict())
|
|
||||||
|
|
||||||
# Console server ports
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('console-server-port:type')), ConsolePortTypeChoices.as_dict())
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('console-server-port-template:type')), ConsolePortTypeChoices.as_dict())
|
|
||||||
|
|
||||||
# Device
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('device:face')), DeviceFaceChoices.as_dict())
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('device:status')), DeviceStatusChoices.as_dict())
|
|
||||||
|
|
||||||
# Device type
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('device-type:subdevice_role')), SubdeviceRoleChoices.as_dict())
|
|
||||||
|
|
||||||
# Front ports
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('front-port:type')), PortTypeChoices.as_dict())
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('front-port-template:type')), PortTypeChoices.as_dict())
|
|
||||||
|
|
||||||
# Interfaces
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('interface:type')), InterfaceTypeChoices.as_dict())
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('interface:mode')), InterfaceModeChoices.as_dict())
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('interface-template:type')), InterfaceTypeChoices.as_dict())
|
|
||||||
|
|
||||||
# Power feed
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('power-feed:phase')), PowerFeedPhaseChoices.as_dict())
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('power-feed:status')), PowerFeedStatusChoices.as_dict())
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('power-feed:supply')), PowerFeedSupplyChoices.as_dict())
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('power-feed:type')), PowerFeedTypeChoices.as_dict())
|
|
||||||
|
|
||||||
# Power outlets
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('power-outlet:type')), PowerOutletTypeChoices.as_dict())
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('power-outlet:feed_leg')), PowerOutletFeedLegChoices.as_dict())
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('power-outlet-template:type')), PowerOutletTypeChoices.as_dict())
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('power-outlet-template:feed_leg')), PowerOutletFeedLegChoices.as_dict())
|
|
||||||
|
|
||||||
# Power ports
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('power-port:type')), PowerPortTypeChoices.as_dict())
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('power-port:connection_status')), dict(CONNECTION_STATUS_CHOICES))
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('power-port-template:type')), PowerPortTypeChoices.as_dict())
|
|
||||||
|
|
||||||
# Rack
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('rack:type')), RackTypeChoices.as_dict())
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('rack:width')), RackWidthChoices.as_dict())
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('rack:status')), RackStatusChoices.as_dict())
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('rack:outer_unit')), RackDimensionUnitChoices.as_dict())
|
|
||||||
|
|
||||||
# Rear ports
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('rear-port:type')), PortTypeChoices.as_dict())
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('rear-port-template:type')), PortTypeChoices.as_dict())
|
|
||||||
|
|
||||||
# Site
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('site:status')), SiteStatusChoices.as_dict())
|
|
||||||
|
|
||||||
|
|
||||||
class RegionTest(APITestCase):
|
class RegionTest(APITestCase):
|
||||||
|
|
||||||
|
@ -7,12 +7,10 @@ from rest_framework import status
|
|||||||
|
|
||||||
from dcim.models import Device, DeviceRole, DeviceType, Manufacturer, Platform, Rack, RackGroup, RackRole, Region, Site
|
from dcim.models import Device, DeviceRole, DeviceType, Manufacturer, Platform, Rack, RackGroup, RackRole, Region, Site
|
||||||
from extras.api.views import ScriptViewSet
|
from extras.api.views import ScriptViewSet
|
||||||
from extras.choices import *
|
|
||||||
from extras.constants import GRAPH_MODELS
|
|
||||||
from extras.models import ConfigContext, Graph, ExportTemplate, Tag
|
from extras.models import ConfigContext, Graph, ExportTemplate, Tag
|
||||||
from extras.scripts import BooleanVar, IntegerVar, Script, StringVar
|
from extras.scripts import BooleanVar, IntegerVar, Script, StringVar
|
||||||
from tenancy.models import Tenant, TenantGroup
|
from tenancy.models import Tenant, TenantGroup
|
||||||
from utilities.testing import APITestCase, choices_to_dict
|
from utilities.testing import APITestCase
|
||||||
|
|
||||||
|
|
||||||
class AppTest(APITestCase):
|
class AppTest(APITestCase):
|
||||||
@ -24,27 +22,6 @@ class AppTest(APITestCase):
|
|||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
def test_choices(self):
|
|
||||||
|
|
||||||
url = reverse('extras-api:field-choice-list')
|
|
||||||
response = self.client.get(url, **self.header)
|
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
|
|
||||||
# ExportTemplate
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('export-template:template_language')), TemplateLanguageChoices.as_dict())
|
|
||||||
|
|
||||||
# Graph
|
|
||||||
content_types = ContentType.objects.filter(GRAPH_MODELS)
|
|
||||||
graph_type_choices = {
|
|
||||||
"{}.{}".format(ct.app_label, ct.model): str(ct) for ct in content_types
|
|
||||||
}
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('graph:type')), graph_type_choices)
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('graph:template_language')), TemplateLanguageChoices.as_dict())
|
|
||||||
|
|
||||||
# ObjectChange
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('object-change:action')), ObjectChangeActionChoices.as_dict())
|
|
||||||
|
|
||||||
|
|
||||||
class GraphTest(APITestCase):
|
class GraphTest(APITestCase):
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ from rest_framework import status
|
|||||||
from dcim.models import Device, DeviceRole, DeviceType, Manufacturer, Site
|
from dcim.models import Device, DeviceRole, DeviceType, Manufacturer, Site
|
||||||
from ipam.choices import *
|
from ipam.choices import *
|
||||||
from ipam.models import Aggregate, IPAddress, Prefix, RIR, Role, Service, VLAN, VLANGroup, VRF
|
from ipam.models import Aggregate, IPAddress, Prefix, RIR, Role, Service, VLAN, VLANGroup, VRF
|
||||||
from utilities.testing import APITestCase, choices_to_dict, disable_warnings
|
from utilities.testing import APITestCase, disable_warnings
|
||||||
|
|
||||||
|
|
||||||
class AppTest(APITestCase):
|
class AppTest(APITestCase):
|
||||||
@ -19,31 +19,6 @@ class AppTest(APITestCase):
|
|||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
def test_choices(self):
|
|
||||||
|
|
||||||
url = reverse('ipam-api:field-choice-list')
|
|
||||||
response = self.client.get(url, **self.header)
|
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
|
|
||||||
# Aggregate
|
|
||||||
# self.assertEqual(choices_to_dict(response.data.get('aggregate:family')), )
|
|
||||||
|
|
||||||
# Prefix
|
|
||||||
# self.assertEqual(choices_to_dict(response.data.get('prefix:family')), )
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('prefix:status')), PrefixStatusChoices.as_dict())
|
|
||||||
|
|
||||||
# IPAddress
|
|
||||||
# self.assertEqual(choices_to_dict(response.data.get('ip-address:family')), )
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('ip-address:role')), IPAddressRoleChoices.as_dict())
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('ip-address:status')), IPAddressStatusChoices.as_dict())
|
|
||||||
|
|
||||||
# VLAN
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('vlan:status')), VLANStatusChoices.as_dict())
|
|
||||||
|
|
||||||
# Service
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('service:protocol')), ServiceProtocolChoices.as_dict())
|
|
||||||
|
|
||||||
|
|
||||||
class VRFTest(APITestCase):
|
class VRFTest(APITestCase):
|
||||||
|
|
||||||
|
@ -19,13 +19,6 @@ class AppTest(APITestCase):
|
|||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
def test_choices(self):
|
|
||||||
|
|
||||||
url = reverse('secrets-api:field-choice-list')
|
|
||||||
response = self.client.get(url, **self.header)
|
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
|
|
||||||
|
|
||||||
class SecretRoleTest(APITestCase):
|
class SecretRoleTest(APITestCase):
|
||||||
|
|
||||||
|
@ -14,13 +14,6 @@ class AppTest(APITestCase):
|
|||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
def test_choices(self):
|
|
||||||
|
|
||||||
url = reverse('tenancy-api:field-choice-list')
|
|
||||||
response = self.client.get(url, **self.header)
|
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
|
|
||||||
|
|
||||||
class TenantGroupTest(APITestCase):
|
class TenantGroupTest(APITestCase):
|
||||||
|
|
||||||
|
@ -36,33 +36,6 @@ def create_test_user(username='testuser', permissions=None):
|
|||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
def choices_to_dict(choices_list):
|
|
||||||
"""
|
|
||||||
Convert a list of field choices to a dictionary suitable for direct comparison with a ChoiceSet. For example:
|
|
||||||
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"value": "choice-1",
|
|
||||||
"label": "First Choice"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"value": "choice-2",
|
|
||||||
"label": "Second Choice"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
Becomes:
|
|
||||||
|
|
||||||
{
|
|
||||||
"choice-1": "First Choice",
|
|
||||||
"choice-2": "Second Choice
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
return {
|
|
||||||
choice['value']: choice['label'] for choice in choices_list
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def disable_warnings(logger_name):
|
def disable_warnings(logger_name):
|
||||||
"""
|
"""
|
||||||
|
@ -5,7 +5,7 @@ from rest_framework import status
|
|||||||
from dcim.choices import InterfaceModeChoices
|
from dcim.choices import InterfaceModeChoices
|
||||||
from dcim.models import Interface
|
from dcim.models import Interface
|
||||||
from ipam.models import IPAddress, VLAN
|
from ipam.models import IPAddress, VLAN
|
||||||
from utilities.testing import APITestCase, choices_to_dict, disable_warnings
|
from utilities.testing import APITestCase, disable_warnings
|
||||||
from virtualization.choices import *
|
from virtualization.choices import *
|
||||||
from virtualization.models import Cluster, ClusterGroup, ClusterType, VirtualMachine
|
from virtualization.models import Cluster, ClusterGroup, ClusterType, VirtualMachine
|
||||||
|
|
||||||
@ -19,19 +19,6 @@ class AppTest(APITestCase):
|
|||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
def test_choices(self):
|
|
||||||
|
|
||||||
url = reverse('virtualization-api:field-choice-list')
|
|
||||||
response = self.client.get(url, **self.header)
|
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
|
|
||||||
# VirtualMachine
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('virtual-machine:status')), VirtualMachineStatusChoices.as_dict())
|
|
||||||
|
|
||||||
# Interface
|
|
||||||
self.assertEqual(choices_to_dict(response.data.get('interface:type')), VMInterfaceTypeChoices.as_dict())
|
|
||||||
|
|
||||||
|
|
||||||
class ClusterTypeTest(APITestCase):
|
class ClusterTypeTest(APITestCase):
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user