From e9f106dbf0ca48c4b1b6850d2604522901dc7649 Mon Sep 17 00:00:00 2001 From: Julien Rossow-Greenberg Date: Fri, 23 Feb 2024 15:07:56 -0500 Subject: [PATCH] add person method --- pytdx/models/person.py | 180 +++++++++++++++++++++++++++++++++++++++++ pytdx/tdx.py | 19 +++++ tests/test_tdx.py | 7 ++ 3 files changed, 206 insertions(+) create mode 100644 pytdx/models/person.py diff --git a/pytdx/models/person.py b/pytdx/models/person.py new file mode 100644 index 0000000..49286ae --- /dev/null +++ b/pytdx/models/person.py @@ -0,0 +1,180 @@ +from typing import Optional, List, Dict +from .base_model import BaseModel + + +class OrgApplication(BaseModel): + def __init__( + self, + SecurityRoleId: Optional[str] = None, + SecurityRoleName: Optional[str] = None, + IsAdministrator: Optional[bool] = None, + ID: Optional[int] = None, + Name: Optional[str] = None, + Description: Optional[str] = None, + SystemClass: Optional[str] = None, + IsDefault: Optional[bool] = None, + IsActive: Optional[bool] = None, + ): + self.SecurityRoleId = SecurityRoleId + self.SecurityRoleName = SecurityRoleName + self.IsAdministrator = IsAdministrator + self.ID = ID + self.Name = Name + self.Description = Description + self.SystemClass = SystemClass + self.IsDefault = IsDefault + self.IsActive = IsActive + + +class Person(BaseModel): + def __init__( + self, + UID: Optional[str] = None, + ReferenceID: Optional[int] = None, + BEID: Optional[str] = None, + BEIDInt: Optional[int] = None, + IsActive: Optional[bool] = None, + IsConfidential: Optional[bool] = None, + UserName: Optional[str] = None, + FullName: Optional[str] = None, + FirstName: Optional[str] = None, + LastName: Optional[str] = None, + MiddleName: Optional[str] = None, + Salutation: Optional[str] = None, + Nickname: Optional[str] = None, + DefaultAccountID: Optional[int] = None, + DefaultAccountName: Optional[str] = None, + PrimaryEmail: Optional[str] = None, + AlternateEmail: Optional[str] = None, + ExternalID: Optional[str] = None, + AlternateID: Optional[str] = None, + Applications: Optional[List[str]] = None, + SecurityRoleName: Optional[str] = None, + SecurityRoleID: Optional[str] = None, + Permissions: Optional[List[str]] = None, + OrgApplications: Optional[List[OrgApplication]] = None, + PrimaryClientPortalApplicationID: Optional[any] = None, + GroupIDs: Optional[List[int]] = None, + AlertEmail: Optional[str] = None, + ProfileImageFileName: Optional[str] = None, + Company: Optional[str] = None, + Title: Optional[str] = None, + HomePhone: Optional[str] = None, + PrimaryPhone: Optional[str] = None, + WorkPhone: Optional[str] = None, + Pager: Optional[str] = None, + OtherPhone: Optional[str] = None, + MobilePhone: Optional[str] = None, + Fax: Optional[str] = None, + DefaultPriorityID: Optional[int] = None, + DefaultPriorityName: Optional[str] = None, + AboutMe: Optional[str] = None, + WorkAddress: Optional[str] = None, + WorkCity: Optional[str] = None, + WorkState: Optional[str] = None, + WorkZip: Optional[str] = None, + WorkCountry: Optional[str] = None, + HomeAddress: Optional[str] = None, + HomeCity: Optional[str] = None, + HomeState: Optional[str] = None, + HomeZip: Optional[str] = None, + HomeCountry: Optional[str] = None, + LocationID: Optional[int] = None, + LocationName: Optional[str] = None, + LocationRoomID: Optional[int] = None, + LocationRoomName: Optional[str] = None, + DefaultRate: Optional[float] = None, + CostRate: Optional[float] = None, + IsEmployee: Optional[bool] = None, + WorkableHours: Optional[float] = None, + IsCapacityManaged: Optional[bool] = None, + ReportTimeAfterDate: Optional[str] = None, + EndDate: Optional[str] = None, + ShouldReportTime: Optional[bool] = None, + ReportsToUID: Optional[str] = None, + ReportsToFullName: Optional[str] = None, + ResourcePoolID: Optional[int] = None, + ResourcePoolName: Optional[str] = None, + TZID: Optional[int] = None, + TZName: Optional[str] = None, + TypeID: Optional[int] = None, + AuthenticationUserName: Optional[str] = None, + AuthenticationProviderID: Optional[int] = None, + Attributes: Optional[List[Dict[str, any]]] = None, + IMProvider: Optional[str] = None, + IMHandle: Optional[str] = None, + ): + self.UID = UID + self.ReferenceID = ReferenceID + self.BEID = BEID + self.BEIDInt = BEIDInt + self.IsActive = IsActive + self.IsConfidential = IsConfidential + self.UserName = UserName + self.FullName = FullName + self.FirstName = FirstName + self.LastName = LastName + self.MiddleName = MiddleName + self.Salutation = Salutation + self.Nickname = Nickname + self.DefaultAccountID = DefaultAccountID + self.DefaultAccountName = DefaultAccountName + self.PrimaryEmail = PrimaryEmail + self.AlternateEmail = AlternateEmail + self.ExternalID = ExternalID + self.AlternateID = AlternateID + self.Applications = Applications + self.SecurityRoleName = SecurityRoleName + self.SecurityRoleID = SecurityRoleID + self.Permissions = Permissions + self.OrgApplications = OrgApplications + self.PrimaryClientPortalApplicationID = PrimaryClientPortalApplicationID + self.GroupIDs = GroupIDs + self.AlertEmail = AlertEmail + self.ProfileImageFileName = ProfileImageFileName + self.Company = Company + self.Title = Title + self.HomePhone = HomePhone + self.PrimaryPhone = PrimaryPhone + self.WorkPhone = WorkPhone + self.Pager = Pager + self.OtherPhone = OtherPhone + self.MobilePhone = MobilePhone + self.Fax = Fax + self.DefaultPriorityID = DefaultPriorityID + self.DefaultPriorityName = DefaultPriorityName + self.AboutMe = AboutMe + self.WorkAddress = WorkAddress + self.WorkCity = WorkCity + self.WorkState = WorkState + self.WorkZip = WorkZip + self.WorkCountry = WorkCountry + self.HomeAddress = HomeAddress + self.HomeCity = HomeCity + self.HomeState = HomeState + self.HomeZip = HomeZip + self.HomeCountry = HomeCountry + self.LocationID = LocationID + self.LocationName = LocationName + self.LocationRoomID = LocationRoomID + self.LocationRoomName = LocationRoomName + self.DefaultRate = DefaultRate + self.CostRate = CostRate + self.IsEmployee = IsEmployee + self.WorkableHours = WorkableHours + self.IsCapacityManaged = IsCapacityManaged + self.ReportTimeAfterDate = ReportTimeAfterDate + self.EndDate = EndDate + self.ShouldReportTime = ShouldReportTime + self.ReportsToUID = ReportsToUID + self.ReportsToFullName = ReportsToFullName + self.ResourcePoolID = ResourcePoolID + self.ResourcePoolName = ResourcePoolName + self.TZID = TZID + self.TZName = TZName + self.TypeID = TypeID + self.AuthenticationUserName = AuthenticationUserName + self.AuthenticationProviderID = AuthenticationProviderID + self.Attributes = Attributes + self.IMProvider = IMProvider + self.IMHandle = IMHandle diff --git a/pytdx/tdx.py b/pytdx/tdx.py index 329ad4d..1b21c5a 100644 --- a/pytdx/tdx.py +++ b/pytdx/tdx.py @@ -8,6 +8,7 @@ from .models.attribute import AttributeChoice from .models.asset import Asset, AssetModel from .models.knowledge_article import KnowledgeArticle +from .models.person import Person class Tdx: @@ -62,6 +63,7 @@ def __init__( # Define urls self.tdx_api_base_url = f"https://{self.hostname}/{api_path}" + self.people_url = f"{self.tdx_api_base_url}/api/people" if self.ticketing_app_id: self.tickets_url = ( f"{self.tdx_api_base_url}/api/{self.ticketing_app_id}/tickets" @@ -118,6 +120,7 @@ def __valid_custom_classes(self): Asset, AssetModel, KnowledgeArticle, + Person, ) def __to_patch_payload( @@ -532,3 +535,19 @@ def search_kb_articles( response = self.__request("POST", url=url, data=search_payload) return [KnowledgeArticle(**item) for item in response] + + # + # PERSON + # + + def get_person( + self, + person_id: int, + ) -> Person: + """ + Get a single person + """ + url = f"{self.people_url}/{person_id}" + + response = self.__request("GET", url=url) + return Person(**response) diff --git a/tests/test_tdx.py b/tests/test_tdx.py index 9201d1b..5c5596f 100644 --- a/tests/test_tdx.py +++ b/tests/test_tdx.py @@ -7,6 +7,7 @@ from pytdx.models.attribute import AttributeChoice from pytdx.models.asset import Asset, AssetModel from pytdx.models.knowledge_article import KnowledgeArticle +from pytdx.models.person import Person conn_info_encoded = os.environ.get("TDX_SB_CONN") conn_info = json.loads(base64.b64decode(conn_info_encoded)) @@ -110,6 +111,12 @@ def test_update_ticket_with_mock(mocker, tdx_client): assert isinstance(updated_ticket, Ticket) +def test_get_person(tdx_client): + result = tdx_client.get_person(person_id="eb449a7d-df73-ee11-826a-0050f2f4736d") + assert result.UID == "eb449a7d-df73-ee11-826a-0050f2f4736d" + assert isinstance(result, Person) + + ### Admin tests """