Explorar o código

Fixes #7304: Require explicit values for all required choice fields during CSV import

jeremystretch %!s(int64=4) %!d(string=hai) anos
pai
achega
71449b3414

+ 1 - 0
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

+ 0 - 1
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(

+ 4 - 4
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 = {

+ 0 - 6
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'
     )
 

+ 8 - 8
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 = {

+ 4 - 4
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)
 

+ 0 - 1
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(

+ 0 - 1
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(

+ 4 - 4
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 = {