From 71449b3414ec0b89b314f13f35b26913112239f8 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 28 Sep 2021 12:04:54 -0400 Subject: [PATCH] Fixes #7304: Require explicit values for all required choice fields during CSV import --- docs/release-notes/version-3.0.md | 1 + netbox/circuits/forms/bulk_import.py | 1 - netbox/circuits/tests/test_views.py | 8 ++++---- netbox/dcim/forms/bulk_import.py | 6 ------ netbox/dcim/tests/test_views.py | 16 ++++++++-------- netbox/extras/tests/test_customfields.py | 8 ++++---- netbox/ipam/forms/bulk_import.py | 1 - netbox/virtualization/forms/bulk_import.py | 1 - netbox/virtualization/tests/test_views.py | 8 ++++---- 9 files changed, 21 insertions(+), 29 deletions(-) diff --git a/docs/release-notes/version-3.0.md b/docs/release-notes/version-3.0.md index 2a5a47b5a..796f9562f 100644 --- a/docs/release-notes/version-3.0.md +++ b/docs/release-notes/version-3.0.md @@ -11,6 +11,7 @@ ### Bug Fixes * [#7294](https://github.com/netbox-community/netbox/issues/7294) - Fix SVG rendering for cable traces ending at unoccupied front ports +* [#7304](https://github.com/netbox-community/netbox/issues/7304) - Require explicit values for all required choice fields during CSV import * [#7321](https://github.com/netbox-community/netbox/issues/7321) - Don't overwrite multi-select custom fields during bulk edit * [#7324](https://github.com/netbox-community/netbox/issues/7324) - Fix TypeError exception in web UI when filtering objects using single-choice filters * [#7333](https://github.com/netbox-community/netbox/issues/7333) - Prevent inadvertent deletion of prior change records when deleting objects diff --git a/netbox/circuits/forms/bulk_import.py b/netbox/circuits/forms/bulk_import.py index 41ee7281a..af5ec4425 100644 --- a/netbox/circuits/forms/bulk_import.py +++ b/netbox/circuits/forms/bulk_import.py @@ -60,7 +60,6 @@ class CircuitCSVForm(CustomFieldModelCSVForm): ) status = CSVChoiceField( choices=CircuitStatusChoices, - required=False, help_text='Operational status' ) tenant = CSVModelChoiceField( diff --git a/netbox/circuits/tests/test_views.py b/netbox/circuits/tests/test_views.py index b6401b2fa..ccb4a869a 100644 --- a/netbox/circuits/tests/test_views.py +++ b/netbox/circuits/tests/test_views.py @@ -122,10 +122,10 @@ class CircuitTestCase(ViewTestCases.PrimaryObjectViewTestCase): } 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", + "cid,provider,type,status", + "Circuit 4,Provider 1,Circuit Type 1,active", + "Circuit 5,Provider 1,Circuit Type 1,active", + "Circuit 6,Provider 1,Circuit Type 1,active", ) cls.bulk_edit_data = { diff --git a/netbox/dcim/forms/bulk_import.py b/netbox/dcim/forms/bulk_import.py index 93f17e839..072cdf0e0 100644 --- a/netbox/dcim/forms/bulk_import.py +++ b/netbox/dcim/forms/bulk_import.py @@ -70,7 +70,6 @@ class SiteGroupCSVForm(CustomFieldModelCSVForm): class SiteCSVForm(CustomFieldModelCSVForm): status = CSVChoiceField( choices=SiteStatusChoices, - required=False, help_text='Operational status' ) region = CSVModelChoiceField( @@ -156,7 +155,6 @@ class RackCSVForm(CustomFieldModelCSVForm): ) status = CSVChoiceField( choices=RackStatusChoices, - required=False, help_text='Operational status' ) role = CSVModelChoiceField( @@ -929,22 +927,18 @@ class PowerFeedCSVForm(CustomFieldModelCSVForm): ) status = CSVChoiceField( choices=PowerFeedStatusChoices, - required=False, help_text='Operational status' ) type = CSVChoiceField( choices=PowerFeedTypeChoices, - required=False, help_text='Primary or redundant' ) supply = CSVChoiceField( choices=PowerFeedSupplyChoices, - required=False, help_text='Supply type (AC/DC)' ) phase = CSVChoiceField( choices=PowerFeedPhaseChoices, - required=False, help_text='Single or three-phase' ) diff --git a/netbox/dcim/tests/test_views.py b/netbox/dcim/tests/test_views.py index c38dc4ea7..18eaeec3b 100644 --- a/netbox/dcim/tests/test_views.py +++ b/netbox/dcim/tests/test_views.py @@ -322,10 +322,10 @@ class RackTestCase(ViewTestCases.PrimaryObjectViewTestCase): } cls.csv_data = ( - "site,location,name,width,u_height", - "Site 1,,Rack 4,19,42", - "Site 1,Location 1,Rack 5,19,42", - "Site 2,Location 2,Rack 6,19,42", + "site,location,name,status,width,u_height", + "Site 1,,Rack 4,active,19,42", + "Site 1,Location 1,Rack 5,active,19,42", + "Site 2,Location 2,Rack 6,active,19,42", ) cls.bulk_edit_data = { @@ -1991,10 +1991,10 @@ class PowerFeedTestCase(ViewTestCases.PrimaryObjectViewTestCase): } cls.csv_data = ( - "site,power_panel,name,voltage,amperage,max_utilization", - "Site 1,Power Panel 1,Power Feed 4,120,20,80", - "Site 1,Power Panel 1,Power Feed 5,120,20,80", - "Site 1,Power Panel 1,Power Feed 6,120,20,80", + "site,power_panel,name,status,type,supply,phase,voltage,amperage,max_utilization", + "Site 1,Power Panel 1,Power Feed 4,active,primary,ac,single-phase,120,20,80", + "Site 1,Power Panel 1,Power Feed 5,active,primary,ac,single-phase,120,20,80", + "Site 1,Power Panel 1,Power Feed 6,active,primary,ac,single-phase,120,20,80", ) cls.bulk_edit_data = { diff --git a/netbox/extras/tests/test_customfields.py b/netbox/extras/tests/test_customfields.py index c2a2da3dc..32c473678 100644 --- a/netbox/extras/tests/test_customfields.py +++ b/netbox/extras/tests/test_customfields.py @@ -506,10 +506,10 @@ class CustomFieldImportTest(TestCase): Import a Site in CSV format, including a value for each CustomField. """ data = ( - ('name', 'slug', 'cf_text', 'cf_integer', 'cf_boolean', 'cf_date', 'cf_url', 'cf_select'), - ('Site 1', 'site-1', 'ABC', '123', 'True', '2020-01-01', 'http://example.com/1', 'Choice A'), - ('Site 2', 'site-2', 'DEF', '456', 'False', '2020-01-02', 'http://example.com/2', 'Choice B'), - ('Site 3', 'site-3', '', '', '', '', '', ''), + ('name', 'slug', 'status', 'cf_text', 'cf_integer', 'cf_boolean', 'cf_date', 'cf_url', 'cf_select'), + ('Site 1', 'site-1', 'active', 'ABC', '123', 'True', '2020-01-01', 'http://example.com/1', 'Choice A'), + ('Site 2', 'site-2', 'active', 'DEF', '456', 'False', '2020-01-02', 'http://example.com/2', 'Choice B'), + ('Site 3', 'site-3', 'active', '', '', '', '', '', ''), ) csv_data = '\n'.join(','.join(row) for row in data) diff --git a/netbox/ipam/forms/bulk_import.py b/netbox/ipam/forms/bulk_import.py index ef5759748..49d5014f9 100644 --- a/netbox/ipam/forms/bulk_import.py +++ b/netbox/ipam/forms/bulk_import.py @@ -198,7 +198,6 @@ class IPAddressCSVForm(CustomFieldModelCSVForm): ) status = CSVChoiceField( choices=IPAddressStatusChoices, - required=False, help_text='Operational status' ) role = CSVChoiceField( diff --git a/netbox/virtualization/forms/bulk_import.py b/netbox/virtualization/forms/bulk_import.py index 1f0496b7c..d01418aa0 100644 --- a/netbox/virtualization/forms/bulk_import.py +++ b/netbox/virtualization/forms/bulk_import.py @@ -64,7 +64,6 @@ class ClusterCSVForm(CustomFieldModelCSVForm): class VirtualMachineCSVForm(CustomFieldModelCSVForm): status = CSVChoiceField( choices=VirtualMachineStatusChoices, - required=False, help_text='Operational status of device' ) cluster = CSVModelChoiceField( diff --git a/netbox/virtualization/tests/test_views.py b/netbox/virtualization/tests/test_views.py index 86be5159f..020c9ebc5 100644 --- a/netbox/virtualization/tests/test_views.py +++ b/netbox/virtualization/tests/test_views.py @@ -194,10 +194,10 @@ class VirtualMachineTestCase(ViewTestCases.PrimaryObjectViewTestCase): } cls.csv_data = ( - "name,cluster", - "Virtual Machine 4,Cluster 1", - "Virtual Machine 5,Cluster 1", - "Virtual Machine 6,Cluster 1", + "name,status,cluster", + "Virtual Machine 4,active,Cluster 1", + "Virtual Machine 5,active,Cluster 1", + "Virtual Machine 6,active,Cluster 1", ) cls.bulk_edit_data = {