mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
committed by
Jeremy Stretch
parent
fc482ed096
commit
a864e8127b
@ -198,8 +198,12 @@ def parse_csv(reader):
|
|||||||
header = header.strip()
|
header = header.strip()
|
||||||
if '.' in header:
|
if '.' in header:
|
||||||
field, to_field = header.split('.', 1)
|
field, to_field = header.split('.', 1)
|
||||||
|
if field in headers:
|
||||||
|
raise forms.ValidationError(f'Duplicate or conflicting column header for "{field}"')
|
||||||
headers[field] = to_field
|
headers[field] = to_field
|
||||||
else:
|
else:
|
||||||
|
if header in headers:
|
||||||
|
raise forms.ValidationError(f'Duplicate or conflicting column header for "{header}"')
|
||||||
headers[header] = None
|
headers[header] = None
|
||||||
|
|
||||||
# Parse CSV rows into a list of dictionaries mapped from the column headers.
|
# Parse CSV rows into a list of dictionaries mapped from the column headers.
|
||||||
|
@ -319,6 +319,22 @@ class CSVDataFieldTest(TestCase):
|
|||||||
with self.assertRaises(forms.ValidationError):
|
with self.assertRaises(forms.ValidationError):
|
||||||
self.field.clean(input)
|
self.field.clean(input)
|
||||||
|
|
||||||
|
def test_duplicate_header(self):
|
||||||
|
input = """
|
||||||
|
status,status
|
||||||
|
Active,Active
|
||||||
|
"""
|
||||||
|
with self.assertRaisesRegex(forms.ValidationError, 'Duplicate'):
|
||||||
|
self.field.clean(input)
|
||||||
|
|
||||||
|
def test_duplicate_header_key(self):
|
||||||
|
input = """
|
||||||
|
vrf.name,vrf.rd
|
||||||
|
Test VRF,123:456
|
||||||
|
"""
|
||||||
|
with self.assertRaisesRegex(forms.ValidationError, 'Duplicate'):
|
||||||
|
self.field.clean(input)
|
||||||
|
|
||||||
def test_clean_default_to_field(self):
|
def test_clean_default_to_field(self):
|
||||||
input = """
|
input = """
|
||||||
address,status,vrf.name
|
address,status,vrf.name
|
||||||
|
Reference in New Issue
Block a user