Skip to content

Commit

Permalink
feat(api/2): Removed meta from top of listings
Browse files Browse the repository at this point in the history
  • Loading branch information
kaedroho committed Feb 8, 2016
1 parent 3536a80 commit fb61033
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 33 deletions.
4 changes: 1 addition & 3 deletions wagtail/api/v2/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ def paginate_queryset(self, queryset, request, view=None):

def get_paginated_response(self, data):
data = OrderedDict([
('meta', OrderedDict([
('total_count', self.total_count),
])),
('total_count', self.total_count),
(self.view.name, data),
])
return Response(data)
14 changes: 5 additions & 9 deletions wagtail/api/v2/tests/test_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,10 @@ def test_basic(self):
# 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['meta'])
self.assertIsInstance(content['meta']['total_count'], int)
self.assertEqual(content['meta']['total_count'], Document.objects.count())
self.assertIn('total_count', content)
self.assertIsInstance(content['total_count'], int)
self.assertEqual(content['total_count'], Document.objects.count())

# Check that the documents section is there
self.assertIn('documents', content)
Expand Down Expand Up @@ -193,7 +189,7 @@ def test_limit_total_count(self):
content = json.loads(response.content.decode('UTF-8'))

# The total count must not be affected by "limit"
self.assertEqual(content['meta']['total_count'], Document.objects.count())
self.assertEqual(content['total_count'], Document.objects.count())

def test_limit_not_integer_gives_error(self):
response = self.get_response(limit='abc')
Expand Down Expand Up @@ -246,7 +242,7 @@ def test_offset_total_count(self):
content = json.loads(response.content.decode('UTF-8'))

# The total count must not be affected by "offset"
self.assertEqual(content['meta']['total_count'], Document.objects.count())
self.assertEqual(content['total_count'], Document.objects.count())

def test_offset_not_integer_gives_error(self):
response = self.get_response(offset='abc')
Expand Down
14 changes: 5 additions & 9 deletions wagtail/api/v2/tests/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,10 @@ def test_basic(self):
# 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['meta'])
self.assertIsInstance(content['meta']['total_count'], int)
self.assertEqual(content['meta']['total_count'], get_image_model().objects.count())
self.assertIn('total_count', content)
self.assertIsInstance(content['total_count'], int)
self.assertEqual(content['total_count'], get_image_model().objects.count())

# Check that the images section is there
self.assertIn('images', content)
Expand Down Expand Up @@ -191,7 +187,7 @@ def test_limit_total_count(self):
content = json.loads(response.content.decode('UTF-8'))

# The total count must not be affected by "limit"
self.assertEqual(content['meta']['total_count'], get_image_model().objects.count())
self.assertEqual(content['total_count'], get_image_model().objects.count())

def test_limit_not_integer_gives_error(self):
response = self.get_response(limit='abc')
Expand Down Expand Up @@ -244,7 +240,7 @@ def test_offset_total_count(self):
content = json.loads(response.content.decode('UTF-8'))

# The total count must not be affected by "offset"
self.assertEqual(content['meta']['total_count'], get_image_model().objects.count())
self.assertEqual(content['total_count'], get_image_model().objects.count())

def test_offset_not_integer_gives_error(self):
response = self.get_response(offset='abc')
Expand Down
20 changes: 8 additions & 12 deletions wagtail/api/v2/tests/test_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,10 @@ def test_basic(self):
# 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['meta'])
self.assertIsInstance(content['meta']['total_count'], int)
self.assertEqual(content['meta']['total_count'], get_total_page_count())
self.assertIn('total_count', content)
self.assertIsInstance(content['total_count'], int)
self.assertEqual(content['total_count'], get_total_page_count())

# Check that the pages section is there
self.assertIn('pages', content)
Expand All @@ -67,7 +63,7 @@ def test_unpublished_pages_dont_appear_in_list(self):

response = self.get_response()
content = json.loads(response.content.decode('UTF-8'))
self.assertEqual(content['meta']['total_count'], total_count - 1)
self.assertEqual(content['total_count'], total_count - 1)

def test_private_pages_dont_appear_in_list(self):
total_count = get_total_page_count()
Expand All @@ -80,7 +76,7 @@ def test_private_pages_dont_appear_in_list(self):

response = self.get_response()
content = json.loads(response.content.decode('UTF-8'))
self.assertEqual(content['meta']['total_count'], new_total_count)
self.assertEqual(content['total_count'], new_total_count)


# TYPE FILTER
Expand All @@ -97,7 +93,7 @@ def test_type_filter_total_count(self):
content = json.loads(response.content.decode('UTF-8'))

# Total count must be reduced as this filters the results
self.assertEqual(content['meta']['total_count'], 3)
self.assertEqual(content['total_count'], 3)

def test_non_existant_type_gives_error(self):
response = self.get_response(type='demosite.IDontExist')
Expand Down Expand Up @@ -428,7 +424,7 @@ def test_limit_total_count(self):
content = json.loads(response.content.decode('UTF-8'))

# The total count must not be affected by "limit"
self.assertEqual(content['meta']['total_count'], get_total_page_count())
self.assertEqual(content['total_count'], get_total_page_count())

def test_limit_not_integer_gives_error(self):
response = self.get_response(limit='abc')
Expand Down Expand Up @@ -481,7 +477,7 @@ def test_offset_total_count(self):
content = json.loads(response.content.decode('UTF-8'))

# The total count must not be affected by "offset"
self.assertEqual(content['meta']['total_count'], get_total_page_count())
self.assertEqual(content['total_count'], get_total_page_count())

def test_offset_not_integer_gives_error(self):
response = self.get_response(offset='abc')
Expand Down

0 comments on commit fb61033

Please sign in to comment.