diff --git a/netbox/circuits/tests/test_views.py b/netbox/circuits/tests/test_views.py index 18f40dfbd..1e065f458 100644 --- a/netbox/circuits/tests/test_views.py +++ b/netbox/circuits/tests/test_views.py @@ -7,23 +7,6 @@ from utilities.testing import StandardTestCases class ProviderTestCase(StandardTestCases.Views): 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 def setUpTestData(cls): @@ -34,21 +17,28 @@ class ProviderTestCase(StandardTestCases.Views): Provider(name='Provider 3', slug='provider-3', asn=65003), ]) + cls.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', + } + + cls.csv_data = ( + "name,slug", + "Provider 4,provider-4", + "Provider 5,provider-5", + "Provider 6,provider-6", + ) + class CircuitTypeTestCase(StandardTestCases.Views): 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 @@ -63,27 +53,22 @@ class CircuitTypeTestCase(StandardTestCases.Views): CircuitType(name='Circuit Type 3', slug='circuit-type-3'), ]) + cls.form_data = { + 'name': 'Circuit Type X', + 'slug': 'circuit-type-x', + 'description': 'A new circuit type', + } + + cls.csv_data = ( + "name,slug", + "Circuit Type 4,circuit-type-4", + "Circuit Type 5,circuit-type-5", + "Circuit Type 6,circuit-type-6", + ) + class CircuitTestCase(StandardTestCases.Views): 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 def setUpTestData(cls): @@ -99,3 +84,23 @@ class CircuitTestCase(StandardTestCases.Views): Circuit(cid='Circuit 2', provider=provider, type=circuittype), Circuit(cid='Circuit 3', provider=provider, type=circuittype), ]) + + cls.form_data = { + 'cid': 'Circuit X', + 'provider': provider.pk, + 'type': circuittype.pk, + 'status': CircuitStatusChoices.STATUS_ACTIVE, + 'tenant': None, + 'install_date': datetime.date(2020, 1, 1), + 'commit_rate': 1000, + 'description': 'A new circuit', + 'comments': 'Some comments', + 'tags': 'Alpha,Bravo,Charlie', + } + + cls.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", + ) diff --git a/netbox/utilities/testing/utils.py b/netbox/utilities/testing/utils.py index 8066cc710..61b3ed64d 100644 --- a/netbox/utilities/testing/utils.py +++ b/netbox/utilities/testing/utils.py @@ -32,8 +32,6 @@ def post_data(data): for key, value in data.items(): if value is None: ret[key] = '' - elif hasattr(value, 'pk'): - ret[key] = getattr(value, 'pk') else: ret[key] = str(value)