mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-23 04:22:01 -06:00
Add bulk delete view tests
This commit is contained in:
parent
5386ed438e
commit
24ab082674
@ -1129,6 +1129,7 @@ class VirtualChassisTestCase(StandardTestCases.Views):
|
||||
# Disable inapplicable tests
|
||||
test_get_object = None
|
||||
test_import_objects = None
|
||||
test_bulk_delete_objects = None
|
||||
|
||||
# TODO: Requires special form handling
|
||||
test_create_object = None
|
||||
|
@ -107,7 +107,7 @@ class StandardTestCases:
|
||||
self.model._meta.model_name
|
||||
)
|
||||
|
||||
if action in ('list', 'add', 'import'):
|
||||
if action in ('list', 'add', 'import', 'bulk_delete'):
|
||||
return reverse(url_format.format(action))
|
||||
|
||||
elif action in ('get', 'edit', 'delete'):
|
||||
@ -253,3 +253,31 @@ class StandardTestCases:
|
||||
self.assertHttpStatus(response, 200)
|
||||
|
||||
self.assertEqual(self.model.objects.count(), initial_count + len(self.csv_data) - 1)
|
||||
|
||||
@override_settings(EXEMPT_VIEW_PERMISSIONS=[])
|
||||
def test_bulk_delete_objects(self):
|
||||
pk_list = self.model.objects.values_list('pk', flat=True)
|
||||
|
||||
request = {
|
||||
'path': self._get_url('bulk_delete'),
|
||||
'data': {
|
||||
'pk': pk_list,
|
||||
'confirm': True,
|
||||
'_confirm': True, # Form button
|
||||
},
|
||||
'follow': False, # Do not follow 302 redirects
|
||||
}
|
||||
|
||||
# Attempt to make the request without required permissions
|
||||
with disable_warnings('django.request'):
|
||||
self.assertHttpStatus(self.client.post(**request), 403)
|
||||
|
||||
# Assign the required permission and submit again
|
||||
self.add_permissions(
|
||||
'{}.delete_{}'.format(self.model._meta.app_label, self.model._meta.model_name)
|
||||
)
|
||||
response = self.client.post(**request)
|
||||
self.assertHttpStatus(response, 302)
|
||||
|
||||
# Check that all objects were deleted
|
||||
self.assertEqual(self.model.objects.count(), 0)
|
||||
|
Loading…
Reference in New Issue
Block a user