diff --git a/ibmcloudant/cloudant_v1.py b/ibmcloudant/cloudant_v1.py index fbb5e11c..768b6ab6 100644 --- a/ibmcloudant/cloudant_v1.py +++ b/ibmcloudant/cloudant_v1.py @@ -6125,6 +6125,60 @@ def post_search_as_stream( response = self.send(request, stream=True, **kwargs) return response + def get_search_disk_size( + self, + db: str, + ddoc: str, + index: str, + **kwargs, + ) -> DetailedResponse: + """ + Retrieve information about the search index disk size. + + Retrieve size of the search index on disk. + + :param str db: Path parameter to specify the database name. + :param str ddoc: Path parameter to specify the design document name. The + design document name is the design document ID excluding the `_design/` + prefix. + :param str index: Path parameter to specify the index name. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `SearchDiskSizeInformation` object + """ + + if not db: + raise ValueError('db must be provided') + if not ddoc: + raise ValueError('ddoc must be provided') + if not index: + raise ValueError('index must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='get_search_disk_size', + ) + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['db', 'ddoc', 'index'] + path_param_values = self.encode_path_vars(db, ddoc, index) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/{db}/_design/{ddoc}/_search_disk_size/{index}'.format(**path_param_dict) + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + ) + + response = self.send(request, **kwargs) + return response + def get_search_info( self, db: str, @@ -6198,7 +6252,8 @@ def head_replication_document( supports the same query arguments as the `GET /_replicator/{doc_id}` method, but only headers like content length and the revision (ETag header) are returned. - :param str doc_id: Path parameter to specify the document ID. + :param str doc_id: Path parameter to specify the ID of the stored + replication configuration in the `_replicator` database. :param str if_none_match: (optional) Header parameter for a conditional HTTP request not matching an ETag. :param dict headers: A `dict` containing the request headers @@ -6399,7 +6454,8 @@ def delete_replication_document( Cancels a replication by deleting the document that describes it from the `_replicator` database. - :param str doc_id: Path parameter to specify the document ID. + :param str doc_id: Path parameter to specify the ID of the stored + replication configuration in the `_replicator` database. :param str if_match: (optional) Header parameter for a conditional HTTP request matching an ETag. :param str batch: (optional) Query parameter to specify whether to store in @@ -6471,7 +6527,8 @@ def get_replication_document( configuration of the replication. The status of the replication is no longer recorded in the document but can be checked via the replication scheduler. - :param str doc_id: Path parameter to specify the document ID. + :param str doc_id: Path parameter to specify the ID of the stored + replication configuration in the `_replicator` database. :param str if_none_match: (optional) Header parameter for a conditional HTTP request not matching an ETag. :param bool attachments: (optional) Query parameter to specify whether to @@ -6563,7 +6620,8 @@ def put_replication_document( Creates or modifies a document in the `_replicator` database to start a new replication or to edit an existing replication. - :param str doc_id: Path parameter to specify the document ID. + :param str doc_id: Path parameter to specify the ID of the stored + replication configuration in the `_replicator` database. :param ReplicationDocument replication_document: HTTP request body for replication operations. :param str if_match: (optional) Header parameter for a conditional HTTP @@ -17412,6 +17470,80 @@ def __ne__(self, other: 'SearchAnalyzeResult') -> bool: return not self == other +class SearchDiskSizeInformation: + """ + Schema for search index disk size. + + :param str name: The name of the search index prefixed by the design document ID + where the index is stored. + :param SearchIndexDiskSize search_index: Schema for search index disk size. + """ + + def __init__( + self, + name: str, + search_index: 'SearchIndexDiskSize', + ) -> None: + """ + Initialize a SearchDiskSizeInformation object. + + :param str name: The name of the search index prefixed by the design + document ID where the index is stored. + :param SearchIndexDiskSize search_index: Schema for search index disk size. + """ + self.name = name + self.search_index = search_index + + @classmethod + def from_dict(cls, _dict: Dict) -> 'SearchDiskSizeInformation': + """Initialize a SearchDiskSizeInformation object from a json dictionary.""" + args = {} + if (name := _dict.get('name')) is not None: + args['name'] = name + else: + raise ValueError('Required property \'name\' not present in SearchDiskSizeInformation JSON') + if (search_index := _dict.get('search_index')) is not None: + args['search_index'] = SearchIndexDiskSize.from_dict(search_index) + else: + raise ValueError('Required property \'search_index\' not present in SearchDiskSizeInformation JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a SearchDiskSizeInformation object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'name') and self.name is not None: + _dict['name'] = self.name + if hasattr(self, 'search_index') and self.search_index is not None: + if isinstance(self.search_index, dict): + _dict['search_index'] = self.search_index + else: + _dict['search_index'] = self.search_index.to_dict() + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this SearchDiskSizeInformation object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'SearchDiskSizeInformation') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'SearchDiskSizeInformation') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class SearchIndexDefinition: """ Schema for a search index definition. @@ -17520,6 +17652,64 @@ def __ne__(self, other: 'SearchIndexDefinition') -> bool: return not self == other +class SearchIndexDiskSize: + """ + Schema for search index disk size. + + :param int disk_size: (optional) The size of the search index on disk. + """ + + def __init__( + self, + *, + disk_size: Optional[int] = None, + ) -> None: + """ + Initialize a SearchIndexDiskSize object. + + :param int disk_size: (optional) The size of the search index on disk. + """ + self.disk_size = disk_size + + @classmethod + def from_dict(cls, _dict: Dict) -> 'SearchIndexDiskSize': + """Initialize a SearchIndexDiskSize object from a json dictionary.""" + args = {} + if (disk_size := _dict.get('disk_size')) is not None: + args['disk_size'] = disk_size + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a SearchIndexDiskSize object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'disk_size') and self.disk_size is not None: + _dict['disk_size'] = self.disk_size + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this SearchIndexDiskSize object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'SearchIndexDiskSize') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'SearchIndexDiskSize') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class SearchIndexInfo: """ Schema for metadata information about a search index. diff --git a/test/integration/test_cloudant_v1.py b/test/integration/test_cloudant_v1.py index 361001a0..c145881e 100644 --- a/test/integration/test_cloudant_v1.py +++ b/test/integration/test_cloudant_v1.py @@ -1428,6 +1428,18 @@ def test_post_search_as_stream(self): result = response.get_result() assert result is not None + @needscredentials + def test_get_search_disk_size(self): + response = self.cloudant_service.get_search_disk_size( + db='testString', + ddoc='testString', + index='testString', + ) + + assert response.get_status_code() == 200 + search_disk_size_information = response.get_result() + assert search_disk_size_information is not None + @needscredentials def test_get_search_info(self): response = self.cloudant_service.get_search_info( diff --git a/test/unit/test_cloudant_v1.py b/test/unit/test_cloudant_v1.py index ed5d7f89..04e53335 100644 --- a/test/unit/test_cloudant_v1.py +++ b/test/unit/test_cloudant_v1.py @@ -9092,6 +9092,95 @@ def test_post_search_as_stream_value_error_with_retries(self): self.test_post_search_as_stream_value_error() +class TestGetSearchDiskSize: + """ + Test Class for get_search_disk_size + """ + + @responses.activate + def test_get_search_disk_size_all_params(self): + """ + get_search_disk_size() + """ + # Set up mock + url = preprocess_url('/testString/_design/testString/_search_disk_size/testString') + mock_response = '{"name": "name", "search_index": {"disk_size": 0}}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Set up parameter values + db = 'testString' + ddoc = 'testString' + index = 'testString' + + # Invoke method + response = _service.get_search_disk_size( + db, + ddoc, + index, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_get_search_disk_size_all_params_with_retries(self): + # Enable retries and run test_get_search_disk_size_all_params. + _service.enable_retries() + self.test_get_search_disk_size_all_params() + + # Disable retries and run test_get_search_disk_size_all_params. + _service.disable_retries() + self.test_get_search_disk_size_all_params() + + @responses.activate + def test_get_search_disk_size_value_error(self): + """ + test_get_search_disk_size_value_error() + """ + # Set up mock + url = preprocess_url('/testString/_design/testString/_search_disk_size/testString') + mock_response = '{"name": "name", "search_index": {"disk_size": 0}}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Set up parameter values + db = 'testString' + ddoc = 'testString' + index = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "db": db, + "ddoc": ddoc, + "index": index, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.get_search_disk_size(**req_copy) + + def test_get_search_disk_size_value_error_with_retries(self): + # Enable retries and run test_get_search_disk_size_value_error. + _service.enable_retries() + self.test_get_search_disk_size_value_error() + + # Disable retries and run test_get_search_disk_size_value_error. + _service.disable_retries() + self.test_get_search_disk_size_value_error() + + class TestGetSearchInfo: """ Test Class for get_search_info @@ -17261,6 +17350,42 @@ def test_search_analyze_result_serialization(self): assert search_analyze_result_model_json2 == search_analyze_result_model_json +class TestModel_SearchDiskSizeInformation: + """ + Test Class for SearchDiskSizeInformation + """ + + def test_search_disk_size_information_serialization(self): + """ + Test serialization/deserialization for SearchDiskSizeInformation + """ + + # Construct dict forms of any model objects needed in order to build this model. + + search_index_disk_size_model = {} # SearchIndexDiskSize + search_index_disk_size_model['disk_size'] = 0 + + # Construct a json representation of a SearchDiskSizeInformation model + search_disk_size_information_model_json = {} + search_disk_size_information_model_json['name'] = 'testString' + search_disk_size_information_model_json['search_index'] = search_index_disk_size_model + + # Construct a model instance of SearchDiskSizeInformation by calling from_dict on the json representation + search_disk_size_information_model = SearchDiskSizeInformation.from_dict(search_disk_size_information_model_json) + assert search_disk_size_information_model != False + + # Construct a model instance of SearchDiskSizeInformation by calling from_dict on the json representation + search_disk_size_information_model_dict = SearchDiskSizeInformation.from_dict(search_disk_size_information_model_json).__dict__ + search_disk_size_information_model2 = SearchDiskSizeInformation(**search_disk_size_information_model_dict) + + # Verify the model instances are equivalent + assert search_disk_size_information_model == search_disk_size_information_model2 + + # Convert model instance back to dict and verify no loss of data + search_disk_size_information_model_json2 = search_disk_size_information_model.to_dict() + assert search_disk_size_information_model_json2 == search_disk_size_information_model_json + + class TestModel_SearchIndexDefinition: """ Test Class for SearchIndexDefinition @@ -17303,6 +17428,36 @@ def test_search_index_definition_serialization(self): assert search_index_definition_model_json2 == search_index_definition_model_json +class TestModel_SearchIndexDiskSize: + """ + Test Class for SearchIndexDiskSize + """ + + def test_search_index_disk_size_serialization(self): + """ + Test serialization/deserialization for SearchIndexDiskSize + """ + + # Construct a json representation of a SearchIndexDiskSize model + search_index_disk_size_model_json = {} + search_index_disk_size_model_json['disk_size'] = 0 + + # Construct a model instance of SearchIndexDiskSize by calling from_dict on the json representation + search_index_disk_size_model = SearchIndexDiskSize.from_dict(search_index_disk_size_model_json) + assert search_index_disk_size_model != False + + # Construct a model instance of SearchIndexDiskSize by calling from_dict on the json representation + search_index_disk_size_model_dict = SearchIndexDiskSize.from_dict(search_index_disk_size_model_json).__dict__ + search_index_disk_size_model2 = SearchIndexDiskSize(**search_index_disk_size_model_dict) + + # Verify the model instances are equivalent + assert search_index_disk_size_model == search_index_disk_size_model2 + + # Convert model instance back to dict and verify no loss of data + search_index_disk_size_model_json2 = search_index_disk_size_model.to_dict() + assert search_index_disk_size_model_json2 == search_index_disk_size_model_json + + class TestModel_SearchIndexInfo: """ Test Class for SearchIndexInfo