Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
Support '/_search_disk_size' search endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
smithsz authored and ricellis committed Feb 15, 2018
1 parent d9ed603 commit 0ea7188
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# 2.8.0 (Unreleased)

- [NEW] Added support for `/_search_disk_size` endpoint which retrieves disk size information for a specific search index.
- [FIXED] Updated default IBM Cloud Identity and Access Management token URL.
- [REMOVED] Removed broken source and target parameters that constantly threw `AttributeError` when creating a replication document.

Expand Down
12 changes: 12 additions & 0 deletions src/cloudant/design_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,3 +699,15 @@ def search_info(self, search_index):
'/'.join([self.document_url, '_search_info', search_index]))
ddoc_search_info.raise_for_status()
return ddoc_search_info.json()

def search_disk_size(self, search_index):
"""
Retrieves disk size information about a specified search index within
the design document, returns dictionary
GET databasename/_design/{ddoc}/_search_disk_size/{search_index}
"""
ddoc_search_disk_size = self.r_session.get(
'/'.join([self.document_url, '_search_disk_size', search_index]))
ddoc_search_disk_size.raise_for_status()
return ddoc_search_disk_size.json()
40 changes: 40 additions & 0 deletions tests/unit/design_document_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,46 @@ def test_get_search_info(self):
self.assertTrue(search_index_metadata['pending_seq'] <= 101, 'The pending_seq should be 101 or fewer.')
self.assertTrue(search_index_metadata['disk_size'] >0, 'The disk_size should be greater than 0.')

@unittest.skipUnless(
os.environ.get('RUN_CLOUDANT_TESTS') is not None,
'Skipping Cloudant _search_disk_size endpoint test'
)
def test_get_search_disk_size(self):
"""
Test retrieval of search_disk_size endpoint from the DesignDocument.
"""
self.populate_db_with_documents(100)
ddoc = DesignDocument(self.db, '_design/ddoc001')
ddoc.add_search_index(
'search001',
'function (doc) {\n index("default", doc._id); '
'if (doc._id) {index("name", doc.name, {"store": true}); }\n}'
)
ddoc.save()

ddoc_remote = DesignDocument(self.db, '_design/ddoc001')
ddoc_remote.fetch()

ddoc_remote.search_info('search001') # trigger index build

search_disk_size = ddoc_remote.search_disk_size('search001')

self.assertEqual(
sorted(search_disk_size.keys()), ['name', 'search_index'],
'The search disk size should contain only keys "name" and "search_index"')
self.assertEqual(
search_disk_size['name'], '_design/ddoc001/search001',
'The search index "name" should be correct.')
self.assertEqual(
sorted(search_disk_size['search_index'].keys()), ['disk_size'],
'The search index should contain only key "disk_size"')
self.assertTrue(
isinstance(search_disk_size['search_index']['disk_size'], int),
'The "disk_size" value should be an integer.')
self.assertTrue(
search_disk_size['search_index']['disk_size'] > 0,
'The "disk_size" should be greater than 0.')

@unittest.skipUnless(
os.environ.get('RUN_CLOUDANT_TESTS') is not None,
'Skipping Cloudant _search_info raises HTTPError test'
Expand Down

0 comments on commit 0ea7188

Please sign in to comment.