MCPcopy Index your code
hub / github.com/O365/python-o365 / TestMessageApiCalls

Class TestMessageApiCalls

tests/test_message.py:138–348  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

136
137
138class TestMessageApiCalls:
139 base_url = MSGraphProtocol().service_url
140
141 def test_save_draft_with_small_attachment(self):
142 msg = message()
143 msg.subject = "Test"
144 msg.attachments.add([(io.BytesIO(b"content"), "filename.txt")])
145
146 assert msg.save_draft() is True
147 [call] = msg.con.calls
148 assert call.url == self.base_url + "me/mailFolders/Drafts/messages"
149 assert call.payload == {
150 "attachments": [
151 {
152 "@odata.type": "#microsoft.graph.fileAttachment",
153 "contentBytes": "Y29udGVudA==",
154 "name": "filename.txt",
155 }
156 ],
157 "body": {"content": "", "contentType": "HTML"},
158 "flag": {"flagStatus": "notFlagged"},
159 "importance": "normal",
160 "isDeliveryReceiptRequested": False,
161 "isReadReceiptRequested": False,
162 "subject": "Test",
163 }
164
165 def test_save_draft_with_with_small_attachment_when_object_id_is_set(self):
166 msg = message(__cloud_data__={"id": "123", "isDraft": True})
167 msg.attachments.add([(io.BytesIO(b"content"), "filename.txt")])
168
169 assert msg.save_draft() is True
170 [call] = msg.con.calls
171 assert call.url == self.base_url + "me/messages/123/attachments"
172 assert call.payload == {
173 "@odata.type": "#microsoft.graph.fileAttachment",
174 "contentBytes": "Y29udGVudA==",
175 "name": "filename.txt",
176 }
177
178 @mock.patch("O365.utils.attachment.UPLOAD_SIZE_LIMIT_SIMPLE", 7)
179 @mock.patch("O365.utils.attachment.DEFAULT_UPLOAD_CHUNK_SIZE", 5)
180 def test_save_draft_with_with_large_attachment_when_object_id_is_set(self):
181 upload_url = "https://sn3302.up.1drv.com/up/foobar"
182
183 msg = message(__cloud_data__={"id": "123", "isDraft": True})
184 msg.attachments.add([(io.BytesIO(b"long-content"), "filename.txt")])
185
186 msg.con.responses.clear()
187 msg.con.responses.extend(
188 [
189 MockResponse({"uploadUrl": upload_url}),
190 MockResponse({}),
191 MockResponse({}),
192 MockResponse({}),
193 MockResponse({}),
194 ]
195 )

Callers

nothing calls this directly

Calls 1

MSGraphProtocolClass · 0.90

Tested by

no test coverage detected