Skip to content

Commit 0f20877

Browse files
author
David Baumgold
authored
Merge pull request #137 from nylas/event-rsvp-check-message-id
Check message ID before trying to RSVP to an event
2 parents d7a30e8 + 68aa5a9 commit 0f20877

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

nylas/client/restful_models.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,10 @@ def as_json(self):
611611
return dct
612612

613613
def rsvp(self, status, comment=None):
614+
if not self.message_id:
615+
raise ValueError(
616+
"This event was not imported from an iCalendar invite, and so it is not possible to RSVP via Nylas"
617+
)
614618
if status not in {"yes", "no", "maybe"}:
615619
raise ValueError("invalid status: {status}".format(status=status))
616620

tests/conftest.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,7 @@ def mock_events(mocked_responses, api_url):
11141114
[
11151115
{
11161116
"id": "1234abcd5678",
1117+
"message_id": "evh5uy0shhpm5d0le89goor17",
11171118
"title": "Pool party",
11181119
"location": "Local Community Pool",
11191120
"participants": [
@@ -1130,7 +1131,13 @@ def mock_events(mocked_responses, api_url):
11301131
"status": "no",
11311132
},
11321133
],
1133-
}
1134+
},
1135+
{
1136+
"id": "9876543cba",
1137+
"message_id": None,
1138+
"title": "Event Without Message",
1139+
"description": "This event does not have a corresponding message ID.",
1140+
},
11341141
]
11351142
)
11361143
endpoint = re.compile(api_url + "/events")

tests/test_events.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,16 @@ def test_event_rsvp_with_comment(mocked_responses, api_client):
7676

7777

7878
@pytest.mark.usefixtures("mock_events")
79-
def test_event_rsvp_invalid(mocked_responses, api_client):
79+
def test_event_rsvp_invalid(api_client):
8080
event = api_client.events.first()
81-
with pytest.raises(ValueError):
81+
with pytest.raises(ValueError) as excinfo:
8282
event.rsvp("purple")
83+
assert "invalid status" in str(excinfo)
84+
85+
86+
@pytest.mark.usefixtures("mock_events")
87+
def test_event_rsvp_no_message(api_client):
88+
event = api_client.events.all()[1]
89+
with pytest.raises(ValueError) as excinfo:
90+
event.rsvp("yes")
91+
assert "This event was not imported from an iCalendar invite" in str(excinfo)

0 commit comments

Comments
 (0)