Skip to content

Commit

Permalink
Batching: Rename items_count to total_items
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasgraf committed May 20, 2016
1 parent 6d2893c commit 7585eb7
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 39 deletions.
4 changes: 2 additions & 2 deletions docs/source/_json/batching.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ content-type: application/json
"last": "http://localhost:55001/plone/folder/@search?b_size=5&sort_on=path&b_start=5",
"next": "http://localhost:55001/plone/folder/@search?b_size=5&sort_on=path&b_start=5"
},
"items_count": 8,
"member": [
{
"@id": "http://localhost:55001/plone/folder",
Expand Down Expand Up @@ -44,5 +43,6 @@ content-type: application/json
"description": "",
"title": "Document 4"
}
]
],
"total_items": 8
}
4 changes: 2 additions & 2 deletions docs/source/_json/collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ content-type: application/json
"exclude_from_nav": false,
"expires": null,
"item_count": 30,
"items_count": 3,
"language": "",
"limit": 1000,
"member": [
Expand Down Expand Up @@ -69,5 +68,6 @@ content-type: application/json
"sort_reversed": null,
"subjects": [],
"text": null,
"title": "My Collection"
"title": "My Collection",
"total_items": 3
}
4 changes: 2 additions & 2 deletions docs/source/_json/folder.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ content-type: application/json
"effective": null,
"exclude_from_nav": false,
"expires": null,
"items_count": 2,
"language": "",
"member": [
{
Expand All @@ -51,5 +50,6 @@ content-type: application/json
"relatedItems": [],
"rights": "",
"subjects": [],
"title": "My Folder"
"title": "My Folder",
"total_items": 2
}
4 changes: 2 additions & 2 deletions docs/source/_json/search.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ content-type: application/json
"first": "http://localhost:55001/plone/@search?sort_on=path&b_start=0",
"last": "http://localhost:55001/plone/@search?sort_on=path&b_start=0"
},
"items_count": 2,
"member": [
{
"@id": "http://localhost:55001/plone/front-page",
Expand All @@ -25,5 +24,6 @@ content-type: application/json
"description": "",
"title": "Test Folder"
}
]
],
"total_items": 2
}
16 changes: 8 additions & 8 deletions docs/source/_json/siteroot.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ content-type: application/json
"first": "http://localhost:55001/plone?b_start=0",
"last": "http://localhost:55001/plone?b_start=0"
},
"items_count": 2,
"member": [
{
"@id": "http://localhost:55001/plone/robot-test-folder",
"@type": "Folder",
"description": "",
"title": "Test Folder"
},
{
"@id": "http://localhost:55001/plone/front-page",
"@type": "Document",
"description": "Congratulations! You have successfully installed Plone.",
"title": "Welcome to Plone"
},
{
"@id": "http://localhost:55001/plone/robot-test-folder",
"@type": "Folder",
"description": "",
"title": "Test Folder"
}
],
"parent": {}
"parent": {},
"total_items": 2
}
4 changes: 2 additions & 2 deletions docs/source/batching.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Representations of collection-like resources are batched / paginated:
"prev": "http://.../plone/folder/search?b_size=10&b_start=10",
"next": "http://.../plone/folder/search?b_size=10&b_start=30"
},
"items_count": 175,
"total_items": 175,
"member": [
"..."
]
Expand All @@ -31,7 +31,7 @@ Attribute Description
batching parameters
``member`` Current batch of items / members of the collection-like
resource
``items_count`` Total number of items
``total_items`` Total number of items
``batching`` Batching related navigation links (see below)
================ ===========================================================

Expand Down
2 changes: 1 addition & 1 deletion src/plone/restapi/batching.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __iter__(self):
return iter(self.batch)

@property
def items_count(self):
def total_items(self):
"""Return the number of total items in underlying sequence.
"""
return self.batch.sequence_length
Expand Down
2 changes: 1 addition & 1 deletion src/plone/restapi/search/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def search(self, query=None):

results = {}
results['@id'] = batch.canonical_url
results['items_count'] = batch.items_count
results['total_items'] = batch.total_items
results['batching'] = batch.links

results['member'] = []
Expand Down
2 changes: 1 addition & 1 deletion src/plone/restapi/serializer/atcontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __call__(self):

result = folder_metadata
result['@id'] = batch.canonical_url
result['items_count'] = batch.items_count
result['total_items'] = batch.total_items
result['batching'] = batch.links

result['member'] = [
Expand Down
2 changes: 1 addition & 1 deletion src/plone/restapi/serializer/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __call__(self):

results = collection_metadata
results['@id'] = batch.canonical_url
results['items_count'] = batch.items_count
results['total_items'] = batch.total_items
results['batching'] = batch.links

results['member'] = [
Expand Down
2 changes: 1 addition & 1 deletion src/plone/restapi/serializer/dxcontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def __call__(self):

result = folder_metadata
result['@id'] = batch.canonical_url
result['items_count'] = batch.items_count
result['total_items'] = batch.total_items
result['batching'] = batch.links

result['member'] = [
Expand Down
2 changes: 1 addition & 1 deletion src/plone/restapi/serializer/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __call__(self):
'parent': {},
}

result['items_count'] = batch.items_count
result['total_items'] = batch.total_items
result['batching'] = batch.links

result['member'] = [
Expand Down
26 changes: 13 additions & 13 deletions src/plone/restapi/tests/test_batching.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ def test_total_item_count_is_correct(self):
# Fetch the second page of the batch
response = self.api_session.get('/folder/@search?b_start=2&b_size=2')

# Total count of items should be in items_count
self.assertEqual(6, response.json()['items_count'])
# Total count of items should be in total_items
self.assertEqual(6, response.json()['total_items'])


class TestBatchingCollections(TestBatchingDXBase):
Expand Down Expand Up @@ -168,8 +168,8 @@ def test_total_item_count_is_correct(self):
# Fetch the second page of the batch
response = self.api_session.get('/collection?b_start=2&b_size=2')

# Total count of items should be in items_count
self.assertEqual(6, response.json()['items_count'])
# Total count of items should be in total_items
self.assertEqual(6, response.json()['total_items'])


class TestBatchingDXFolders(TestBatchingDXBase):
Expand Down Expand Up @@ -226,8 +226,8 @@ def test_total_item_count_is_correct(self):
# Fetch the second page of the batch
response = self.api_session.get('/folder?b_start=2&b_size=2')

# Total count of items should be in items_count
self.assertEqual(5, response.json()['items_count'])
# Total count of items should be in total_items
self.assertEqual(5, response.json()['total_items'])


class TestBatchingSiteRoot(TestBatchingDXBase):
Expand Down Expand Up @@ -280,8 +280,8 @@ def test_total_item_count_is_correct(self):
# Fetch the second page of the batch
response = self.api_session.get('/?b_start=2&b_size=2')

# Total count of items should be in items_count
self.assertEqual(5, response.json()['items_count'])
# Total count of items should be in total_items
self.assertEqual(5, response.json()['total_items'])


class TestBatchingArchetypes(unittest.TestCase):
Expand Down Expand Up @@ -356,8 +356,8 @@ def test_total_item_count_is_correct(self):
# Fetch the second page of the batch
response = self.api_session.get('/folder?b_start=2&b_size=2')

# Total count of items should be in items_count
self.assertEqual(5, response.json()['items_count'])
# Total count of items should be in total_items
self.assertEqual(5, response.json()['total_items'])


class TestHypermediaBatch(unittest.TestCase):
Expand All @@ -368,13 +368,13 @@ def setUp(self):
self.portal = self.layer['portal']
self.request = self.portal.REQUEST

def test_items_count(self):
def test_total_items(self):
items = range(1, 26)
self.request.form['b_size'] = 10
batch = HypermediaBatch(self.portal, self.request, items)
# items_count should be total number of items in the sequence
# total_items should be total number of items in the sequence
self.assertEqual(
25, batch.items_count)
25, batch.total_items)

def test_default_batch_size(self):
items = range(1, 27)
Expand Down
4 changes: 2 additions & 2 deletions src/plone/restapi/tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ def test_overall_response_format(self):

results = response.json()
self.assertEqual(
results[u'items_count'],
results[u'total_items'],
len(results[u'member']),
'items_count property should match actual item count.'
'total_items property should match actual item count.'
)

def test_search_on_context_constrains_query_by_path(self):
Expand Down

0 comments on commit 7585eb7

Please sign in to comment.