mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-23 04:22:01 -06:00
Move form/CSV data declaration under setUpTestData
This commit is contained in:
parent
939b5f2e29
commit
78d43a5d66
@ -7,23 +7,6 @@ from utilities.testing import StandardTestCases
|
|||||||
|
|
||||||
class ProviderTestCase(StandardTestCases.Views):
|
class ProviderTestCase(StandardTestCases.Views):
|
||||||
model = Provider
|
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):
|
||||||
@ -34,21 +17,28 @@ class ProviderTestCase(StandardTestCases.Views):
|
|||||||
Provider(name='Provider 3', slug='provider-3', asn=65003),
|
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):
|
class CircuitTypeTestCase(StandardTestCases.Views):
|
||||||
model = CircuitType
|
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
|
# Disable inapplicable tests
|
||||||
test_get_object = None
|
test_get_object = None
|
||||||
@ -63,27 +53,22 @@ class CircuitTypeTestCase(StandardTestCases.Views):
|
|||||||
CircuitType(name='Circuit Type 3', slug='circuit-type-3'),
|
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):
|
class CircuitTestCase(StandardTestCases.Views):
|
||||||
model = Circuit
|
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
|
||||||
def setUpTestData(cls):
|
def setUpTestData(cls):
|
||||||
@ -99,3 +84,23 @@ class CircuitTestCase(StandardTestCases.Views):
|
|||||||
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),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
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",
|
||||||
|
)
|
||||||
|
@ -32,8 +32,6 @@ def post_data(data):
|
|||||||
for key, value in data.items():
|
for key, value in data.items():
|
||||||
if value is None:
|
if value is None:
|
||||||
ret[key] = ''
|
ret[key] = ''
|
||||||
elif hasattr(value, 'pk'):
|
|
||||||
ret[key] = getattr(value, 'pk')
|
|
||||||
else:
|
else:
|
||||||
ret[key] = str(value)
|
ret[key] = str(value)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user