def test_slicing_queryset_smaller_than_chunk_size(self): """Test if slicing a queryset smaller than the specified chunk size.""" # Get a queryset of all 22 cars queryset = Car.objects.all() self.assertEqual(queryset.count(), 22) # Slice the queryset into chunks of 30 slices = slice_queryset(queryset, 30) # First slice should have all 22 cars for queryset in slices: self.assertEqual(queryset.count(), 22)
def test_slice_queryset(self): """Test if the `slice_queryset` works as expected.""" # Get a queryset of all 22 cars queryset = Car.objects.all() self.assertEqual(queryset.count(), 22) # Slice the queryset into chunks of 5 slices = slice_queryset(queryset, 5) # First 4 chunks should have 5 cars in each queryset # and the last chunk should have 2 cars. for index, queryset in enumerate(slices): if index < 4: self.assertEqual(queryset.count(), 5) else: self.assertEqual(queryset.count(), 2)
def _get_sliced_queryset(self): """Return the sliced queryset.""" chunk_size = apps.get_app_config('django_elastic_appsearch').chunk_size return slice_queryset(self, chunk_size)