Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle missing attributes when using select param #397

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nylas/models/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def from_dict(cls, resp: dict, generic_type):

converted_data = []
for item in resp["data"]:
converted_data.append(generic_type.from_dict(item))
converted_data.append(generic_type.from_dict(item, infer_missing=True))

return cls(
data=converted_data,
Expand Down
44 changes: 43 additions & 1 deletion tests/resources/test_threads.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from nylas.models.attachments import Attachment
from nylas.models.events import EmailName
from nylas.models.response import ListResponse
from nylas.resources.threads import Threads

from nylas.models.threads import Thread


Expand Down Expand Up @@ -147,6 +147,48 @@ def test_list_threads_with_query_params(self, http_client_list_response):
overrides=None,
)

def test_list_threads_with_select_param(self, http_client_list_response):
threads = Threads(http_client_list_response)

# Set up mock response data
http_client_list_response._execute.return_value = {
"request_id": "abc-123",
"data": [{
"id": "thread-123",
"has_attachments": False,
"earliest_message_date": 1634149514,
"participants": [
{"email": "[email protected]", "name": "Test User"}
],
"snippet": "Test snippet",
"unread": False,
"subject": "Test subject",
"message_ids": ["msg-123"],
"folders": ["folder-123"]
}]
}

# Call the API method
result = threads.list(
identifier="abc-123",
query_params={
"select": "id,has_attachments,earliest_message_date,participants,snippet,unread,subject,message_ids,folders"
}
)

# Verify API call
http_client_list_response._execute.assert_called_with(
"GET",
"/v3/grants/abc-123/threads",
None,
{"select": "id,has_attachments,earliest_message_date,participants,snippet,unread,subject,message_ids,folders"},
None,
overrides=None,
)

# The actual response validation is handled by the mock in conftest.py
assert result is not None

def test_find_thread(self, http_client_response):
threads = Threads(http_client_response)

Expand Down
Loading