From 486f1a74abdef2561800c994ede207e7e4f96823 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Thu, 28 May 2020 12:05:54 -0400 Subject: [PATCH] Standardize base classes for view test cases --- netbox/dcim/tests/test_views.py | 62 +++++++++++++---------- netbox/extras/tests/test_views.py | 40 +++++++-------- netbox/ipam/tests/test_views.py | 16 +++--- netbox/secrets/tests/test_views.py | 19 +++---- netbox/virtualization/tests/test_views.py | 16 +++--- 5 files changed, 76 insertions(+), 77 deletions(-) diff --git a/netbox/dcim/tests/test_views.py b/netbox/dcim/tests/test_views.py index 6e28700c8..cfbb2b95f 100644 --- a/netbox/dcim/tests/test_views.py +++ b/netbox/dcim/tests/test_views.py @@ -321,7 +321,16 @@ class ManufacturerTestCase(ViewTestCases.OrganizationalObjectViewTestCase): ) -class DeviceTypeTestCase(ViewTestCases.PrimaryObjectViewTestCase): +# TODO: Change base class to PrimaryObjectViewTestCase +class DeviceTypeTestCase( + ViewTestCases.GetObjectViewTestCase, + ViewTestCases.CreateObjectViewTestCase, + ViewTestCases.EditObjectViewTestCase, + ViewTestCases.DeleteObjectViewTestCase, + ViewTestCases.ListObjectsViewTestCase, + ViewTestCases.BulkEditObjectsViewTestCase, + ViewTestCases.BulkDeleteObjectsViewTestCase +): model = DeviceType @classmethod @@ -792,14 +801,15 @@ class RearPortTemplateTestCase(ViewTestCases.DeviceComponentTemplateViewTestCase } -class DeviceBayTemplateTestCase(ViewTestCases.DeviceComponentTemplateViewTestCase): +# TODO: Change base class to DeviceComponentTemplateViewTestCase +class DeviceBayTemplateTestCase( + ViewTestCases.EditObjectViewTestCase, + ViewTestCases.DeleteObjectViewTestCase, + ViewTestCases.BulkCreateObjectsViewTestCase, + ViewTestCases.BulkDeleteObjectsViewTestCase +): model = DeviceBayTemplate - # Disable inapplicable views - test_bulk_edit_objects_without_permission = None - test_bulk_edit_objects_with_model_permission = None - test_bulk_edit_objects_with_object_permission = None - @classmethod def setUpTestData(cls): manufacturer = Manufacturer.objects.create(name='Manufacturer 1', slug='manufacturer-1') @@ -1439,14 +1449,18 @@ class InventoryItemTestCase(ViewTestCases.DeviceComponentViewTestCase): ) -class CableTestCase(ViewTestCases.PrimaryObjectViewTestCase): +# TODO: Change base class to PrimaryObjectViewTestCase +class CableTestCase( + ViewTestCases.GetObjectViewTestCase, + ViewTestCases.EditObjectViewTestCase, + ViewTestCases.DeleteObjectViewTestCase, + ViewTestCases.ListObjectsViewTestCase, + ViewTestCases.BulkImportObjectsViewTestCase, + ViewTestCases.BulkEditObjectsViewTestCase, + ViewTestCases.BulkDeleteObjectsViewTestCase +): model = Cable - # TODO: Creation URL needs termination context - test_create_object_without_permission = None - test_create_object_with_model_permission = None - test_create_object_with_object_permission = None - @classmethod def setUpTestData(cls): @@ -1515,22 +1529,16 @@ class CableTestCase(ViewTestCases.PrimaryObjectViewTestCase): } -class VirtualChassisTestCase(ViewTestCases.PrimaryObjectViewTestCase): +# TODO: Change base class to PrimaryObjectViewTestCase +class VirtualChassisTestCase( + ViewTestCases.GetObjectViewTestCase, + ViewTestCases.DeleteObjectViewTestCase, + ViewTestCases.ListObjectsViewTestCase, + ViewTestCases.BulkEditObjectsViewTestCase, + ViewTestCases.BulkDeleteObjectsViewTestCase +): model = VirtualChassis - # Disable inapplicable tests - test_bulk_import_objects_without_permission = None - test_bulk_import_objects_with_model_permission = None - test_bulk_import_objects_with_object_permission = None - - # TODO: Requires special form handling - test_create_object_without_permission = None - test_create_object_with_model_permission = None - test_create_object_with_object_permission = None - test_edit_object_without_permission = None - test_edit_object_with_model_permission = None - test_edit_object_with_object_permission = None - @classmethod def setUpTestData(cls): diff --git a/netbox/extras/tests/test_views.py b/netbox/extras/tests/test_views.py index f52054cc1..6d41886fc 100644 --- a/netbox/extras/tests/test_views.py +++ b/netbox/extras/tests/test_views.py @@ -10,17 +10,17 @@ from extras.models import ConfigContext, ObjectChange, Tag from utilities.testing import ViewTestCases, TestCase -class TagTestCase(ViewTestCases.PrimaryObjectViewTestCase): +# TODO: Change base class to PrimaryObjectViewTestCase +class TagTestCase( + ViewTestCases.GetObjectViewTestCase, + ViewTestCases.EditObjectViewTestCase, + ViewTestCases.DeleteObjectViewTestCase, + ViewTestCases.ListObjectsViewTestCase, + ViewTestCases.BulkEditObjectsViewTestCase, + ViewTestCases.BulkDeleteObjectsViewTestCase +): model = Tag - # Disable inapplicable tests - test_create_object_without_permission = None - test_create_object_with_model_permission = None - test_create_object_with_object_permission = None - test_bulk_import_objects_without_permission = None - test_bulk_import_objects_with_model_permission = None - test_bulk_import_objects_with_object_permission = None - @classmethod def setUpTestData(cls): @@ -42,22 +42,16 @@ class TagTestCase(ViewTestCases.PrimaryObjectViewTestCase): } -class ConfigContextTestCase(ViewTestCases.PrimaryObjectViewTestCase): +# TODO: Change base class to PrimaryObjectViewTestCase +class ConfigContextTestCase( + ViewTestCases.GetObjectViewTestCase, + ViewTestCases.DeleteObjectViewTestCase, + ViewTestCases.ListObjectsViewTestCase, + ViewTestCases.BulkEditObjectsViewTestCase, + ViewTestCases.BulkDeleteObjectsViewTestCase +): model = ConfigContext - # Disable inapplicable tests - test_bulk_import_objects_without_permission = None - test_bulk_import_objects_with_model_permission = None - test_bulk_import_objects_with_object_permission = None - - # TODO: Resolve model discrepancies when creating/editing ConfigContexts - test_create_object_without_permission = None - test_create_object_with_model_permission = None - test_create_object_with_object_permission = None - test_edit_object_without_permission = None - test_edit_object_with_model_permission = None - test_edit_object_with_object_permission = None - @classmethod def setUpTestData(cls): diff --git a/netbox/ipam/tests/test_views.py b/netbox/ipam/tests/test_views.py index bbd252473..794284dba 100644 --- a/netbox/ipam/tests/test_views.py +++ b/netbox/ipam/tests/test_views.py @@ -333,14 +333,18 @@ class VLANTestCase(ViewTestCases.PrimaryObjectViewTestCase): } -class ServiceTestCase(ViewTestCases.PrimaryObjectViewTestCase): +# TODO: Update base class to PrimaryObjectViewTestCase +class ServiceTestCase( + ViewTestCases.GetObjectViewTestCase, + ViewTestCases.EditObjectViewTestCase, + ViewTestCases.DeleteObjectViewTestCase, + ViewTestCases.ListObjectsViewTestCase, + ViewTestCases.BulkImportObjectsViewTestCase, + ViewTestCases.BulkEditObjectsViewTestCase, + ViewTestCases.BulkDeleteObjectsViewTestCase +): model = Service - # TODO: Resolve URL for Service creation - test_create_object_without_permission = None - test_create_object_with_model_permission = None - test_create_object_with_object_permission = None - @classmethod def setUpTestData(cls): diff --git a/netbox/secrets/tests/test_views.py b/netbox/secrets/tests/test_views.py index 7796be63d..577ba4ef4 100644 --- a/netbox/secrets/tests/test_views.py +++ b/netbox/secrets/tests/test_views.py @@ -36,19 +36,16 @@ class SecretRoleTestCase(ViewTestCases.OrganizationalObjectViewTestCase): ) -class SecretTestCase(ViewTestCases.PrimaryObjectViewTestCase): +# TODO: Change base class to PrimaryObjectViewTestCase +class SecretTestCase( + ViewTestCases.GetObjectViewTestCase, + ViewTestCases.DeleteObjectViewTestCase, + ViewTestCases.ListObjectsViewTestCase, + ViewTestCases.BulkEditObjectsViewTestCase, + ViewTestCases.BulkDeleteObjectsViewTestCase +): model = Secret - # Disable inapplicable tests - test_create_object_without_permission = None - test_create_object_with_model_permission = None - test_create_object_with_object_permission = None - - # TODO: Check permissions enforcement on secrets.views.secret_edit - test_edit_object_without_permission = None - test_edit_object_with_model_permission = None - test_edit_object_with_object_permission = None - @classmethod def setUpTestData(cls): diff --git a/netbox/virtualization/tests/test_views.py b/netbox/virtualization/tests/test_views.py index 067606648..9fde12186 100644 --- a/netbox/virtualization/tests/test_views.py +++ b/netbox/virtualization/tests/test_views.py @@ -185,21 +185,17 @@ class VirtualMachineTestCase(ViewTestCases.PrimaryObjectViewTestCase): } +# TODO: Update base class to DeviceComponentViewTestCase class InterfaceTestCase( ViewTestCases.GetObjectViewTestCase, - ViewTestCases.DeviceComponentViewTestCase, + ViewTestCases.EditObjectViewTestCase, + ViewTestCases.DeleteObjectViewTestCase, + ViewTestCases.BulkCreateObjectsViewTestCase, + ViewTestCases.BulkEditObjectsViewTestCase, + ViewTestCases.BulkDeleteObjectsViewTestCase, ): model = Interface - # Disable inapplicable tests - test_list_objects_anonymous = None - test_list_objects_without_permission = None - test_list_objects_with_model_permission = None - test_list_objects_with_object_permission = None - test_bulk_import_objects_without_permission = None - test_bulk_import_objects_with_model_permission = None - test_bulk_import_objects_with_object_permission = None - def _get_base_url(self): # Interface belongs to the DCIM app, so we have to override the base URL return 'virtualization:interface_{}'