mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-11 16:53:10 +00:00
Renamed "results" to "items"
This commit is contained in:
parent
c09059cc44
commit
858e97d95d
4 changed files with 44 additions and 44 deletions
|
|
@ -38,6 +38,6 @@ class WagtailPagination(BasePagination):
|
|||
def get_paginated_response(self, data):
|
||||
data = OrderedDict([
|
||||
('total_count', self.total_count),
|
||||
('results', data),
|
||||
('items', data),
|
||||
])
|
||||
return Response(data)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class TestDocumentListing(TestCase):
|
|||
return self.client.get(reverse('wagtailapi_v2:documents:listing'), params)
|
||||
|
||||
def get_document_id_list(self, content):
|
||||
return [document['id'] for document in content['results']]
|
||||
return [document['id'] for document in content['items']]
|
||||
|
||||
|
||||
# BASIC TESTS
|
||||
|
|
@ -36,12 +36,12 @@ class TestDocumentListing(TestCase):
|
|||
self.assertIsInstance(content['total_count'], int)
|
||||
self.assertEqual(content['total_count'], Document.objects.count())
|
||||
|
||||
# Check that the results section is there
|
||||
self.assertIn('results', content)
|
||||
self.assertIsInstance(content['results'], list)
|
||||
# Check that the items section is there
|
||||
self.assertIn('items', content)
|
||||
self.assertIsInstance(content['items'], list)
|
||||
|
||||
# Check that each document has a meta section with type and detail_url attributes
|
||||
for document in content['results']:
|
||||
for document in content['items']:
|
||||
self.assertIn('meta', document)
|
||||
self.assertIsInstance(document['meta'], dict)
|
||||
self.assertEqual(set(document['meta'].keys()), {'type', 'detail_url', 'download_url'})
|
||||
|
|
@ -62,21 +62,21 @@ class TestDocumentListing(TestCase):
|
|||
response = self.get_response()
|
||||
content = json.loads(response.content.decode('UTF-8'))
|
||||
|
||||
for document in content['results']:
|
||||
for document in content['items']:
|
||||
self.assertEqual(set(document.keys()), {'id', 'meta', 'title', 'tags'})
|
||||
|
||||
def test_fields(self):
|
||||
response = self.get_response(fields='title')
|
||||
content = json.loads(response.content.decode('UTF-8'))
|
||||
|
||||
for document in content['results']:
|
||||
for document in content['items']:
|
||||
self.assertEqual(set(document.keys()), {'id', 'meta', 'title'})
|
||||
|
||||
def test_fields_tags(self):
|
||||
response = self.get_response(fields='tags')
|
||||
content = json.loads(response.content.decode('UTF-8'))
|
||||
|
||||
for document in content['results']:
|
||||
for document in content['items']:
|
||||
self.assertIsInstance(document['tags'], list)
|
||||
|
||||
def test_fields_which_are_not_in_api_fields_gives_error(self):
|
||||
|
|
@ -178,11 +178,11 @@ class TestDocumentListing(TestCase):
|
|||
|
||||
# LIMIT
|
||||
|
||||
def test_limit_only_two_results_returned(self):
|
||||
def test_limit_only_two_items_returned(self):
|
||||
response = self.get_response(limit=2)
|
||||
content = json.loads(response.content.decode('UTF-8'))
|
||||
|
||||
self.assertEqual(len(content['results']), 2)
|
||||
self.assertEqual(len(content['items']), 2)
|
||||
|
||||
def test_limit_total_count(self):
|
||||
response = self.get_response(limit=2)
|
||||
|
|
@ -220,7 +220,7 @@ class TestDocumentListing(TestCase):
|
|||
response = self.get_response()
|
||||
content = json.loads(response.content.decode('UTF-8'))
|
||||
|
||||
self.assertEqual(len(content['results']), 2)
|
||||
self.assertEqual(len(content['items']), 2)
|
||||
|
||||
|
||||
# OFFSET
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class TestImageListing(TestCase):
|
|||
return self.client.get(reverse('wagtailapi_v2:images:listing'), params)
|
||||
|
||||
def get_image_id_list(self, content):
|
||||
return [image['id'] for image in content['results']]
|
||||
return [image['id'] for image in content['items']]
|
||||
|
||||
|
||||
# BASIC TESTS
|
||||
|
|
@ -36,12 +36,12 @@ class TestImageListing(TestCase):
|
|||
self.assertIsInstance(content['total_count'], int)
|
||||
self.assertEqual(content['total_count'], get_image_model().objects.count())
|
||||
|
||||
# Check that the results section is there
|
||||
self.assertIn('results', content)
|
||||
self.assertIsInstance(content['results'], list)
|
||||
# Check that the items section is there
|
||||
self.assertIn('items', content)
|
||||
self.assertIsInstance(content['items'], list)
|
||||
|
||||
# Check that each image has a meta section with type and detail_url attributes
|
||||
for image in content['results']:
|
||||
for image in content['items']:
|
||||
self.assertIn('meta', image)
|
||||
self.assertIsInstance(image['meta'], dict)
|
||||
self.assertEqual(set(image['meta'].keys()), {'type', 'detail_url'})
|
||||
|
|
@ -59,21 +59,21 @@ class TestImageListing(TestCase):
|
|||
response = self.get_response()
|
||||
content = json.loads(response.content.decode('UTF-8'))
|
||||
|
||||
for image in content['results']:
|
||||
for image in content['items']:
|
||||
self.assertEqual(set(image.keys()), {'id', 'meta', 'title', 'width', 'height', 'tags'})
|
||||
|
||||
def test_fields(self):
|
||||
response = self.get_response(fields='title,width,height')
|
||||
content = json.loads(response.content.decode('UTF-8'))
|
||||
|
||||
for image in content['results']:
|
||||
for image in content['items']:
|
||||
self.assertEqual(set(image.keys()), {'id', 'meta', 'title', 'width', 'height'})
|
||||
|
||||
def test_fields_tags(self):
|
||||
response = self.get_response(fields='tags')
|
||||
content = json.loads(response.content.decode('UTF-8'))
|
||||
|
||||
for image in content['results']:
|
||||
for image in content['items']:
|
||||
self.assertEqual(set(image.keys()), {'id', 'meta', 'tags'})
|
||||
self.assertIsInstance(image['tags'], list)
|
||||
|
||||
|
|
@ -176,11 +176,11 @@ class TestImageListing(TestCase):
|
|||
|
||||
# LIMIT
|
||||
|
||||
def test_limit_only_two_results_returned(self):
|
||||
def test_limit_only_two_items_returned(self):
|
||||
response = self.get_response(limit=2)
|
||||
content = json.loads(response.content.decode('UTF-8'))
|
||||
|
||||
self.assertEqual(len(content['results']), 2)
|
||||
self.assertEqual(len(content['items']), 2)
|
||||
|
||||
def test_limit_total_count(self):
|
||||
response = self.get_response(limit=2)
|
||||
|
|
@ -218,7 +218,7 @@ class TestImageListing(TestCase):
|
|||
response = self.get_response()
|
||||
content = json.loads(response.content.decode('UTF-8'))
|
||||
|
||||
self.assertEqual(len(content['results']), 2)
|
||||
self.assertEqual(len(content['items']), 2)
|
||||
|
||||
|
||||
# OFFSET
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class TestPageListing(TestCase):
|
|||
return self.client.get(reverse('wagtailapi_v2:pages:listing'), params)
|
||||
|
||||
def get_page_id_list(self, content):
|
||||
return [page['id'] for page in content['results']]
|
||||
return [page['id'] for page in content['items']]
|
||||
|
||||
|
||||
# BASIC TESTS
|
||||
|
|
@ -45,12 +45,12 @@ class TestPageListing(TestCase):
|
|||
self.assertIsInstance(content['total_count'], int)
|
||||
self.assertEqual(content['total_count'], get_total_page_count())
|
||||
|
||||
# Check that the results section is there
|
||||
self.assertIn('results', content)
|
||||
self.assertIsInstance(content['results'], list)
|
||||
# Check that the items section is there
|
||||
self.assertIn('items', content)
|
||||
self.assertIsInstance(content['items'], list)
|
||||
|
||||
# Check that each page has a meta section with type, detail_url and html_url attributes
|
||||
for page in content['results']:
|
||||
for page in content['items']:
|
||||
self.assertIn('meta', page)
|
||||
self.assertIsInstance(page['meta'], dict)
|
||||
self.assertEqual(set(page['meta'].keys()), {'type', 'detail_url', 'html_url'})
|
||||
|
|
@ -81,11 +81,11 @@ class TestPageListing(TestCase):
|
|||
|
||||
# TYPE FILTER
|
||||
|
||||
def test_type_filter_results_are_all_blog_entries(self):
|
||||
def test_type_filter_items_are_all_blog_entries(self):
|
||||
response = self.get_response(type='demosite.BlogEntryPage')
|
||||
content = json.loads(response.content.decode('UTF-8'))
|
||||
|
||||
for page in content['results']:
|
||||
for page in content['items']:
|
||||
self.assertEqual(page['meta']['type'], 'demosite.BlogEntryPage')
|
||||
|
||||
# All fields in specific type available
|
||||
|
|
@ -95,7 +95,7 @@ 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 results
|
||||
# Total count must be reduced as this filters the items
|
||||
self.assertEqual(content['total_count'], 3)
|
||||
|
||||
def test_type_filter_multiple(self):
|
||||
|
|
@ -105,7 +105,7 @@ class TestPageListing(TestCase):
|
|||
blog_page_seen = False
|
||||
event_page_seen = False
|
||||
|
||||
for page in content['results']:
|
||||
for page in content['items']:
|
||||
self.assertIn(page['meta']['type'], ['demosite.BlogEntryPage', 'demosite.EventPage'])
|
||||
|
||||
if page['meta']['type'] == 'demosite.BlogEntryPage':
|
||||
|
|
@ -116,8 +116,8 @@ class TestPageListing(TestCase):
|
|||
# Only generic fields available
|
||||
self.assertEqual(set(page.keys()), {'id', 'meta', 'title', 'slug', 'show_in_menus', 'seo_title', 'search_description', 'first_published_at'})
|
||||
|
||||
self.assertTrue(blog_page_seen, "No blog pages were found in the results")
|
||||
self.assertTrue(event_page_seen, "No event pages were found in the results")
|
||||
self.assertTrue(blog_page_seen, "No blog pages were found in the items")
|
||||
self.assertTrue(event_page_seen, "No event pages were found in the items")
|
||||
|
||||
def test_non_existant_type_gives_error(self):
|
||||
response = self.get_response(type='demosite.IDontExist')
|
||||
|
|
@ -139,21 +139,21 @@ class TestPageListing(TestCase):
|
|||
response = self.get_response(type='demosite.BlogEntryPage')
|
||||
content = json.loads(response.content.decode('UTF-8'))
|
||||
|
||||
for page in content['results']:
|
||||
for page in content['items']:
|
||||
self.assertEqual(set(page.keys()), {'id', 'meta', 'title', 'slug', 'show_in_menus', 'seo_title', 'search_description', 'first_published_at', 'date', 'related_links', 'feed_image', 'body', 'carousel_items', 'tags'})
|
||||
|
||||
def test_fields(self):
|
||||
response = self.get_response(type='demosite.BlogEntryPage', fields='title,date,feed_image')
|
||||
content = json.loads(response.content.decode('UTF-8'))
|
||||
|
||||
for page in content['results']:
|
||||
for page in content['items']:
|
||||
self.assertEqual(set(page.keys()), {'id', 'meta', 'title', 'date', 'feed_image'})
|
||||
|
||||
def test_fields_child_relation(self):
|
||||
response = self.get_response(type='demosite.BlogEntryPage', fields='title,related_links')
|
||||
content = json.loads(response.content.decode('UTF-8'))
|
||||
|
||||
for page in content['results']:
|
||||
for page in content['items']:
|
||||
self.assertEqual(set(page.keys()), {'id', 'meta', 'title', 'related_links'})
|
||||
self.assertIsInstance(page['related_links'], list)
|
||||
|
||||
|
|
@ -161,7 +161,7 @@ class TestPageListing(TestCase):
|
|||
response = self.get_response(type='demosite.BlogEntryPage', fields='title,date,feed_image')
|
||||
content = json.loads(response.content.decode('UTF-8'))
|
||||
|
||||
for page in content['results']:
|
||||
for page in content['items']:
|
||||
feed_image = page['feed_image']
|
||||
|
||||
if feed_image is not None:
|
||||
|
|
@ -177,7 +177,7 @@ class TestPageListing(TestCase):
|
|||
response = self.get_response(type='demosite.BlogEntryPage', fields='tags')
|
||||
content = json.loads(response.content.decode('UTF-8'))
|
||||
|
||||
for page in content['results']:
|
||||
for page in content['items']:
|
||||
self.assertEqual(set(page.keys()), {'id', 'meta', 'tags'})
|
||||
self.assertIsInstance(page['tags'], list)
|
||||
|
||||
|
|
@ -197,7 +197,7 @@ class TestPageListing(TestCase):
|
|||
'feed_image',
|
||||
'related_links',
|
||||
]
|
||||
self.assertEqual(list(content['results'][0].keys()), field_order)
|
||||
self.assertEqual(list(content['items'][0].keys()), field_order)
|
||||
|
||||
def test_fields_without_type_gives_error(self):
|
||||
response = self.get_response(fields='title,related_links')
|
||||
|
|
@ -437,11 +437,11 @@ class TestPageListing(TestCase):
|
|||
|
||||
# LIMIT
|
||||
|
||||
def test_limit_only_two_results_returned(self):
|
||||
def test_limit_only_two_items_returned(self):
|
||||
response = self.get_response(limit=2)
|
||||
content = json.loads(response.content.decode('UTF-8'))
|
||||
|
||||
self.assertEqual(len(content['results']), 2)
|
||||
self.assertEqual(len(content['items']), 2)
|
||||
|
||||
def test_limit_total_count(self):
|
||||
response = self.get_response(limit=2)
|
||||
|
|
@ -479,7 +479,7 @@ class TestPageListing(TestCase):
|
|||
response = self.get_response()
|
||||
content = json.loads(response.content.decode('UTF-8'))
|
||||
|
||||
self.assertEqual(len(content['results']), 2)
|
||||
self.assertEqual(len(content['items']), 2)
|
||||
|
||||
|
||||
# OFFSET
|
||||
|
|
@ -519,7 +519,7 @@ class TestPageListing(TestCase):
|
|||
|
||||
page_id_list = self.get_page_id_list(content)
|
||||
|
||||
# Check that the results are the blog index and three blog pages
|
||||
# Check that the items are the blog index and three blog pages
|
||||
self.assertEqual(set(page_id_list), set([5, 16, 18, 19]))
|
||||
|
||||
def test_search_with_type(self):
|
||||
|
|
|
|||
Loading…
Reference in a new issue