Skip to content
This repository has been archived by the owner on May 9, 2024. It is now read-only.

Commit

Permalink
add person method
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Rossow-Greenberg committed Feb 23, 2024
1 parent d962840 commit e9f106d
Show file tree
Hide file tree
Showing 3 changed files with 206 additions and 0 deletions.
180 changes: 180 additions & 0 deletions pytdx/models/person.py
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions pytdx/tdx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -118,6 +120,7 @@ def __valid_custom_classes(self):
Asset,
AssetModel,
KnowledgeArticle,
Person,
)

def __to_patch_payload(
Expand Down Expand Up @@ -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)
7 changes: 7 additions & 0 deletions tests/test_tdx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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

"""
Expand Down

0 comments on commit e9f106d

Please sign in to comment.