Add bulk delete view tests

This commit is contained in:
Jeremy Stretch 2020-02-03 10:04:09 -05:00
parent 5386ed438e
commit 24ab082674
2 changed files with 30 additions and 1 deletions

View File

@ -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

View File

@ -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)