diff --git a/ibmcloudant/cloudant_v1.py b/ibmcloudant/cloudant_v1.py index 768b6ab6..a96a339e 100644 --- a/ibmcloudant/cloudant_v1.py +++ b/ibmcloudant/cloudant_v1.py @@ -8195,6 +8195,80 @@ def post_activity_tracker_events( response = self.send(request, **kwargs) return response + def get_capacity_databases_information( + self, + **kwargs, + ) -> DetailedResponse: + """ + Retrieve maximum allowed database count. + + Retrieves the maximum number of databases currently allowed in the instance. + + :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 `CapacityDatabasesInformation` object + """ + + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='get_capacity_databases_information', + ) + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + url = '/_api/v2/user/capacity/databases' + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + ) + + response = self.send(request, **kwargs) + return response + + def get_current_databases_information( + self, + **kwargs, + ) -> DetailedResponse: + """ + Retrieve current database count. + + Retrieves the current number of databases that exist in the instance. + + :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 `CurrentDatabasesInformation` object + """ + + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='get_current_databases_information', + ) + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + url = '/_api/v2/user/current/databases' + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + ) + + response = self.send(request, **kwargs) + return response + def get_current_throughput_information( self, **kwargs, @@ -10358,6 +10432,132 @@ def __ne__(self, other: 'BulkGetResultItem') -> bool: return not self == other +class CapacityDatabasesInformation: + """ + Schema for information about maximum total database count. + + :param CapacityDatabasesInformationCurrent current: (optional) Schema for + information about the current database capacity. + """ + + def __init__( + self, + *, + current: Optional['CapacityDatabasesInformationCurrent'] = None, + ) -> None: + """ + Initialize a CapacityDatabasesInformation object. + + :param CapacityDatabasesInformationCurrent current: (optional) Schema for + information about the current database capacity. + """ + self.current = current + + @classmethod + def from_dict(cls, _dict: Dict) -> 'CapacityDatabasesInformation': + """Initialize a CapacityDatabasesInformation object from a json dictionary.""" + args = {} + if (current := _dict.get('current')) is not None: + args['current'] = CapacityDatabasesInformationCurrent.from_dict(current) + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a CapacityDatabasesInformation 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, 'current') and self.current is not None: + if isinstance(self.current, dict): + _dict['current'] = self.current + else: + _dict['current'] = self.current.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 CapacityDatabasesInformation object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'CapacityDatabasesInformation') -> 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: 'CapacityDatabasesInformation') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class CapacityDatabasesInformationCurrent: + """ + Schema for information about the current database capacity. + + :param DatabasesCountInformation databases: (optional) Schema for databases + count. + """ + + def __init__( + self, + *, + databases: Optional['DatabasesCountInformation'] = None, + ) -> None: + """ + Initialize a CapacityDatabasesInformationCurrent object. + + :param DatabasesCountInformation databases: (optional) Schema for databases + count. + """ + self.databases = databases + + @classmethod + def from_dict(cls, _dict: Dict) -> 'CapacityDatabasesInformationCurrent': + """Initialize a CapacityDatabasesInformationCurrent object from a json dictionary.""" + args = {} + if (databases := _dict.get('databases')) is not None: + args['databases'] = DatabasesCountInformation.from_dict(databases) + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a CapacityDatabasesInformationCurrent 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, 'databases') and self.databases is not None: + if isinstance(self.databases, dict): + _dict['databases'] = self.databases + else: + _dict['databases'] = self.databases.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 CapacityDatabasesInformationCurrent object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'CapacityDatabasesInformationCurrent') -> 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: 'CapacityDatabasesInformationCurrent') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class CapacityThroughputInformation: """ Schema for information about the currently provisioned and target throughput capacity. @@ -10984,6 +11184,69 @@ def __ne__(self, other: 'CorsInformation') -> bool: return not self == other +class CurrentDatabasesInformation: + """ + Schema for information about the current database counts. + + :param DatabasesCountInformation databases: (optional) Schema for databases + count. + """ + + def __init__( + self, + *, + databases: Optional['DatabasesCountInformation'] = None, + ) -> None: + """ + Initialize a CurrentDatabasesInformation object. + + :param DatabasesCountInformation databases: (optional) Schema for databases + count. + """ + self.databases = databases + + @classmethod + def from_dict(cls, _dict: Dict) -> 'CurrentDatabasesInformation': + """Initialize a CurrentDatabasesInformation object from a json dictionary.""" + args = {} + if (databases := _dict.get('databases')) is not None: + args['databases'] = DatabasesCountInformation.from_dict(databases) + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a CurrentDatabasesInformation 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, 'databases') and self.databases is not None: + if isinstance(self.databases, dict): + _dict['databases'] = self.databases + else: + _dict['databases'] = self.databases.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 CurrentDatabasesInformation object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'CurrentDatabasesInformation') -> 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: 'CurrentDatabasesInformation') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class CurrentThroughputInformation: """ Schema for information about current consumption of a provisioned throughput capacity. @@ -11514,6 +11777,64 @@ def __ne__(self, other: 'DatabaseInformationProps') -> bool: return not self == other +class DatabasesCountInformation: + """ + Schema for databases count. + + :param int total: (optional) The total number of databases. + """ + + def __init__( + self, + *, + total: Optional[int] = None, + ) -> None: + """ + Initialize a DatabasesCountInformation object. + + :param int total: (optional) The total number of databases. + """ + self.total = total + + @classmethod + def from_dict(cls, _dict: Dict) -> 'DatabasesCountInformation': + """Initialize a DatabasesCountInformation object from a json dictionary.""" + args = {} + if (total := _dict.get('total')) is not None: + args['total'] = total + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a DatabasesCountInformation 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, 'total') and self.total is not None: + _dict['total'] = self.total + 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 DatabasesCountInformation object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'DatabasesCountInformation') -> 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: 'DatabasesCountInformation') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class DbEvent: """ Schema for a database change event. diff --git a/stubs/gen-its-mappings.json b/stubs/gen-its-mappings.json index 737cf1c6..d39f95f1 100644 --- a/stubs/gen-its-mappings.json +++ b/stubs/gen-its-mappings.json @@ -445,7 +445,7 @@ "uuid": "a2e4e696-e631-33f8-b168-5015048cdad8" }, { - "id": "8593b1aa-6297-3120-a04e-c199e2808167", + "id": "8593b1aa-6297-3120-a04e-c199e2808168", "request": { "url": "/_api/v2/user/current/databases", "method": "GET" @@ -473,7 +473,7 @@ } } }, - "uuid": "8593b1aa-6297-3120-a04e-c199e2808167" + "uuid": "8593b1aa-6297-3120-a04e-c199e2808168" }, { "id": "8c38b725-a6ac-3f63-a723-9f4925ae23fd", diff --git a/test/integration/test_cloudant_v1.py b/test/integration/test_cloudant_v1.py index c145881e..be039006 100644 --- a/test/integration/test_cloudant_v1.py +++ b/test/integration/test_cloudant_v1.py @@ -2033,6 +2033,22 @@ def test_post_activity_tracker_events(self): ok = response.get_result() assert ok is not None + @needscredentials + def test_get_capacity_databases_information(self): + response = self.cloudant_service.get_capacity_databases_information() + + assert response.get_status_code() == 200 + capacity_databases_information = response.get_result() + assert capacity_databases_information is not None + + @needscredentials + def test_get_current_databases_information(self): + response = self.cloudant_service.get_current_databases_information() + + assert response.get_status_code() == 200 + current_databases_information = response.get_result() + assert current_databases_information is not None + @needscredentials def test_get_current_throughput_information(self): response = self.cloudant_service.get_current_throughput_information() diff --git a/test/unit/test_cloudant_v1.py b/test/unit/test_cloudant_v1.py index 04e53335..3b369a6c 100644 --- a/test/unit/test_cloudant_v1.py +++ b/test/unit/test_cloudant_v1.py @@ -13527,6 +13527,82 @@ def test_post_activity_tracker_events_value_error_with_retries(self): self.test_post_activity_tracker_events_value_error() +class TestGetCapacityDatabasesInformation: + """ + Test Class for get_capacity_databases_information + """ + + @responses.activate + def test_get_capacity_databases_information_all_params(self): + """ + get_capacity_databases_information() + """ + # Set up mock + url = preprocess_url('/_api/v2/user/capacity/databases') + mock_response = '{"current": {"databases": {"total": 0}}}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Invoke method + response = _service.get_capacity_databases_information() + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_get_capacity_databases_information_all_params_with_retries(self): + # Enable retries and run test_get_capacity_databases_information_all_params. + _service.enable_retries() + self.test_get_capacity_databases_information_all_params() + + # Disable retries and run test_get_capacity_databases_information_all_params. + _service.disable_retries() + self.test_get_capacity_databases_information_all_params() + + +class TestGetCurrentDatabasesInformation: + """ + Test Class for get_current_databases_information + """ + + @responses.activate + def test_get_current_databases_information_all_params(self): + """ + get_current_databases_information() + """ + # Set up mock + url = preprocess_url('/_api/v2/user/current/databases') + mock_response = '{"databases": {"total": 0}}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Invoke method + response = _service.get_current_databases_information() + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_get_current_databases_information_all_params_with_retries(self): + # Enable retries and run test_get_current_databases_information_all_params. + _service.enable_retries() + self.test_get_current_databases_information_all_params() + + # Disable retries and run test_get_current_databases_information_all_params. + _service.disable_retries() + self.test_get_current_databases_information_all_params() + + class TestGetCurrentThroughputInformation: """ Test Class for get_current_throughput_information @@ -14414,6 +14490,79 @@ def test_bulk_get_result_item_serialization(self): assert bulk_get_result_item_model_json2 == bulk_get_result_item_model_json +class TestModel_CapacityDatabasesInformation: + """ + Test Class for CapacityDatabasesInformation + """ + + def test_capacity_databases_information_serialization(self): + """ + Test serialization/deserialization for CapacityDatabasesInformation + """ + + # Construct dict forms of any model objects needed in order to build this model. + + databases_count_information_model = {} # DatabasesCountInformation + databases_count_information_model['total'] = 0 + + capacity_databases_information_current_model = {} # CapacityDatabasesInformationCurrent + capacity_databases_information_current_model['databases'] = databases_count_information_model + + # Construct a json representation of a CapacityDatabasesInformation model + capacity_databases_information_model_json = {} + capacity_databases_information_model_json['current'] = capacity_databases_information_current_model + + # Construct a model instance of CapacityDatabasesInformation by calling from_dict on the json representation + capacity_databases_information_model = CapacityDatabasesInformation.from_dict(capacity_databases_information_model_json) + assert capacity_databases_information_model != False + + # Construct a model instance of CapacityDatabasesInformation by calling from_dict on the json representation + capacity_databases_information_model_dict = CapacityDatabasesInformation.from_dict(capacity_databases_information_model_json).__dict__ + capacity_databases_information_model2 = CapacityDatabasesInformation(**capacity_databases_information_model_dict) + + # Verify the model instances are equivalent + assert capacity_databases_information_model == capacity_databases_information_model2 + + # Convert model instance back to dict and verify no loss of data + capacity_databases_information_model_json2 = capacity_databases_information_model.to_dict() + assert capacity_databases_information_model_json2 == capacity_databases_information_model_json + + +class TestModel_CapacityDatabasesInformationCurrent: + """ + Test Class for CapacityDatabasesInformationCurrent + """ + + def test_capacity_databases_information_current_serialization(self): + """ + Test serialization/deserialization for CapacityDatabasesInformationCurrent + """ + + # Construct dict forms of any model objects needed in order to build this model. + + databases_count_information_model = {} # DatabasesCountInformation + databases_count_information_model['total'] = 0 + + # Construct a json representation of a CapacityDatabasesInformationCurrent model + capacity_databases_information_current_model_json = {} + capacity_databases_information_current_model_json['databases'] = databases_count_information_model + + # Construct a model instance of CapacityDatabasesInformationCurrent by calling from_dict on the json representation + capacity_databases_information_current_model = CapacityDatabasesInformationCurrent.from_dict(capacity_databases_information_current_model_json) + assert capacity_databases_information_current_model != False + + # Construct a model instance of CapacityDatabasesInformationCurrent by calling from_dict on the json representation + capacity_databases_information_current_model_dict = CapacityDatabasesInformationCurrent.from_dict(capacity_databases_information_current_model_json).__dict__ + capacity_databases_information_current_model2 = CapacityDatabasesInformationCurrent(**capacity_databases_information_current_model_dict) + + # Verify the model instances are equivalent + assert capacity_databases_information_current_model == capacity_databases_information_current_model2 + + # Convert model instance back to dict and verify no loss of data + capacity_databases_information_current_model_json2 = capacity_databases_information_current_model.to_dict() + assert capacity_databases_information_current_model_json2 == capacity_databases_information_current_model_json + + class TestModel_CapacityThroughputInformation: """ Test Class for CapacityThroughputInformation @@ -14774,6 +14923,41 @@ def test_cors_information_serialization(self): assert cors_information_model_json2 == cors_information_model_json +class TestModel_CurrentDatabasesInformation: + """ + Test Class for CurrentDatabasesInformation + """ + + def test_current_databases_information_serialization(self): + """ + Test serialization/deserialization for CurrentDatabasesInformation + """ + + # Construct dict forms of any model objects needed in order to build this model. + + databases_count_information_model = {} # DatabasesCountInformation + databases_count_information_model['total'] = 0 + + # Construct a json representation of a CurrentDatabasesInformation model + current_databases_information_model_json = {} + current_databases_information_model_json['databases'] = databases_count_information_model + + # Construct a model instance of CurrentDatabasesInformation by calling from_dict on the json representation + current_databases_information_model = CurrentDatabasesInformation.from_dict(current_databases_information_model_json) + assert current_databases_information_model != False + + # Construct a model instance of CurrentDatabasesInformation by calling from_dict on the json representation + current_databases_information_model_dict = CurrentDatabasesInformation.from_dict(current_databases_information_model_json).__dict__ + current_databases_information_model2 = CurrentDatabasesInformation(**current_databases_information_model_dict) + + # Verify the model instances are equivalent + assert current_databases_information_model == current_databases_information_model2 + + # Convert model instance back to dict and verify no loss of data + current_databases_information_model_json2 = current_databases_information_model.to_dict() + assert current_databases_information_model_json2 == current_databases_information_model_json + + class TestModel_CurrentThroughputInformation: """ Test Class for CurrentThroughputInformation @@ -14975,6 +15159,36 @@ def test_database_information_props_serialization(self): assert database_information_props_model_json2 == database_information_props_model_json +class TestModel_DatabasesCountInformation: + """ + Test Class for DatabasesCountInformation + """ + + def test_databases_count_information_serialization(self): + """ + Test serialization/deserialization for DatabasesCountInformation + """ + + # Construct a json representation of a DatabasesCountInformation model + databases_count_information_model_json = {} + databases_count_information_model_json['total'] = 0 + + # Construct a model instance of DatabasesCountInformation by calling from_dict on the json representation + databases_count_information_model = DatabasesCountInformation.from_dict(databases_count_information_model_json) + assert databases_count_information_model != False + + # Construct a model instance of DatabasesCountInformation by calling from_dict on the json representation + databases_count_information_model_dict = DatabasesCountInformation.from_dict(databases_count_information_model_json).__dict__ + databases_count_information_model2 = DatabasesCountInformation(**databases_count_information_model_dict) + + # Verify the model instances are equivalent + assert databases_count_information_model == databases_count_information_model2 + + # Convert model instance back to dict and verify no loss of data + databases_count_information_model_json2 = databases_count_information_model.to_dict() + assert databases_count_information_model_json2 == databases_count_information_model_json + + class TestModel_DbEvent: """ Test Class for DbEvent