Skip to content

Commit

Permalink
* removed unused imports
Browse files Browse the repository at this point in the history
* renamed methods
* removed unnecessary methods
* updated tests for method rename
  • Loading branch information
Wouter Evolane committed Nov 29, 2023
1 parent 9127ea5 commit a9b6ae3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
24 changes: 9 additions & 15 deletions dynatrace/environment_v2/settings.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
from datetime import datetime
from dynatrace.dynatrace_object import DynatraceObject
from typing import List, Optional, Union, Dict, Any
from typing import Optional, Dict, Any

from dynatrace.dynatrace_object import DynatraceObject
from dynatrace.http_client import HttpClient
from dynatrace.pagination import PaginatedList
import json
import logging
from http.client import HTTPConnection # py3


class SettingService:
Expand All @@ -15,7 +11,7 @@ class SettingService:
def __init__(self, http_client: HttpClient):
self.__http_client = http_client

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

def post(self,external_id,object_id,schema_id,schema_version,scope, value,validate_only):
def create_object(self,external_id,object_id,schema_id,schema_version,scope, value,validate_only):
"""Creates a new settings object
:param external_id: External identifier for the object being created
:param object_id: The ID of the settings object that should be replaced. Only applicable if an external identifier
:param object_id: the ID of the object
:param schema_id: The schema on which the object is based
:param schema_version: The version of the schema on which the object is based.
:param scope The scope that the object targets. For more details, please see Dynatrace Documentation.
:param scope The scope that the object targets. For more details, please see Dynatrace Documentation.
:param value The value of the setting.
:return: a Settings object
"""
Expand All @@ -63,7 +59,7 @@ def post(self,external_id,object_id,schema_id,schema_version,scope, value,valida
return response


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

def update(self, object_id: str, value):
def update_object(self, object_id: str, value):
"""Updates an existing settings object
:param object_id: the ID of the object
"""
return self.__http_client.make_request(path=f"{self.ENDPOINT}/{object_id}", params=value, method="PUT")

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

class Settings(DynatraceObject):
value = None
def _create_from_raw_data(self, raw_element: Dict[str, Any]):
# Mandatory
self.objectId: str = raw_element["objectId"]
self.value: str = raw_element["value"]
def to_json(self):
return self.value
16 changes: 8 additions & 8 deletions test/environment_v2/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@
"operations": False,
"security": False},
"supplementaryIdentifiers": [] }
def test_list(dt: Dynatrace):
settings = dt.settings.list(schema_id="builtin:ownership.teams")
def test_list_objects(dt: Dynatrace):
settings = dt.settings.list_objects(schema_id="builtin:ownership.teams")
assert isinstance(settings, PaginatedList)
assert len(list(settings)) == 1
assert all(isinstance(s, st.Settings) for s in settings)

def test_get(dt: Dynatrace):
setting = dt.settings.get(object_id="vu9U3hXa3q0AAAABABdidWlsdGluOm93bmVyc2hpcC50ZWFtcwAGdGVuYW50AAZ0ZW5hbnQAJGVjN2UyNTdhLWM5MTktM2YzMC05NWFiLTliMzNkMmQwZGRkY77vVN4V2t6t")
def test_get_object(dt: Dynatrace):
setting = dt.settings.get_object(object_id="vu9U3hXa3q0AAAABABdidWlsdGluOm93bmVyc2hpcC50ZWFtcwAGdGVuYW50AAZ0ZW5hbnQAJGVjN2UyNTdhLWM5MTktM2YzMC05NWFiLTliMzNkMmQwZGRkY77vVN4V2t6t")
assert isinstance(setting, st.Settings)

def test_post(dt: Dynatrace):
def test_post_object(dt: Dynatrace):

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)
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)
assert response[0].get("code") == 200
assert response[0].get("code") is not None

def test_put(dt: Dynatrace):
def test_put_object(dt: Dynatrace):
payload["identifier"] = "unittestupdate"
response = dt.settings.update("unittest",payload)
response = dt.settings.update_object("unittest",payload)
print(response)

0 comments on commit a9b6ae3

Please sign in to comment.