Просмотр исходного кода

Move form/CSV data declaration under setUpTestData

Jeremy Stretch 6 лет назад
Родитель
Сommit
78d43a5d66
2 измененных файлов с 52 добавлено и 49 удалено
  1. 52 47
      netbox/circuits/tests/test_views.py
  2. 0 2
      netbox/utilities/testing/utils.py

+ 52 - 47
netbox/circuits/tests/test_views.py

@@ -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",
+        )

+ 0 - 2
netbox/utilities/testing/utils.py

@@ -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)