Skip to content

Commit a9b6ae3

Browse files
author
Wouter Evolane
committed
* removed unused imports
* renamed methods * removed unnecessary methods * updated tests for method rename
1 parent 9127ea5 commit a9b6ae3

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

dynatrace/environment_v2/settings.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
from datetime import datetime
2-
from dynatrace.dynatrace_object import DynatraceObject
3-
from typing import List, Optional, Union, Dict, Any
1+
from typing import Optional, Dict, Any
42

3+
from dynatrace.dynatrace_object import DynatraceObject
54
from dynatrace.http_client import HttpClient
65
from dynatrace.pagination import PaginatedList
7-
import json
8-
import logging
9-
from http.client import HTTPConnection # py3
106

117

128
class SettingService:
@@ -15,7 +11,7 @@ class SettingService:
1511
def __init__(self, http_client: HttpClient):
1612
self.__http_client = http_client
1713

18-
def list(self,schema_id: Optional[str] = None,
14+
def list_objects(self,schema_id: Optional[str] = None,
1915
scope: Optional[str] = None,external_ids: Optional[str] = None,
2016
fields: Optional[str] = None,
2117
filter:Optional[str] = None, sort:Optional[str] = None, page_size:Optional[str] = None) -> PaginatedList["DynatraceObject"]:
@@ -34,15 +30,15 @@ def list(self,schema_id: Optional[str] = None,
3430
}
3531
return PaginatedList(Settings, self.__http_client, target_url=self.ENDPOINT, list_item="items", target_params=params)
3632

37-
def post(self,external_id,object_id,schema_id,schema_version,scope, value,validate_only):
33+
def create_object(self,external_id,object_id,schema_id,schema_version,scope, value,validate_only):
3834
"""Creates a new settings object
3935
4036
:param external_id: External identifier for the object being created
4137
:param object_id: The ID of the settings object that should be replaced. Only applicable if an external identifier
4238
:param object_id: the ID of the object
4339
:param schema_id: The schema on which the object is based
4440
:param schema_version: The version of the schema on which the object is based.
45-
:param scope The scope that the object targets. For more details, please see Dynatrace Documentation.
41+
:param scope The scope that the object targets. For more details, please see Dynatrace Documentation.
4642
:param value The value of the setting.
4743
:return: a Settings object
4844
"""
@@ -63,7 +59,7 @@ def post(self,external_id,object_id,schema_id,schema_version,scope, value,valida
6359
return response
6460

6561

66-
def get(self, object_id: str):
62+
def get_object(self, object_id: str):
6763
"""Gets parameters of specified settings object
6864
6965
:param object_id: the ID of the object
@@ -72,14 +68,15 @@ def get(self, object_id: str):
7268
response = self.__http_client.make_request(f"{self.ENDPOINT}/{object_id}").json()
7369
return Settings(raw_element=response)
7470

75-
def update(self, object_id: str, value):
71+
def update_object(self, object_id: str, value):
7672
"""Updates an existing settings object
73+
7774
:param object_id: the ID of the object
7875
7976
"""
8077
return self.__http_client.make_request(path=f"{self.ENDPOINT}/{object_id}", params=value, method="PUT")
8178

82-
def delete(self, object_id: str):
79+
def delete_object(self, object_id: str):
8380
"""Deletes the specified object
8481
8582
:param object_id: the ID of the object
@@ -88,10 +85,7 @@ def delete(self, object_id: str):
8885
return self.__http_client.make_request(path=f"{self.ENDPOINT}/{object_id}", method="DELETE")
8986

9087
class Settings(DynatraceObject):
91-
value = None
9288
def _create_from_raw_data(self, raw_element: Dict[str, Any]):
9389
# Mandatory
9490
self.objectId: str = raw_element["objectId"]
9591
self.value: str = raw_element["value"]
96-
def to_json(self):
97-
return self.value

test/environment_v2/test_settings.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@
1515
"operations": False,
1616
"security": False},
1717
"supplementaryIdentifiers": [] }
18-
def test_list(dt: Dynatrace):
19-
settings = dt.settings.list(schema_id="builtin:ownership.teams")
18+
def test_list_objects(dt: Dynatrace):
19+
settings = dt.settings.list_objects(schema_id="builtin:ownership.teams")
2020
assert isinstance(settings, PaginatedList)
2121
assert len(list(settings)) == 1
2222
assert all(isinstance(s, st.Settings) for s in settings)
2323

24-
def test_get(dt: Dynatrace):
25-
setting = dt.settings.get(object_id="vu9U3hXa3q0AAAABABdidWlsdGluOm93bmVyc2hpcC50ZWFtcwAGdGVuYW50AAZ0ZW5hbnQAJGVjN2UyNTdhLWM5MTktM2YzMC05NWFiLTliMzNkMmQwZGRkY77vVN4V2t6t")
24+
def test_get_object(dt: Dynatrace):
25+
setting = dt.settings.get_object(object_id="vu9U3hXa3q0AAAABABdidWlsdGluOm93bmVyc2hpcC50ZWFtcwAGdGVuYW50AAZ0ZW5hbnQAJGVjN2UyNTdhLWM5MTktM2YzMC05NWFiLTliMzNkMmQwZGRkY77vVN4V2t6t")
2626
assert isinstance(setting, st.Settings)
2727

28-
def test_post(dt: Dynatrace):
28+
def test_post_object(dt: Dynatrace):
2929

30-
response = dt.settings.post(external_id='unittest',object_id='unittest',schema_id="builtin:ownership.teams",schema_version="1.0.6",scope="environment", value=payload,validate_only=False)
30+
response = dt.settings.create_object(external_id='unittest',object_id='unittest',schema_id="builtin:ownership.teams",schema_version="1.0.6",scope="environment", value=payload,validate_only=False)
3131
assert response[0].get("code") == 200
3232
assert response[0].get("code") is not None
3333

34-
def test_put(dt: Dynatrace):
34+
def test_put_object(dt: Dynatrace):
3535
payload["identifier"] = "unittestupdate"
36-
response = dt.settings.update("unittest",payload)
36+
response = dt.settings.update_object("unittest",payload)
3737
print(response)

0 commit comments

Comments
 (0)