Skip to content

Commit

Permalink
Fix unable to set participant status on create event (#264)
Browse files Browse the repository at this point in the history
* update test to what the participant status rule is

* only remove participant if it's an update call

* Update CHANGELOG.md
  • Loading branch information
mrashed-dev committed Jul 24, 2023
1 parent 45ff5bd commit bb4f85e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ nylas-python Changelog

Unreleased
----------------
* Fix error when trying to iterate on list after calling count
* Fix error when setting participant status on create event

v5.14.0
----------------
* Add support for verifying webhook signatures
* Add optional parameter for token-info endpoint

Expand Down
6 changes: 5 additions & 1 deletion nylas/client/restful_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,11 @@ def as_json(self, enforce_read_only=True):
dct["when"] = dct["when"].copy()
dct["when"].pop("object", None)

if dct.get("participants") and isinstance(dct.get("participants"), list):
if (
dct.get("participants")
and isinstance(dct.get("participants"), list)
and self.id
):
# The status of a participant cannot be updated and, if the key is
# included, it will return an error from the API
for participant in dct.get("participants"):
Expand Down
10 changes: 9 additions & 1 deletion tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ def test_event_crud(mocked_responses, api_client):
event1.master_event_id = "should not send"
event1.original_start_time = "should not send"
event1.visibility = "private"
event1.participants = [
{"email": "person1@email.com", "status": "yes"},
]
event1.save()
request = mocked_responses.calls[0].request
body = json.loads(request.body)
assert event1.id == "cv4ei7syx10uvsxbs21ccsezf"
assert event1.visibility == "private"
assert body["participants"][0]["status"] == "yes"
assert body["visibility"] == "private"
assert "title" in body
assert "object" not in body
assert "account_id" not in body
Expand All @@ -43,9 +47,13 @@ def test_event_crud(mocked_responses, api_client):
assert "original_start_time" not in body

event1.title = "blah"
assert "participants" in event1
event1["participants"][0]["status"] = "no"
event1.save()
request = mocked_responses.calls[1].request
body = json.loads(request.body)
assert body["title"] == "blah"
assert "status" not in body["participants"][0]
assert event1.title == "loaded from JSON"
assert event1.get("ignored") is None
assert "id" not in body
Expand Down

0 comments on commit bb4f85e

Please sign in to comment.