mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 18:08:38 -06:00
Add test for bulk API deletions
This commit is contained in:
parent
6694ec78bc
commit
eba2ea06ff
@ -300,6 +300,29 @@ class APIViewTestCases:
|
|||||||
self.assertHttpStatus(response, status.HTTP_204_NO_CONTENT)
|
self.assertHttpStatus(response, status.HTTP_204_NO_CONTENT)
|
||||||
self.assertFalse(self._get_queryset().filter(pk=instance.pk).exists())
|
self.assertFalse(self._get_queryset().filter(pk=instance.pk).exists())
|
||||||
|
|
||||||
|
def test_bulk_delete_objects(self):
|
||||||
|
"""
|
||||||
|
DELETE a set of objects in a single request.
|
||||||
|
"""
|
||||||
|
# Add object-level permission
|
||||||
|
obj_perm = ObjectPermission(
|
||||||
|
actions=['delete']
|
||||||
|
)
|
||||||
|
obj_perm.save()
|
||||||
|
obj_perm.users.add(self.user)
|
||||||
|
obj_perm.object_types.add(ContentType.objects.get_for_model(self.model))
|
||||||
|
|
||||||
|
# Target the three most recently created objects to avoid triggering recursive deletions
|
||||||
|
# (e.g. with MPTT objects)
|
||||||
|
id_list = self._get_queryset().order_by('-id').values_list('id', flat=True)[:3]
|
||||||
|
self.assertEqual(len(id_list), 3, "Insufficient number of objects to test bulk deletion")
|
||||||
|
data = [{"id": id} for id in id_list]
|
||||||
|
|
||||||
|
initial_count = self._get_queryset().count()
|
||||||
|
response = self.client.delete(self._get_list_url(), data, format='json', **self.header)
|
||||||
|
self.assertHttpStatus(response, status.HTTP_204_NO_CONTENT)
|
||||||
|
self.assertEqual(self._get_queryset().count(), initial_count - 3)
|
||||||
|
|
||||||
class APIViewTestCase(
|
class APIViewTestCase(
|
||||||
GetObjectViewTestCase,
|
GetObjectViewTestCase,
|
||||||
ListObjectsViewTestCase,
|
ListObjectsViewTestCase,
|
||||||
|
Loading…
Reference in New Issue
Block a user