diff --git a/CHANGES.md b/CHANGES.md index 3a734fa9..a1db5435 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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. diff --git a/src/cloudant/design_document.py b/src/cloudant/design_document.py index 3e460741..b32c5e33 100644 --- a/src/cloudant/design_document.py +++ b/src/cloudant/design_document.py @@ -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() diff --git a/tests/unit/design_document_tests.py b/tests/unit/design_document_tests.py index 44ede8fa..3fef4d0d 100644 --- a/tests/unit/design_document_tests.py +++ b/tests/unit/design_document_tests.py @@ -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'