Skip to content

Commit

Permalink
Add Events Helpers to PDI Connector (move-coop#865)
Browse files Browse the repository at this point in the history
* add helpers to Events object

* stage docstring

* add docs

* linting

* fix typo + enforce validation

* add return docs

* add events tests

* use mock pdi

* jk

* mark live tests

* add alias

* drop unused imports
  • Loading branch information
IanRFerguson authored Aug 16, 2023
1 parent 07174ad commit 1ab1c10
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 1 deletion.
81 changes: 80 additions & 1 deletion parsons/pdi/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __init__(self):
self.calendars_url = self.base_url + "/calendars"
self.eventactivities_url = self.base_url + "/eventActivities"
self.activites_url = self.base_url + "/activities"
self.activityassignment_url = self.base_url + "/eventActivityAssignements"
self.activityassignment_url = self.base_url + "/eventActivityAssignments"

super().__init__()

Expand Down Expand Up @@ -506,3 +506,82 @@ def update_activity_assignment(
)

return response

def get_event_activity_assignments(self, start_date, end_date, expand, limit=None):
"""
Get a list of event activity assignments.
Relevant API docs:
https://api.bluevote.com/docs/index#/EventActivityAssignments
`Args`:
start_date: str
Earliest records to be returned in the API response
Per the API docs, use "YYYY-MM-DD" format
end_date: str
Latest records to be returned in the API response.
Per the API docs, use "YYYY-MM-DD" format
expand: bool
Parameter to determine if we return the list of shift assigments
expanded or not
limit: int
Specify limit to return (max=2000)
`Returns`:
Parsons Table with event activity assignment responses
"""

if limit and limit > 2000:
raise ValueError("Maximum allowed limit is 2000")

params = {"startDate": start_date, "endDate": end_date, "expand": expand}
return self._request(self.activityassignment_url, args=params, limit=limit)

def get_event_activities(self, start_date, end_date, limit=None):
"""
Get a list of event activities.
Relevant API docs:
https://api.bluevote.com/docs/index#!/EventActivities/EventActivities_GetAll
`Args`:
start_date: str
Earliest records to be returned in the API response
Per the API docs, use "YYYY-MM-DD" format
end_date: str
Latest records to be returned in the API response.
Per the API docs, use "YYYY-MM-DD" format
limit: int
Specify limit to return (max=2000)
`Returns`:
Parsons Table with event activity responses
"""

if limit and limit > 2000:
raise ValueError("Maximum allowed limit is 2000")

params = {"startDate": start_date, "endDate": end_date}
return self._request(self.eventactivities_url, args=params, limit=limit)

def get_calendars(self, limit=None):
"""
Gets a list of calendars.
Relevant API docs:
https://api.bluevote.com/docs/index#!/Calendars/Calendars_GetAll
`Args`:
limit: int
Specify limit to return (max=2000)
`Returns`:
Parsons Table object with id, name, description, and timeZone records
"""

if limit and limit > 2000:
raise ValueError("Maximum allowed limit is 2000")

return self._request(self.calendars_url, limit=limit)
62 changes: 62 additions & 0 deletions test/test_pdi/test_events.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from test.utils import mark_live_test
from parsons import Table


#####

START_DATE = "2020-01-01"
END_DATE = "2022-12-31"
EXPAND = True
LOWER_LIMIT = 1

# TODO: Invoke this, it should fail as 2000 is the max limit for
# all of the relevant events functions
UPPER_LIMIT = 2001


@mark_live_test
def test_get_calendars(live_pdi):
response = live_pdi.get_calendars()

assert type(response) == Table


@mark_live_test
def test_get_calendars_with_limit(live_pdi):
response = live_pdi.get_calendars(limit=LOWER_LIMIT)

assert response.num_rows == 1


@mark_live_test
def test_get_event_activities(live_pdi):
response = live_pdi.get_event_activities(start_date=START_DATE, end_date=END_DATE)

assert type(response) == Table


@mark_live_test
def test_get_event_activities_with_limit(live_pdi):
response = live_pdi.get_event_activities(
start_date=START_DATE, end_date=END_DATE, limit=LOWER_LIMIT
)

assert response.num_rows == 1


@mark_live_test
def test_get_event_activity_assignments(live_pdi):
response = live_pdi.get_event_activity_assignments(
start_date=START_DATE, end_date=END_DATE, expand=EXPAND
)

assert type(response) == Table


@mark_live_test
def test_get_event_activity_assignments_with_limit(live_pdi):
response = live_pdi.get_event_activity_assignments(
start_date=START_DATE, end_date=END_DATE, expand=EXPAND
)

assert response.num_rows == 1

0 comments on commit 1ab1c10

Please sign in to comment.