diff --git a/CHANGELOG.md b/CHANGELOG.md index 065cfe44..16f035a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ ### Bug Fixes 1. [#283](https://github.com/influxdata/influxdb-client-python/pull/283): Set proxy server in config file +1. [#290](https://github.com/influxdata/influxdb-client-python/pull/290): `Threshold` domain models mapping +1. [#290](https://github.com/influxdata/influxdb-client-python/pull/290): `DashboardService` responses types ## 1.19.0 [2021-07-09] diff --git a/influxdb_client/domain/check.py b/influxdb_client/domain/check.py index 365a0484..249bc058 100644 --- a/influxdb_client/domain/check.py +++ b/influxdb_client/domain/check.py @@ -32,11 +32,11 @@ class Check(object): and the value is json key in definition. """ openapi_types = { - 'type': 'str', + 'type': 'str' } attribute_map = { - 'type': 'type', + 'type': 'type' } discriminator_value_class_map = { diff --git a/influxdb_client/domain/greater_threshold.py b/influxdb_client/domain/greater_threshold.py index 6ce01bd5..5d9791e4 100644 --- a/influxdb_client/domain/greater_threshold.py +++ b/influxdb_client/domain/greater_threshold.py @@ -14,10 +14,10 @@ import re # noqa: F401 import six -from influxdb_client.domain.threshold import Threshold +from influxdb_client.domain.threshold_base import ThresholdBase -class GreaterThreshold(Threshold): +class GreaterThreshold(ThresholdBase): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -48,7 +48,7 @@ class GreaterThreshold(Threshold): def __init__(self, type="greater", value=None, level=None, all_values=None): # noqa: E501,D401,D403 """GreaterThreshold - a model defined in OpenAPI.""" # noqa: E501 - Threshold.__init__(self, level=level, all_values=all_values) # noqa: E501 + ThresholdBase.__init__(self, level=level, all_values=all_values) # noqa: E501 self._type = None self._value = None diff --git a/influxdb_client/domain/lesser_threshold.py b/influxdb_client/domain/lesser_threshold.py index 3756b37d..0a4cd9f3 100644 --- a/influxdb_client/domain/lesser_threshold.py +++ b/influxdb_client/domain/lesser_threshold.py @@ -14,10 +14,10 @@ import re # noqa: F401 import six -from influxdb_client.domain.threshold import Threshold +from influxdb_client.domain.threshold_base import ThresholdBase -class LesserThreshold(Threshold): +class LesserThreshold(ThresholdBase): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -48,7 +48,7 @@ class LesserThreshold(Threshold): def __init__(self, type="lesser", value=None, level=None, all_values=None): # noqa: E501,D401,D403 """LesserThreshold - a model defined in OpenAPI.""" # noqa: E501 - Threshold.__init__(self, level=level, all_values=all_values) # noqa: E501 + ThresholdBase.__init__(self, level=level, all_values=all_values) # noqa: E501 self._type = None self._value = None diff --git a/influxdb_client/domain/notification_endpoint.py b/influxdb_client/domain/notification_endpoint.py index b3056d03..d1df46a4 100644 --- a/influxdb_client/domain/notification_endpoint.py +++ b/influxdb_client/domain/notification_endpoint.py @@ -32,11 +32,11 @@ class NotificationEndpoint(object): and the value is json key in definition. """ openapi_types = { - 'type': 'NotificationEndpointType', + 'type': 'NotificationEndpointType' } attribute_map = { - 'type': 'type', + 'type': 'type' } discriminator_value_class_map = { diff --git a/influxdb_client/domain/notification_rule.py b/influxdb_client/domain/notification_rule.py index aad3e9a9..592f0917 100644 --- a/influxdb_client/domain/notification_rule.py +++ b/influxdb_client/domain/notification_rule.py @@ -32,11 +32,11 @@ class NotificationRule(object): and the value is json key in definition. """ openapi_types = { - 'type': 'str', + 'type': 'str' } attribute_map = { - 'type': 'type', + 'type': 'type' } discriminator_value_class_map = { diff --git a/influxdb_client/domain/post_check.py b/influxdb_client/domain/post_check.py index 2a323e80..2f17669d 100644 --- a/influxdb_client/domain/post_check.py +++ b/influxdb_client/domain/post_check.py @@ -32,11 +32,11 @@ class PostCheck(object): and the value is json key in definition. """ openapi_types = { - 'type': 'str', + 'type': 'str' } attribute_map = { - 'type': 'type', + 'type': 'type' } discriminator_value_class_map = { diff --git a/influxdb_client/domain/post_notification_endpoint.py b/influxdb_client/domain/post_notification_endpoint.py index c65e90a6..0e6f6296 100644 --- a/influxdb_client/domain/post_notification_endpoint.py +++ b/influxdb_client/domain/post_notification_endpoint.py @@ -32,11 +32,11 @@ class PostNotificationEndpoint(object): and the value is json key in definition. """ openapi_types = { - 'type': 'NotificationEndpointType', + 'type': 'NotificationEndpointType' } attribute_map = { - 'type': 'type', + 'type': 'type' } discriminator_value_class_map = { diff --git a/influxdb_client/domain/post_notification_rule.py b/influxdb_client/domain/post_notification_rule.py index bf476642..22fe922a 100644 --- a/influxdb_client/domain/post_notification_rule.py +++ b/influxdb_client/domain/post_notification_rule.py @@ -32,11 +32,11 @@ class PostNotificationRule(object): and the value is json key in definition. """ openapi_types = { - 'type': 'str', + 'type': 'str' } attribute_map = { - 'type': 'type', + 'type': 'type' } discriminator_value_class_map = { diff --git a/influxdb_client/domain/property_key.py b/influxdb_client/domain/property_key.py index 496b3c4c..2a4ef2ed 100644 --- a/influxdb_client/domain/property_key.py +++ b/influxdb_client/domain/property_key.py @@ -14,9 +14,10 @@ import re # noqa: F401 import six +from influxdb_client.domain.expression import Expression -class PropertyKey(object): +class PropertyKey(Expression): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -38,7 +39,9 @@ class PropertyKey(object): } def __init__(self): # noqa: E501,D401,D403 - """PropertyKey - a model defined in OpenAPI.""" # noqa: E501 self.discriminator = None + """PropertyKey - a model defined in OpenAPI.""" # noqa: E501 + Expression.__init__(self) # noqa: E501 + self.discriminator = None def to_dict(self): """Return the model properties as a dict.""" diff --git a/influxdb_client/domain/range_threshold.py b/influxdb_client/domain/range_threshold.py index 89ec4263..11931f12 100644 --- a/influxdb_client/domain/range_threshold.py +++ b/influxdb_client/domain/range_threshold.py @@ -14,10 +14,10 @@ import re # noqa: F401 import six -from influxdb_client.domain.threshold import Threshold +from influxdb_client.domain.threshold_base import ThresholdBase -class RangeThreshold(Threshold): +class RangeThreshold(ThresholdBase): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -52,7 +52,7 @@ class RangeThreshold(Threshold): def __init__(self, type="range", min=None, max=None, within=None, level=None, all_values=None): # noqa: E501,D401,D403 """RangeThreshold - a model defined in OpenAPI.""" # noqa: E501 - Threshold.__init__(self, level=level, all_values=all_values) # noqa: E501 + ThresholdBase.__init__(self, level=level, all_values=all_values) # noqa: E501 self._type = None self._min = None diff --git a/influxdb_client/domain/threshold.py b/influxdb_client/domain/threshold.py index 1a806cf0..a05193f4 100644 --- a/influxdb_client/domain/threshold.py +++ b/influxdb_client/domain/threshold.py @@ -14,10 +14,9 @@ import re # noqa: F401 import six -from influxdb_client.domain.threshold_base import ThresholdBase -class Threshold(ThresholdBase): +class Threshold(object): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -33,19 +32,51 @@ class Threshold(ThresholdBase): and the value is json key in definition. """ openapi_types = { - 'level': 'CheckStatusLevel', - 'all_values': 'bool' + 'type': 'str', } attribute_map = { - 'level': 'level', - 'all_values': 'allValues' + 'type': 'type', } - def __init__(self, level=None, all_values=None): # noqa: E501,D401,D403 + discriminator_value_class_map = { + 'greater': 'GreaterThreshold', + 'lesser': 'LesserThreshold', + 'range': 'RangeThreshold' + } + + def __init__(self, type=None): # noqa: E501,D401,D403 """Threshold - a model defined in OpenAPI.""" # noqa: E501 - ThresholdBase.__init__(self, level=level, all_values=all_values) # noqa: E501 - self.discriminator = None + self._type = None + self.discriminator = 'type' + + self.type = type + + @property + def type(self): + """Get the type of this Threshold. + + :return: The type of this Threshold. + :rtype: str + """ # noqa: E501 + return self._type + + @type.setter + def type(self, type): + """Set the type of this Threshold. + + :param type: The type of this Threshold. + :type: str + """ # noqa: E501 + if type is None: + raise ValueError("Invalid value for `type`, must not be `None`") # noqa: E501 + self._type = type + + def get_real_child_model(self, data): + """Return the real base class specified by the discriminator.""" + discriminator_key = self.attribute_map[self.discriminator] + discriminator_value = data[discriminator_key] + return self.discriminator_value_class_map.get(discriminator_value) def to_dict(self): """Return the model properties as a dict.""" diff --git a/influxdb_client/service/dashboards_service.py b/influxdb_client/service/dashboards_service.py index 5a219a78..e55686c4 100644 --- a/influxdb_client/service/dashboards_service.py +++ b/influxdb_client/service/dashboards_service.py @@ -733,7 +733,7 @@ def get_dashboards_id(self, dashboard_id, **kwargs): # noqa: E501,D401,D403 :param str dashboard_id: The ID of the dashboard to update. (required) :param str zap_trace_span: OpenTracing span context :param str include: Includes the cell view properties in the response if set to `properties` - :return: object + :return: Dashboard If the method is called asynchronously, returns the request thread. """ # noqa: E501 @@ -756,7 +756,7 @@ def get_dashboards_id_with_http_info(self, dashboard_id, **kwargs): # noqa: E50 :param str dashboard_id: The ID of the dashboard to update. (required) :param str zap_trace_span: OpenTracing span context :param str include: Includes the cell view properties in the response if set to `properties` - :return: object + :return: Dashboard If the method is called asynchronously, returns the request thread. """ # noqa: E501 @@ -820,7 +820,7 @@ def get_dashboards_id_with_http_info(self, dashboard_id, **kwargs): # noqa: E50 body=body_params, post_params=form_params, files=local_var_files, - response_type='object', # noqa: E501 + response_type='Dashboard', # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1626,7 +1626,7 @@ def post_dashboards(self, create_dashboard_request, **kwargs): # noqa: E501,D40 :param async_req bool :param CreateDashboardRequest create_dashboard_request: Dashboard to create (required) :param str zap_trace_span: OpenTracing span context - :return: object + :return: Dashboard If the method is called asynchronously, returns the request thread. """ # noqa: E501 @@ -1648,7 +1648,7 @@ def post_dashboards_with_http_info(self, create_dashboard_request, **kwargs): # :param async_req bool :param CreateDashboardRequest create_dashboard_request: Dashboard to create (required) :param str zap_trace_span: OpenTracing span context - :return: object + :return: Dashboard If the method is called asynchronously, returns the request thread. """ # noqa: E501 @@ -1714,7 +1714,7 @@ def post_dashboards_with_http_info(self, create_dashboard_request, **kwargs): # body=body_params, post_params=form_params, files=local_var_files, - response_type='object', # noqa: E501 + response_type='Dashboard', # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/influxdb_client/service/default_service.py b/influxdb_client/service/default_service.py index 74d3cab0..4a199216 100644 --- a/influxdb_client/service/default_service.py +++ b/influxdb_client/service/default_service.py @@ -240,6 +240,7 @@ def post_signin(self, **kwargs): # noqa: E501,D401,D403 :param async_req bool :param str zap_trace_span: OpenTracing span context + :param str authorization: An auth credential for the Basic scheme :return: None If the method is called asynchronously, returns the request thread. @@ -261,13 +262,14 @@ def post_signin_with_http_info(self, **kwargs): # noqa: E501,D401,D403 :param async_req bool :param str zap_trace_span: OpenTracing span context + :param str authorization: An auth credential for the Basic scheme :return: None If the method is called asynchronously, returns the request thread. """ # noqa: E501 local_var_params = locals() - all_params = ['zap_trace_span'] # noqa: E501 + all_params = ['zap_trace_span', 'authorization'] # noqa: E501 all_params.append('async_req') all_params.append('_return_http_data_only') all_params.append('_preload_content') @@ -292,6 +294,8 @@ def post_signin_with_http_info(self, **kwargs): # noqa: E501,D401,D403 header_params = {} if 'zap_trace_span' in local_var_params: header_params['Zap-Trace-Span'] = local_var_params['zap_trace_span'] # noqa: E501 + if 'authorization' in local_var_params: + header_params['Authorization'] = local_var_params['authorization'] # noqa: E501 form_params = [] local_var_files = {} diff --git a/influxdb_client/service/users_service.py b/influxdb_client/service/users_service.py index 2abe47ff..1dd6b1a6 100644 --- a/influxdb_client/service/users_service.py +++ b/influxdb_client/service/users_service.py @@ -148,7 +148,7 @@ def get_flags(self, **kwargs): # noqa: E501,D401,D403 :param async_req bool :param str zap_trace_span: OpenTracing span context - :return: Flags + :return: dict(str, object) If the method is called asynchronously, returns the request thread. """ # noqa: E501 @@ -169,7 +169,7 @@ def get_flags_with_http_info(self, **kwargs): # noqa: E501,D401,D403 :param async_req bool :param str zap_trace_span: OpenTracing span context - :return: Flags + :return: dict(str, object) If the method is called asynchronously, returns the request thread. """ # noqa: E501 @@ -225,7 +225,7 @@ def get_flags_with_http_info(self, **kwargs): # noqa: E501,D401,D403 body=body_params, post_params=form_params, files=local_var_files, - response_type='Flags', # noqa: E501 + response_type='dict(str, object)', # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -792,6 +792,7 @@ def post_users_id_password(self, user_id, password_reset_body, **kwargs): # noq :param str user_id: The user ID. (required) :param PasswordResetBody password_reset_body: New password (required) :param str zap_trace_span: OpenTracing span context + :param str authorization: An auth credential for the Basic scheme :return: None If the method is called asynchronously, returns the request thread. @@ -815,13 +816,14 @@ def post_users_id_password_with_http_info(self, user_id, password_reset_body, ** :param str user_id: The user ID. (required) :param PasswordResetBody password_reset_body: New password (required) :param str zap_trace_span: OpenTracing span context + :param str authorization: An auth credential for the Basic scheme :return: None If the method is called asynchronously, returns the request thread. """ # noqa: E501 local_var_params = locals() - all_params = ['user_id', 'password_reset_body', 'zap_trace_span'] # noqa: E501 + all_params = ['user_id', 'password_reset_body', 'zap_trace_span', 'authorization'] # noqa: E501 all_params.append('async_req') all_params.append('_return_http_data_only') all_params.append('_preload_content') @@ -856,6 +858,8 @@ def post_users_id_password_with_http_info(self, user_id, password_reset_body, ** header_params = {} if 'zap_trace_span' in local_var_params: header_params['Zap-Trace-Span'] = local_var_params['zap_trace_span'] # noqa: E501 + if 'authorization' in local_var_params: + header_params['Authorization'] = local_var_params['authorization'] # noqa: E501 form_params = [] local_var_files = {} @@ -907,6 +911,7 @@ def put_me_password(self, password_reset_body, **kwargs): # noqa: E501,D401,D40 :param async_req bool :param PasswordResetBody password_reset_body: New password (required) :param str zap_trace_span: OpenTracing span context + :param str authorization: An auth credential for the Basic scheme :return: None If the method is called asynchronously, returns the request thread. @@ -929,13 +934,14 @@ def put_me_password_with_http_info(self, password_reset_body, **kwargs): # noqa :param async_req bool :param PasswordResetBody password_reset_body: New password (required) :param str zap_trace_span: OpenTracing span context + :param str authorization: An auth credential for the Basic scheme :return: None If the method is called asynchronously, returns the request thread. """ # noqa: E501 local_var_params = locals() - all_params = ['password_reset_body', 'zap_trace_span'] # noqa: E501 + all_params = ['password_reset_body', 'zap_trace_span', 'authorization'] # noqa: E501 all_params.append('async_req') all_params.append('_return_http_data_only') all_params.append('_preload_content') @@ -964,6 +970,8 @@ def put_me_password_with_http_info(self, password_reset_body, **kwargs): # noqa header_params = {} if 'zap_trace_span' in local_var_params: header_params['Zap-Trace-Span'] = local_var_params['zap_trace_span'] # noqa: E501 + if 'authorization' in local_var_params: + header_params['Authorization'] = local_var_params['authorization'] # noqa: E501 form_params = [] local_var_files = {} diff --git a/tests/test_Dashboards.py b/tests/test_Dashboards.py new file mode 100644 index 00000000..37dca721 --- /dev/null +++ b/tests/test_Dashboards.py @@ -0,0 +1,33 @@ +import datetime + +from influxdb_client import DashboardsService, CreateDashboardRequest, CellsService, \ + CreateCell +from tests.base_test import BaseTest + + +class DashboardsClientTest(BaseTest): + + def setUp(self) -> None: + super(DashboardsClientTest, self).setUp() + + self.dashboards_service = DashboardsService(self.client.api_client) + dashboards = self.dashboards_service.get_dashboards() + + for dashboard in dashboards.dashboards: + if dashboard.name.endswith("_IT"): + print("Delete dashboard: ", dashboard.name) + self.dashboards_service.delete_dashboards_id(dashboard.id) + + def test_create_dashboard_with_cell(self): + unique_id = str(datetime.datetime.now().timestamp()) + + dashboard = self.dashboards_service.post_dashboards( + create_dashboard_request=CreateDashboardRequest(org_id=self.find_my_org().id, name=f"Dashboard_{unique_id}_IT")) + self.assertEqual(dashboard.name, f"Dashboard_{unique_id}_IT") + + cells_service = CellsService(self.client.api_client) + cell = cells_service.post_dashboards_id_cells( + dashboard_id=dashboard.id, create_cell=CreateCell(name=f"Cell_{unique_id}_IT", h=3, w=12)) + self.assertIsNotNone(cell.id) + view = cells_service.get_dashboards_id_cells_id_view(dashboard_id=dashboard.id, cell_id=cell.id) + self.assertEqual(view.name, f"Cell_{unique_id}_IT") diff --git a/tests/test_Thresholds.py b/tests/test_Thresholds.py new file mode 100644 index 00000000..ef87a8b6 --- /dev/null +++ b/tests/test_Thresholds.py @@ -0,0 +1,45 @@ +import json + +import httpretty + +from influxdb_client import InfluxDBClient, ChecksService +from tests.base_test import BaseTest + + +class ThresholdsClientTest(BaseTest): + + def setUp(self) -> None: + super(ThresholdsClientTest, self).setUp() + + httpretty.enable() + httpretty.reset() + + def tearDown(self) -> None: + self.client.close() + httpretty.disable() + + def test_threshold(self): + dictionary = { + "id": "01", + "orgID": "org_id", + "name": "name", + "type": "threshold", + "query": "query", + "thresholds": [{ + "allValues": False, + "level": "CRIT", + "value": 10.5, + "type": "greater" + }], + } + httpretty.register_uri(httpretty.GET, uri="http://localhost/api/v2/checks/01", status=200, + body=json.dumps(dictionary, indent=4), + adding_headers={'Content-Type': 'application/json'}) + self.client = InfluxDBClient("http://localhost", "my-token", org="my-org", debug=True) + checks_service = ChecksService(api_client=self.client.api_client) + check = checks_service.get_checks_id(check_id="01") + self.assertEqual(1, len(check.thresholds)) + self.assertEqual(False, check.thresholds[0].all_values) + self.assertEqual(10.5, check.thresholds[0].value) + self.assertEqual("CRIT", check.thresholds[0].level) + self.assertEqual("greater", check.thresholds[0].type)