Skip to content

Commit 6acd150

Browse files
authored
[TSDK-298] Support collective and group events (nylas#217)
This PR bring support to collective and group events.
1 parent 444efed commit 6acd150

4 files changed

Lines changed: 68 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
nylas-python Changelog
22
======================
33

4+
Unreleased
5+
----------------
6+
* Add support for collective and group events
7+
48
v5.8.0
59
----------------
610
* Add support for getting the number of queried objects (count view)

nylas/client/client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ def availability(
316316
interval,
317317
start_at,
318318
end_at,
319+
event_collection_id=None,
319320
buffer=None,
320321
round_robin=None,
321322
free_busy=None,
@@ -356,6 +357,8 @@ def availability(
356357
data["buffer"] = buffer
357358
if round_robin is not None:
358359
data["round_robin"] = round_robin
360+
if event_collection_id is not None:
361+
data["event_collection_id"] = event_collection_id
359362

360363
resp = self._request(HttpMethod.POST, url, json=data, cls=Calendar)
361364
_validate(resp)

nylas/client/restful_models.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,9 @@ class Event(NylasAPIObject):
671671
"ical_uid",
672672
"metadata",
673673
"notifications",
674+
"event_collection_id",
675+
"capacity",
676+
"round_robin_order",
674677
]
675678
datetime_attrs = {"original_start_at": "original_start_time"}
676679
collection_name = "events"
@@ -772,7 +775,7 @@ def generate_ics(self, ical_uid=None, method=None, prodid=None):
772775
"Unexpected response from the API server. Returned 200 but no 'ics' string found."
773776
)
774777

775-
def save(self, **kwargs):
778+
def validate(self):
776779
if (
777780
self.conferencing
778781
and "details" in self.conferencing
@@ -781,6 +784,18 @@ def save(self, **kwargs):
781784
raise ValueError(
782785
"Cannot set both 'details' and 'autocreate' in conferencing object."
783786
)
787+
if (
788+
self.capacity
789+
and self.capacity != -1
790+
and self.participants
791+
and len(self.participants) > self.capacity
792+
):
793+
raise ValueError(
794+
"The number of participants in the event exceeds the set capacity."
795+
)
796+
797+
def save(self, **kwargs):
798+
self.validate()
784799

785800
super(Event, self).save(**kwargs)
786801

tests/test_events.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,51 @@ def test_event_conferencing_details_autocreate_error(mocked_responses, api_clien
138138
)
139139

140140

141+
@pytest.mark.usefixtures("mock_event_create_response")
142+
def test_event_error_if_participants_more_than_capacity(mocked_responses, api_client):
143+
event = blank_event(api_client)
144+
event.capacity = 1
145+
event.participants = [
146+
{"email": "person1@email.com"},
147+
{"email": "person2@email.com"},
148+
]
149+
with pytest.raises(ValueError) as excinfo:
150+
event.save()
151+
assert "The number of participants in the event exceeds the set capacity." in str(
152+
excinfo
153+
)
154+
155+
156+
@pytest.mark.usefixtures("mock_event_create_response")
157+
def test_event_no_error_if_capacity_negative_one(mocked_responses, api_client):
158+
event = blank_event(api_client)
159+
event.capacity = -1
160+
event.participants = [
161+
{"email": "person1@email.com"},
162+
{"email": "person2@email.com"},
163+
]
164+
event.save()
165+
166+
167+
@pytest.mark.usefixtures("mock_event_create_response")
168+
def test_event_no_error_if_participants_less_than_eql_capacity(
169+
mocked_responses, api_client
170+
):
171+
event = blank_event(api_client)
172+
event.capacity = 2
173+
event.participants = [
174+
{"email": "person1@email.com"},
175+
{"email": "person2@email.com"},
176+
]
177+
event.save()
178+
event.capacity = 3
179+
event.participants = [
180+
{"email": "person1@email.com"},
181+
{"email": "person2@email.com"},
182+
]
183+
event.save()
184+
185+
141186
@pytest.mark.usefixtures("mock_calendars", "mock_events")
142187
def test_calendar_events(api_client):
143188
calendar = api_client.calendars.first()

0 commit comments

Comments
 (0)