mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-24 08:25:17 -06:00
fix tests for csv import #13239
This commit is contained in:
parent
74f3cd7466
commit
f0560a9b07
@ -12,6 +12,7 @@ from dcim.models import Manufacturer, Rack, Site
|
|||||||
from extras.choices import *
|
from extras.choices import *
|
||||||
from extras.models import CustomField
|
from extras.models import CustomField
|
||||||
from ipam.models import VLAN
|
from ipam.models import VLAN
|
||||||
|
from utilities.choices import CSVDelimiterChoices, ImportFormatChoices
|
||||||
from utilities.testing import APITestCase, TestCase
|
from utilities.testing import APITestCase, TestCase
|
||||||
from virtualization.models import VirtualMachine
|
from virtualization.models import VirtualMachine
|
||||||
|
|
||||||
@ -1057,7 +1058,7 @@ class CustomFieldImportTest(TestCase):
|
|||||||
)
|
)
|
||||||
csv_data = '\n'.join(','.join(row) for row in data)
|
csv_data = '\n'.join(','.join(row) for row in data)
|
||||||
|
|
||||||
response = self.client.post(reverse('dcim:site_import'), {'data': csv_data, 'format': 'csv'})
|
response = self.client.post(reverse('dcim:site_import'), {'data': csv_data, 'format': ImportFormatChoices.CSV, 'csv_delimiter': CSVDelimiterChoices.AUTO,})
|
||||||
self.assertEqual(response.status_code, 302)
|
self.assertEqual(response.status_code, 302)
|
||||||
self.assertEqual(Site.objects.count(), 3)
|
self.assertEqual(Site.objects.count(), 3)
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ class BulkImportForm(BootstrapMixin, SyncedDataMixin, forms.Form):
|
|||||||
'format': _('Unable to detect data format. Please specify.')
|
'format': _('Unable to detect data format. Please specify.')
|
||||||
})
|
})
|
||||||
|
|
||||||
def _clean_csv(self, data, delimiter=None):
|
def _clean_csv(self, data, delimiter=CSVDelimiterChoices.AUTO):
|
||||||
"""
|
"""
|
||||||
Clean CSV-formatted data. The first row will be treated as column headers.
|
Clean CSV-formatted data. The first row will be treated as column headers.
|
||||||
"""
|
"""
|
||||||
|
@ -10,7 +10,7 @@ from extras.choices import ObjectChangeActionChoices
|
|||||||
from extras.models import ObjectChange
|
from extras.models import ObjectChange
|
||||||
from netbox.models.features import ChangeLoggingMixin
|
from netbox.models.features import ChangeLoggingMixin
|
||||||
from users.models import ObjectPermission
|
from users.models import ObjectPermission
|
||||||
from utilities.choices import ImportFormatChoices
|
from utilities.choices import CSVDelimiterChoices, ImportFormatChoices
|
||||||
from .base import ModelTestCase
|
from .base import ModelTestCase
|
||||||
from .utils import disable_warnings, post_data
|
from .utils import disable_warnings, post_data
|
||||||
|
|
||||||
@ -559,7 +559,8 @@ class ViewTestCases:
|
|||||||
def test_bulk_import_objects_without_permission(self):
|
def test_bulk_import_objects_without_permission(self):
|
||||||
data = {
|
data = {
|
||||||
'data': self._get_csv_data(),
|
'data': self._get_csv_data(),
|
||||||
'format': 'csv',
|
'format': ImportFormatChoices.CSV,
|
||||||
|
'csv_delimiter': CSVDelimiterChoices.AUTO,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Test GET without permission
|
# Test GET without permission
|
||||||
@ -576,7 +577,8 @@ class ViewTestCases:
|
|||||||
initial_count = self._get_queryset().count()
|
initial_count = self._get_queryset().count()
|
||||||
data = {
|
data = {
|
||||||
'data': self._get_csv_data(),
|
'data': self._get_csv_data(),
|
||||||
'format': 'csv',
|
'format': ImportFormatChoices.CSV,
|
||||||
|
'csv_delimiter': CSVDelimiterChoices.AUTO,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Assign model-level permission
|
# Assign model-level permission
|
||||||
@ -605,6 +607,7 @@ class ViewTestCases:
|
|||||||
data = {
|
data = {
|
||||||
'format': ImportFormatChoices.CSV,
|
'format': ImportFormatChoices.CSV,
|
||||||
'data': csv_data,
|
'data': csv_data,
|
||||||
|
'csv_delimiter': CSVDelimiterChoices.AUTO,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Assign model-level permission
|
# Assign model-level permission
|
||||||
@ -637,7 +640,8 @@ class ViewTestCases:
|
|||||||
initial_count = self._get_queryset().count()
|
initial_count = self._get_queryset().count()
|
||||||
data = {
|
data = {
|
||||||
'data': self._get_csv_data(),
|
'data': self._get_csv_data(),
|
||||||
'format': 'csv',
|
'format': ImportFormatChoices.CSV,
|
||||||
|
'csv_delimiter': CSVDelimiterChoices.AUTO,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Assign constrained permission
|
# Assign constrained permission
|
||||||
|
Loading…
Reference in New Issue
Block a user