From 4df6915a0ca0ddca87bb8e1e1d256e3fe0712207 Mon Sep 17 00:00:00 2001
From: Valentin Rigal <rigal@teklia.com>
Date: Mon, 19 Oct 2020 23:10:30 +0200
Subject: [PATCH] Remove with count validation

---
 arkindex/dataimport/tests/test_process_elements.py | 5 +++--
 arkindex/project/mixins.py                         | 7 ++-----
 arkindex/project/pagination.py                     | 2 +-
 3 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/arkindex/dataimport/tests/test_process_elements.py b/arkindex/dataimport/tests/test_process_elements.py
index fcebe11640..80e3cb7240 100644
--- a/arkindex/dataimport/tests/test_process_elements.py
+++ b/arkindex/dataimport/tests/test_process_elements.py
@@ -679,7 +679,7 @@ class TestProcessElements(FixtureAPITestCase):
 
     def test_elements_count(self):
         """
-        Elements count can be retrieved when no cursor is set
+        Elements count can be retrieved with with_count parameter
         """
         self.client.force_login(self.superuser)
         with self.assertNumQueries(7):
@@ -697,7 +697,8 @@ class TestProcessElements(FixtureAPITestCase):
 
         second_page = self.client.get(next_url)
         data = second_page.json()
-        self.assertIsNone(data['count'])
+        # Count should be present in the next URL
+        self.assertEqual(data['count'], 12)
         self.assertIsNone(data['next'])
         self.assertEqual(len(data['results']), 6)
 
diff --git a/arkindex/project/mixins.py b/arkindex/project/mixins.py
index 8ce92cc564..94c5d0b982 100644
--- a/arkindex/project/mixins.py
+++ b/arkindex/project/mixins.py
@@ -164,7 +164,7 @@ class CachedViewMixin(object):
 class CustomPaginationViewMixin(object):
     """
     A custom cursor pagination mixin
-    Elements count can be retrieved with the `with_count` parameter if there is no cursor
+    Elements count can be retrieved with the `with_count` parameter
     """
     pagination_class = CustomCursorPagination
 
@@ -172,9 +172,6 @@ class CustomPaginationViewMixin(object):
     def paginator(self):
         if not hasattr(self, '_paginator'):
             params = self.request.query_params
-            with_count = (
-                not params.get('cursor')
-                and params.get('with_count') not in (None, '', 'false', '0')
-            )
+            with_count = params.get('with_count') not in (None, '', 'false', '0')
             self._paginator = self.pagination_class(with_count=with_count)
         return self._paginator
diff --git a/arkindex/project/pagination.py b/arkindex/project/pagination.py
index d88073ccea..14929b2bae 100644
--- a/arkindex/project/pagination.py
+++ b/arkindex/project/pagination.py
@@ -62,7 +62,7 @@ class CustomCursorPagination(pagination.CursorPagination):
             'name': 'with_count',
             'required': False,
             'in': 'query',
-            'description': 'Count the total number of elements. Incompatible with `cursor` parameter.',
+            'description': 'Count the total number of elements.',
             'schema': {
                 'type': 'boolean',
             }
-- 
GitLab