diff --git a/wagtail/api/v2/pagination.py b/wagtail/api/v2/pagination.py index 3e935212d..c495b1614 100644 --- a/wagtail/api/v2/pagination.py +++ b/wagtail/api/v2/pagination.py @@ -37,7 +37,9 @@ class WagtailPagination(BasePagination): def get_paginated_response(self, data): data = OrderedDict([ - ('total_count', self.total_count), + ('meta', OrderedDict([ + ('total_count', self.total_count), + ])), ('items', data), ]) return Response(data) diff --git a/wagtail/api/v2/tests/test_documents.py b/wagtail/api/v2/tests/test_documents.py index 00c55eb57..7a88d8c91 100644 --- a/wagtail/api/v2/tests/test_documents.py +++ b/wagtail/api/v2/tests/test_documents.py @@ -31,10 +31,14 @@ class TestDocumentListing(TestCase): # Will crash if the JSON is invalid content = json.loads(response.content.decode('UTF-8')) + # Check that the meta section is there + self.assertIn('meta', content) + self.assertIsInstance(content['meta'], dict) + # Check that the total count is there and correct - self.assertIn('total_count', content) - self.assertIsInstance(content['total_count'], int) - self.assertEqual(content['total_count'], Document.objects.count()) + self.assertIn('total_count', content['meta']) + self.assertIsInstance(content['meta']['total_count'], int) + self.assertEqual(content['meta']['total_count'], Document.objects.count()) # Check that the items section is there self.assertIn('items', content) @@ -189,7 +193,7 @@ class TestDocumentListing(TestCase): content = json.loads(response.content.decode('UTF-8')) # The total count must not be affected by "limit" - self.assertEqual(content['total_count'], Document.objects.count()) + self.assertEqual(content['meta']['total_count'], Document.objects.count()) def test_limit_not_integer_gives_error(self): response = self.get_response(limit='abc') @@ -242,7 +246,7 @@ class TestDocumentListing(TestCase): content = json.loads(response.content.decode('UTF-8')) # The total count must not be affected by "offset" - self.assertEqual(content['total_count'], Document.objects.count()) + self.assertEqual(content['meta']['total_count'], Document.objects.count()) def test_offset_not_integer_gives_error(self): response = self.get_response(offset='abc') diff --git a/wagtail/api/v2/tests/test_images.py b/wagtail/api/v2/tests/test_images.py index f305d243e..dda6da8d8 100644 --- a/wagtail/api/v2/tests/test_images.py +++ b/wagtail/api/v2/tests/test_images.py @@ -31,10 +31,14 @@ class TestImageListing(TestCase): # Will crash if the JSON is invalid content = json.loads(response.content.decode('UTF-8')) + # Check that the meta section is there + self.assertIn('meta', content) + self.assertIsInstance(content['meta'], dict) + # Check that the total count is there and correct - self.assertIn('total_count', content) - self.assertIsInstance(content['total_count'], int) - self.assertEqual(content['total_count'], get_image_model().objects.count()) + self.assertIn('total_count', content['meta']) + self.assertIsInstance(content['meta']['total_count'], int) + self.assertEqual(content['meta']['total_count'], get_image_model().objects.count()) # Check that the items section is there self.assertIn('items', content) @@ -187,7 +191,7 @@ class TestImageListing(TestCase): content = json.loads(response.content.decode('UTF-8')) # The total count must not be affected by "limit" - self.assertEqual(content['total_count'], get_image_model().objects.count()) + self.assertEqual(content['meta']['total_count'], get_image_model().objects.count()) def test_limit_not_integer_gives_error(self): response = self.get_response(limit='abc') @@ -240,7 +244,7 @@ class TestImageListing(TestCase): content = json.loads(response.content.decode('UTF-8')) # The total count must not be affected by "offset" - self.assertEqual(content['total_count'], get_image_model().objects.count()) + self.assertEqual(content['meta']['total_count'], get_image_model().objects.count()) def test_offset_not_integer_gives_error(self): response = self.get_response(offset='abc') diff --git a/wagtail/api/v2/tests/test_pages.py b/wagtail/api/v2/tests/test_pages.py index e4b06efe3..ab61df6f5 100644 --- a/wagtail/api/v2/tests/test_pages.py +++ b/wagtail/api/v2/tests/test_pages.py @@ -40,10 +40,14 @@ class TestPageListing(TestCase): # Will crash if the JSON is invalid content = json.loads(response.content.decode('UTF-8')) + # Check that the meta section is there + self.assertIn('meta', content) + self.assertIsInstance(content['meta'], dict) + # Check that the total count is there and correct - self.assertIn('total_count', content) - self.assertIsInstance(content['total_count'], int) - self.assertEqual(content['total_count'], get_total_page_count()) + self.assertIn('total_count', content['meta']) + self.assertIsInstance(content['meta']['total_count'], int) + self.assertEqual(content['meta']['total_count'], get_total_page_count()) # Check that the items section is there self.assertIn('items', content) @@ -63,7 +67,7 @@ class TestPageListing(TestCase): response = self.get_response() content = json.loads(response.content.decode('UTF-8')) - self.assertEqual(content['total_count'], total_count - 1) + self.assertEqual(content['meta']['total_count'], total_count - 1) def test_private_pages_dont_appear_in_list(self): total_count = get_total_page_count() @@ -76,7 +80,7 @@ class TestPageListing(TestCase): response = self.get_response() content = json.loads(response.content.decode('UTF-8')) - self.assertEqual(content['total_count'], new_total_count) + self.assertEqual(content['meta']['total_count'], new_total_count) # TYPE FILTER @@ -95,8 +99,8 @@ class TestPageListing(TestCase): response = self.get_response(type='demosite.BlogEntryPage') content = json.loads(response.content.decode('UTF-8')) - # Total count must be reduced as this filters the items - self.assertEqual(content['total_count'], 3) + # Total count must be reduced as this filters the results + self.assertEqual(content['meta']['total_count'], 3) def test_type_filter_multiple(self): response = self.get_response(type='demosite.BlogEntryPage,demosite.EventPage') @@ -448,7 +452,7 @@ class TestPageListing(TestCase): content = json.loads(response.content.decode('UTF-8')) # The total count must not be affected by "limit" - self.assertEqual(content['total_count'], get_total_page_count()) + self.assertEqual(content['meta']['total_count'], get_total_page_count()) def test_limit_not_integer_gives_error(self): response = self.get_response(limit='abc') @@ -501,7 +505,7 @@ class TestPageListing(TestCase): content = json.loads(response.content.decode('UTF-8')) # The total count must not be affected by "offset" - self.assertEqual(content['total_count'], get_total_page_count()) + self.assertEqual(content['meta']['total_count'], get_total_page_count()) def test_offset_not_integer_gives_error(self): response = self.get_response(offset='abc')