mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-23 16:06:43 -06:00
Add test for CSV import header validation
This commit is contained in:
parent
06cb1400d0
commit
a64832ade3
@ -17,6 +17,36 @@ class CSVImportTestCase(ModelViewTestCase):
|
||||
def _get_csv_data(self, csv_data):
|
||||
return '\n'.join(csv_data)
|
||||
|
||||
def test_invalid_headers(self):
|
||||
"""
|
||||
Test that import form validation fails when an unknown CSV header is present.
|
||||
"""
|
||||
self.add_permissions('dcim.add_region')
|
||||
|
||||
csv_data = [
|
||||
'name,slug,INVALIDHEADER',
|
||||
'Region 1,region-1,abc',
|
||||
'Region 2,region-2,def',
|
||||
'Region 3,region-3,ghi',
|
||||
]
|
||||
data = {
|
||||
'format': ImportFormatChoices.CSV,
|
||||
'data': self._get_csv_data(csv_data),
|
||||
'csv_delimiter': CSVDelimiterChoices.AUTO,
|
||||
}
|
||||
|
||||
# Form validation should fail with invalid header present
|
||||
self.assertHttpStatus(self.client.post(self._get_url('import'), data), 200)
|
||||
self.assertEqual(Region.objects.count(), 0)
|
||||
|
||||
# Correct the CSV header name
|
||||
csv_data[0] = 'name,slug,description'
|
||||
data['data'] = self._get_csv_data(csv_data)
|
||||
|
||||
# Validation should succeed
|
||||
self.assertHttpStatus(self.client.post(self._get_url('import'), data), 302)
|
||||
self.assertEqual(Region.objects.count(), 3)
|
||||
|
||||
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
|
||||
def test_valid_tags(self):
|
||||
csv_data = (
|
||||
|
Loading…
Reference in New Issue
Block a user