From 5aa7f8b32be2b6486a79ca315d3c3db6e56d508e Mon Sep 17 00:00:00 2001 From: LilSpazJoekp <15524072+LilSpazJoekp@users.noreply.github.com> Date: Tue, 11 Jul 2023 15:38:23 -0500 Subject: [PATCH] Fix modmail reply bug (cherry picked from commit praw-dev/praw@5984516aa37a09c858c61dbbeda584adc9fd6c1d) --- CHANGES.rst | 4 + asyncpraw/models/reddit/modmail.py | 12 +- ...mailConversation.test_reply__internal.json | 310 ++++++++++++++++++ .../integration/models/reddit/test_modmail.py | 7 + 4 files changed, 330 insertions(+), 3 deletions(-) create mode 100644 tests/integration/cassettes/TestModmailConversation.test_reply__internal.json diff --git a/CHANGES.rst b/CHANGES.rst index ab3ece0f..3b1a3b49 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,6 +6,10 @@ Async PRAW follows `semantic versioning `_. Unreleased ---------- +**Fixed** + +- An issue with replying to a modmail conversation results in a error. + 7.7.0 (2023/02/25) ------------------ diff --git a/asyncpraw/models/reddit/modmail.py b/asyncpraw/models/reddit/modmail.py index 7dc178fd..135ee989 100644 --- a/asyncpraw/models/reddit/modmail.py +++ b/asyncpraw/models/reddit/modmail.py @@ -272,9 +272,15 @@ async def reply( response = await self._reddit.post( API_PATH["modmail_conversation"].format(id=self.id), data=data ) - message_id = response["conversation"]["objIds"][-1]["id"] - message_data = response["messages"][message_id] - return self._reddit._objector.objectify(message_data) + if isinstance(response, dict): + # Reddit recently changed the response format, so we need to handle both in case they change it back + message_id = response["conversation"]["objIds"][-1]["id"] + message_data = response["messages"][message_id] + return self._reddit._objector.objectify(message_data) + else: + for message in response.messages: + if message.id == response.obj_ids[-1]["id"]: + return message async def unarchive(self): """Unarchive the conversation. diff --git a/tests/integration/cassettes/TestModmailConversation.test_reply__internal.json b/tests/integration/cassettes/TestModmailConversation.test_reply__internal.json new file mode 100644 index 00000000..881686f5 --- /dev/null +++ b/tests/integration/cassettes/TestModmailConversation.test_reply__internal.json @@ -0,0 +1,310 @@ +{ + "interactions": [ + { + "request": { + "body": [ + [ + "grant_type", + "refresh_token" + ], + [ + "refresh_token", + "" + ] + ], + "headers": { + "AUTHORIZATION": [ + "Basic " + ], + "Accept-Encoding": [ + "identity" + ], + "Connection": [ + "close" + ], + "User-Agent": [ + " Async PRAW/7.7.1.dev0 asyncprawcore/2.3.0" + ] + }, + "method": "POST", + "uri": "https://www.reddit.com/api/v1/access_token" + }, + "response": { + "body": { + "string": "{\"access_token\": \"\", \"token_type\": \"bearer\", \"expires_in\": 86400, \"refresh_token\": \"\", \"scope\": \"creddits modnote modcontributors modmail modconfig subscribe structuredstyles vote wikiedit mysubreddits submit modlog modposts modflair save modothers adsconversions read privatemessages report identity livemanage account modtraffic wikiread edit modwiki modself flair history\"}" + }, + "headers": { + "Accept-Ranges": [ + "bytes" + ], + "Cache-Control": [ + "private, max-age=3600" + ], + "Connection": [ + "close" + ], + "Content-Length": [ + "1546" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Date": [ + "Tue, 11 Jul 2023 20:55:58 GMT" + ], + "NEL": [ + "{\"report_to\": \"w3-reporting-nel\", \"max_age\": 14400, \"include_subdomains\": false, \"success_fraction\": 1.0, \"failure_fraction\": 1.0}" + ], + "Report-To": [ + "{\"group\": \"w3-reporting-nel\", \"max_age\": 14400, \"include_subdomains\": true, \"endpoints\": [{ \"url\": \"https://w3-reporting-nel.reddit.com/reports\" }]}, {\"group\": \"w3-reporting\", \"max_age\": 14400, \"include_subdomains\": true, \"endpoints\": [{ \"url\": \"https://w3-reporting.reddit.com/reports\" }]}, {\"group\": \"w3-reporting-csp\", \"max_age\": 14400, \"include_subdomains\": true, \"endpoints\": [{ \"url\": \"https://w3-reporting-csp.reddit.com/reports\" }]}" + ], + "Server": [ + "snooserv" + ], + "Set-Cookie": [ + "edgebucket=CfXvkEKpmnSHl71t3S; Domain=reddit.com; Max-Age=63071999; Path=/; secure" + ], + "Strict-Transport-Security": [ + "max-age=31536000; includeSubdomains" + ], + "Vary": [ + "accept-encoding" + ], + "Via": [ + "1.1 varnish" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "X-XSS-Protection": [ + "1; mode=block" + ], + "x-moose": [ + "majestic" + ] + }, + "status": { + "code": 200, + "message": "OK" + }, + "url": "https://www.reddit.com/api/v1/access_token" + } + }, + { + "request": { + "body": null, + "headers": { + "Accept-Encoding": [ + "identity" + ], + "Authorization": [ + "bearer " + ], + "Cookie": [ + "edgebucket=CfXvkEKpmnSHl71t3S" + ], + "User-Agent": [ + " Async PRAW/7.7.1.dev0 asyncprawcore/2.3.0" + ] + }, + "method": "GET", + "uri": "https://oauth.reddit.com/api/mod/conversations/1mahha?raw_json=1" + }, + "response": { + "body": { + "string": "{\"conversation\": {\"isAuto\": false, \"participant\": {\"isMod\": true, \"isAdmin\": false, \"name\": \"Lil_SpazTest\", \"isOp\": true, \"isParticipant\": true, \"isApproved\": false, \"isHidden\": false, \"id\": 561251419067, \"isDeleted\": false}, \"objIds\": [{\"id\": \"2bjn0i\", \"key\": \"messages\"}, {\"id\": \"2bjn0k\", \"key\": \"messages\"}, {\"id\": \"2bjn2z\", \"key\": \"messages\"}], \"isRepliable\": true, \"lastUserUpdate\": null, \"isInternal\": false, \"lastModUpdate\": \"2023-07-11T20:33:14.617000+0000\", \"authors\": [{\"isMod\": true, \"isAdmin\": false, \"name\": \"Lil_SpazTest\", \"isOp\": true, \"isParticipant\": true, \"isApproved\": false, \"isHidden\": false, \"id\": 561251419067, \"isDeleted\": false}], \"lastUpdated\": \"2023-07-11T20:33:14.617000+0000\", \"participantSubreddit\": {}, \"legacyFirstMessageId\": \"1wttevy\", \"state\": 1, \"conversationType\": \"sr_user\", \"lastUnread\": \"2023-07-11T20:33:14.617000+0000\", \"owner\": {\"displayName\": \"\", \"type\": \"subreddit\", \"id\": \"t5_29ey0j\"}, \"subject\": \"test\", \"id\": \"1mahha\", \"isHighlighted\": false, \"numMessages\": 3}, \"participantSubreddit\": {}, \"messages\": {\"2bjn0k\": {\"body\": \"

additional test

\\n
\", \"author\": {\"name\": \"Lil_SpazTest\", \"isApproved\": false, \"isMod\": true, \"isAdmin\": false, \"isOp\": true, \"isParticipant\": true, \"isHidden\": false, \"id\": 561251419067, \"isDeleted\": false}, \"isInternal\": true, \"date\": \"2023-07-11T20:32:12.025000+0000\", \"bodyMarkdown\": \"additional test\", \"id\": \"2bjn0k\", \"participatingAs\": \"moderator\"}, \"2bjn0i\": {\"body\": \"

testing

\\n
\", \"author\": {\"name\": \"Lil_SpazTest\", \"isApproved\": false, \"isMod\": true, \"isAdmin\": false, \"isOp\": true, \"isParticipant\": true, \"isHidden\": true, \"id\": 561251419067, \"isDeleted\": false}, \"isInternal\": false, \"date\": \"2023-07-11T20:32:11.586000+0000\", \"bodyMarkdown\": \"testing\", \"id\": \"2bjn0i\", \"participatingAs\": \"moderator\"}, \"2bjn2z\": {\"body\": \"

A message

\\n
\", \"author\": {\"name\": \"Lil_SpazTest\", \"isApproved\": false, \"isMod\": true, \"isAdmin\": false, \"isOp\": true, \"isParticipant\": true, \"isHidden\": false, \"id\": 561251419067, \"isDeleted\": false}, \"isInternal\": true, \"date\": \"2023-07-11T20:33:14.617000+0000\", \"bodyMarkdown\": \"A message\", \"id\": \"2bjn2z\", \"participatingAs\": \"moderator\"}}, \"user\": {\"recentComments\": {\"t1_i6yklz7\": {\"comment\": \"test reply\", \"date\": \"2022-05-01T22:37:21.936000+00:00\", \"permalink\": \"https://www.reddit.com/r//comments/uflrmv/test_post/i6yklz7/\", \"title\": \"Test post\"}}, \"muteStatus\": {\"muteCount\": 0, \"isMuted\": false, \"endDate\": null, \"reason\": \"\"}, \"name\": \"Lil_SpazTest\", \"created\": \"2020-07-04T21:34:49.063000+00:00\", \"banStatus\": {\"endDate\": null, \"reason\": \"\", \"isBanned\": false, \"isPermanent\": false}, \"isSuspended\": false, \"approveStatus\": {\"isApproved\": false}, \"isShadowBanned\": false, \"recentPosts\": {\"t3_z3wwe8\": {\"date\": \"2022-11-24T22:47:02.992000+00:00\", \"permalink\": \"https://www.reddit.com/r//comments/z3wwe8/test_post/\", \"title\": \"Test post\"}, \"t3_z4lkt4\": {\"date\": \"2022-11-25T19:16:07.058000+00:00\", \"permalink\": \"https://www.reddit.com/r//comments/z4lkt4/test_post/\", \"title\": \"Test post\"}, \"t3_z3x0le\": {\"date\": \"2022-11-24T22:52:25.348000+00:00\", \"permalink\": \"https://www.reddit.com/r//comments/z3x0le/test_post/\", \"title\": \"Test post\"}, \"t3_z3xa9p\": {\"date\": \"2022-11-24T23:04:17.179000+00:00\", \"permalink\": \"https://www.reddit.com/r//comments/z3xa9p/test_post/\", \"title\": \"Test post\"}, \"t3_z3wslj\": {\"date\": \"2022-11-24T22:42:19.611000+00:00\", \"permalink\": \"https://www.reddit.com/r//comments/z3wslj/test_post/\", \"title\": \"Test post\"}, \"t3_z3wtr9\": {\"date\": \"2022-11-24T22:43:43.212000+00:00\", \"permalink\": \"https://www.reddit.com/r//comments/z3wtr9/test_post/\", \"title\": \"Test post\"}, \"t3_z3wv0z\": {\"date\": \"2022-11-24T22:45:18.381000+00:00\", \"permalink\": \"https://www.reddit.com/r//comments/z3wv0z/test_post/\", \"title\": \"Test post\"}, \"t3_z3x7gi\": {\"date\": \"2022-11-24T23:00:51.261000+00:00\", \"permalink\": \"https://www.reddit.com/r//comments/z3x7gi/test_post/\", \"title\": \"Test post\"}, \"t3_z3x64t\": {\"date\": \"2022-11-24T22:59:35.632000+00:00\", \"permalink\": \"https://www.reddit.com/r//comments/z3x64t/test_post/\", \"title\": \"Test post\"}, \"t3_14lt78w\": {\"date\": \"2023-06-29T02:57:46.846000+00:00\", \"permalink\": \"https://www.reddit.com/r//comments/14lt78w/hi/\", \"title\": \"hi\"}}, \"recentConvos\": {\"fjhla\": {\"date\": \"2020-07-16T01:15:55.263000+0000\", \"permalink\": \"https://mod.reddit.com/mail/perma/fjhla\", \"id\": \"fjhla\", \"subject\": \"Spam\"}, \"1magps\": {\"date\": \"2023-07-11T20:18:46.102000+0000\", \"permalink\": \"https://mod.reddit.com/mail/perma/1magps\", \"id\": \"1magps\", \"subject\": \"test\"}, \"1magq3\": {\"date\": \"2023-07-11T20:28:57.787000+0000\", \"permalink\": \"https://mod.reddit.com/mail/perma/1magq3\", \"id\": \"1magq3\", \"subject\": \"test\"}, \"1l7pjk\": {\"date\": \"2023-06-25T17:16:07.135000+0000\", \"permalink\": \"https://mod.reddit.com/mail/perma/1l7pjk\", \"id\": \"1l7pjk\", \"subject\": \"invitation to moderate /r/\"}, \"1mahha\": {\"date\": \"2023-07-11T20:33:14.617000+0000\", \"permalink\": \"https://mod.reddit.com/mail/perma/1mahha\", \"id\": \"1mahha\", \"subject\": \"test\"}, \"19u06q\": {\"date\": \"2022-11-20T19:21:19.387000+0000\", \"permalink\": \"https://mod.reddit.com/mail/perma/19u06q\", \"id\": \"19u06q\", \"subject\": \"invitation to moderate /r/\"}, \"1mahgy\": {\"date\": \"2023-07-11T20:32:00.840000+0000\", \"permalink\": \"https://mod.reddit.com/mail/perma/1mahgy\", \"id\": \"1mahgy\", \"subject\": \"test\"}, \"fjhnq\": {\"date\": \"2020-07-16T01:15:07.219000+0000\", \"permalink\": \"https://mod.reddit.com/mail/perma/fjhnq\", \"id\": \"fjhnq\", \"subject\": \"Spam\"}}, \"id\": \"t2_75u2lqkb\"}, \"modActions\": {}}" + }, + "headers": { + "Accept-Ranges": [ + "bytes" + ], + "Cache-Control": [ + "private, s-maxage=0, max-age=0, must-revalidate, no-store" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "5735" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Date": [ + "Tue, 11 Jul 2023 20:55:59 GMT" + ], + "Expires": [ + "-1" + ], + "NEL": [ + "{\"report_to\": \"w3-reporting-nel\", \"max_age\": 14400, \"include_subdomains\": false, \"success_fraction\": 1.0, \"failure_fraction\": 1.0}" + ], + "Report-To": [ + "{\"group\": \"w3-reporting-nel\", \"max_age\": 14400, \"include_subdomains\": true, \"endpoints\": [{ \"url\": \"https://w3-reporting-nel.reddit.com/reports\" }]}, {\"group\": \"w3-reporting\", \"max_age\": 14400, \"include_subdomains\": true, \"endpoints\": [{ \"url\": \"https://w3-reporting.reddit.com/reports\" }]}, {\"group\": \"w3-reporting-csp\", \"max_age\": 14400, \"include_subdomains\": true, \"endpoints\": [{ \"url\": \"https://w3-reporting-csp.reddit.com/reports\" }]}" + ], + "Server": [ + "snooserv" + ], + "Set-Cookie": [ + "loid=0000000000000o77bz.2.1434669370561.Z0FBQUFBQmtyY0hmOHJ4bjRhekotblA5ZnBsRnFxVTJWbTItcWNpVUtxM29NYWlCa2xkRnhCa3duQWJJVmF1Z1RObGpaLXRObHQ3OTktMmJtNWtLcmZNRGE4YjJaZm1FY1FzMGg1NjZQcy0xX3BkOXNReFpDeWNoSUtnbzJBZlg5dk9zY0l2OTE3czU; Domain=reddit.com; Max-Age=63071999; Path=/; expires=Thu, 10-Jul-2025 20:55:59 GMT; secure; SameSite=None; Secure", + "session_tracker=iaapcfaqcqnjnnfopb.0.1689108958922.Z0FBQUFBQmtyY0hmZzNuaUpqY2RuWUp6c3VzRXBaejVoaU5wSjc1T01YSG1iRVh2MkVTQkMyRzJOX0o3QVJua0dDQjB1MmtKMzlDYV9vdjJqc0R5X0R3WVFfV204ejFYc2hHdWR0bGZULVZJTFNSMlRyMVU1NTh5Z1dobUYtVnBXcENtMUpBZi14VDU; Domain=reddit.com; Max-Age=7199; Path=/; expires=Tue, 11-Jul-2023 22:55:59 GMT; secure; SameSite=None; Secure", + "csv=2; Max-Age=63072000; Domain=.reddit.com; Path=/; Secure; SameSite=None" + ], + "Strict-Transport-Security": [ + "max-age=31536000; includeSubdomains" + ], + "Vary": [ + "accept-encoding" + ], + "Via": [ + "1.1 varnish" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "X-XSS-Protection": [ + "1; mode=block" + ], + "x-moose": [ + "majestic" + ], + "x-ratelimit-remaining": [ + "995" + ], + "x-ratelimit-reset": [ + "242" + ], + "x-ratelimit-used": [ + "1" + ] + }, + "status": { + "code": 200, + "message": "OK" + }, + "url": "https://oauth.reddit.com/api/mod/conversations/1mahha?raw_json=1" + } + }, + { + "request": { + "body": [ + [ + "api_type", + "json" + ], + [ + "body", + "A message" + ], + [ + "isAuthorHidden", + "false" + ], + [ + "isInternal", + "true" + ] + ], + "headers": { + "Accept-Encoding": [ + "identity" + ], + "Authorization": [ + "bearer " + ], + "Cookie": [ + "csv=2; edgebucket=CfXvkEKpmnSHl71t3S; loid=0000000000000o77bz.2.1434669370561.Z0FBQUFBQmtyY0hmOHJ4bjRhekotblA5ZnBsRnFxVTJWbTItcWNpVUtxM29NYWlCa2xkRnhCa3duQWJJVmF1Z1RObGpaLXRObHQ3OTktMmJtNWtLcmZNRGE4YjJaZm1FY1FzMGg1NjZQcy0xX3BkOXNReFpDeWNoSUtnbzJBZlg5dk9zY0l2OTE3czU; session_tracker=iaapcfaqcqnjnnfopb.0.1689108958922.Z0FBQUFBQmtyY0hmZzNuaUpqY2RuWUp6c3VzRXBaejVoaU5wSjc1T01YSG1iRVh2MkVTQkMyRzJOX0o3QVJua0dDQjB1MmtKMzlDYV9vdjJqc0R5X0R3WVFfV204ejFYc2hHdWR0bGZULVZJTFNSMlRyMVU1NTh5Z1dobUYtVnBXcENtMUpBZi14VDU" + ], + "User-Agent": [ + " Async PRAW/7.7.1.dev0 asyncprawcore/2.3.0" + ] + }, + "method": "POST", + "uri": "https://oauth.reddit.com/api/mod/conversations/1mahha?raw_json=1" + }, + "response": { + "body": { + "string": "{\"conversation\": {\"isAuto\": false, \"participant\": {\"isMod\": true, \"isAdmin\": false, \"name\": \"Lil_SpazTest\", \"isOp\": false, \"isParticipant\": true, \"isApproved\": false, \"isHidden\": false, \"id\": 561251419067, \"isDeleted\": false}, \"objIds\": [{\"id\": \"2bjn0i\", \"key\": \"messages\"}, {\"id\": \"2bjn0k\", \"key\": \"messages\"}, {\"id\": \"2bjn2z\", \"key\": \"messages\"}, {\"id\": \"2bjot3\", \"key\": \"messages\"}], \"isRepliable\": true, \"lastUserUpdate\": null, \"isInternal\": false, \"lastModUpdate\": \"2023-07-11T20:55:59.200000+0000\", \"authors\": [{\"isMod\": true, \"isAdmin\": false, \"name\": \"Lil_SpazTest\", \"isOp\": false, \"isParticipant\": true, \"isApproved\": false, \"isHidden\": false, \"id\": 561251419067, \"isDeleted\": false}, {\"isMod\": true, \"isAdmin\": false, \"name\": \"\", \"isOp\": true, \"isParticipant\": false, \"isApproved\": true, \"isHidden\": false, \"id\": 40646879, \"isDeleted\": false}], \"lastUpdated\": \"2023-07-11T20:55:59.200000+0000\", \"participantSubreddit\": {}, \"legacyFirstMessageId\": \"1wttevy\", \"state\": 1, \"conversationType\": \"sr_user\", \"lastUnread\": \"2023-07-11T20:33:14.617000+0000\", \"owner\": {\"displayName\": \"\", \"type\": \"subreddit\", \"id\": \"t5_29ey0j\"}, \"subject\": \"test\", \"id\": \"1mahha\", \"isHighlighted\": false, \"numMessages\": 4}, \"participantSubreddit\": {}, \"messages\": {\"2bjn0k\": {\"body\": \"

additional test

\\n
\", \"author\": {\"name\": \"Lil_SpazTest\", \"isApproved\": false, \"isMod\": true, \"isAdmin\": false, \"isOp\": false, \"isParticipant\": true, \"isHidden\": false, \"id\": 561251419067, \"isDeleted\": false}, \"isInternal\": true, \"date\": \"2023-07-11T20:32:12.025000+0000\", \"bodyMarkdown\": \"additional test\", \"id\": \"2bjn0k\", \"participatingAs\": \"moderator\"}, \"2bjn0i\": {\"body\": \"

testing

\\n
\", \"author\": {\"name\": \"Lil_SpazTest\", \"isApproved\": false, \"isMod\": true, \"isAdmin\": false, \"isOp\": false, \"isParticipant\": true, \"isHidden\": true, \"id\": 561251419067, \"isDeleted\": false}, \"isInternal\": false, \"date\": \"2023-07-11T20:32:11.586000+0000\", \"bodyMarkdown\": \"testing\", \"id\": \"2bjn0i\", \"participatingAs\": \"moderator\"}, \"2bjot3\": {\"body\": \"

A message

\\n
\", \"author\": {\"name\": \"\", \"isApproved\": true, \"isMod\": true, \"isAdmin\": false, \"isOp\": true, \"isParticipant\": false, \"isHidden\": false, \"id\": 40646879, \"isDeleted\": false}, \"isInternal\": true, \"date\": \"2023-07-11T20:55:59.200000+0000\", \"bodyMarkdown\": \"A message\", \"id\": \"2bjot3\", \"participatingAs\": \"moderator\"}, \"2bjn2z\": {\"body\": \"

A message

\\n
\", \"author\": {\"name\": \"Lil_SpazTest\", \"isApproved\": false, \"isMod\": true, \"isAdmin\": false, \"isOp\": false, \"isParticipant\": true, \"isHidden\": false, \"id\": 561251419067, \"isDeleted\": false}, \"isInternal\": true, \"date\": \"2023-07-11T20:33:14.617000+0000\", \"bodyMarkdown\": \"A message\", \"id\": \"2bjn2z\", \"participatingAs\": \"moderator\"}}, \"user\": {\"recentComments\": {\"t1_i6yklz7\": {\"comment\": \"test reply\", \"date\": \"2022-05-01T22:37:21.936000+00:00\", \"permalink\": \"https://www.reddit.com/r//comments/uflrmv/test_post/i6yklz7/\", \"title\": \"Test post\"}}, \"muteStatus\": {\"muteCount\": 0, \"isMuted\": false, \"endDate\": null, \"reason\": \"\"}, \"name\": \"Lil_SpazTest\", \"created\": \"2020-07-04T21:34:49.063000+00:00\", \"banStatus\": {\"endDate\": null, \"reason\": \"\", \"isBanned\": false, \"isPermanent\": false}, \"isSuspended\": false, \"approveStatus\": {\"isApproved\": false}, \"isShadowBanned\": false, \"recentPosts\": {\"t3_z3wwe8\": {\"date\": \"2022-11-24T22:47:02.992000+00:00\", \"permalink\": \"https://www.reddit.com/r//comments/z3wwe8/test_post/\", \"title\": \"Test post\"}, \"t3_z4lkt4\": {\"date\": \"2022-11-25T19:16:07.058000+00:00\", \"permalink\": \"https://www.reddit.com/r//comments/z4lkt4/test_post/\", \"title\": \"Test post\"}, \"t3_z3x0le\": {\"date\": \"2022-11-24T22:52:25.348000+00:00\", \"permalink\": \"https://www.reddit.com/r//comments/z3x0le/test_post/\", \"title\": \"Test post\"}, \"t3_z3xa9p\": {\"date\": \"2022-11-24T23:04:17.179000+00:00\", \"permalink\": \"https://www.reddit.com/r//comments/z3xa9p/test_post/\", \"title\": \"Test post\"}, \"t3_z3wslj\": {\"date\": \"2022-11-24T22:42:19.611000+00:00\", \"permalink\": \"https://www.reddit.com/r//comments/z3wslj/test_post/\", \"title\": \"Test post\"}, \"t3_z3wtr9\": {\"date\": \"2022-11-24T22:43:43.212000+00:00\", \"permalink\": \"https://www.reddit.com/r//comments/z3wtr9/test_post/\", \"title\": \"Test post\"}, \"t3_z3wv0z\": {\"date\": \"2022-11-24T22:45:18.381000+00:00\", \"permalink\": \"https://www.reddit.com/r//comments/z3wv0z/test_post/\", \"title\": \"Test post\"}, \"t3_z3x7gi\": {\"date\": \"2022-11-24T23:00:51.261000+00:00\", \"permalink\": \"https://www.reddit.com/r//comments/z3x7gi/test_post/\", \"title\": \"Test post\"}, \"t3_z3x64t\": {\"date\": \"2022-11-24T22:59:35.632000+00:00\", \"permalink\": \"https://www.reddit.com/r//comments/z3x64t/test_post/\", \"title\": \"Test post\"}, \"t3_14lt78w\": {\"date\": \"2023-06-29T02:57:46.846000+00:00\", \"permalink\": \"https://www.reddit.com/r//comments/14lt78w/hi/\", \"title\": \"hi\"}}, \"recentConvos\": {\"fjhla\": {\"date\": \"2020-07-16T01:15:55.263000+0000\", \"permalink\": \"https://mod.reddit.com/mail/perma/fjhla\", \"id\": \"fjhla\", \"subject\": \"Spam\"}, \"1magps\": {\"date\": \"2023-07-11T20:18:46.102000+0000\", \"permalink\": \"https://mod.reddit.com/mail/perma/1magps\", \"id\": \"1magps\", \"subject\": \"test\"}, \"1magq3\": {\"date\": \"2023-07-11T20:28:57.787000+0000\", \"permalink\": \"https://mod.reddit.com/mail/perma/1magq3\", \"id\": \"1magq3\", \"subject\": \"test\"}, \"1l7pjk\": {\"date\": \"2023-06-25T17:16:07.135000+0000\", \"permalink\": \"https://mod.reddit.com/mail/perma/1l7pjk\", \"id\": \"1l7pjk\", \"subject\": \"invitation to moderate /r/\"}, \"1mahha\": {\"date\": \"2023-07-11T20:55:59.200000+0000\", \"permalink\": \"https://mod.reddit.com/mail/perma/1mahha\", \"id\": \"1mahha\", \"subject\": \"test\"}, \"19u06q\": {\"date\": \"2022-11-20T19:21:19.387000+0000\", \"permalink\": \"https://mod.reddit.com/mail/perma/19u06q\", \"id\": \"19u06q\", \"subject\": \"invitation to moderate /r/\"}, \"1mahgy\": {\"date\": \"2023-07-11T20:32:00.840000+0000\", \"permalink\": \"https://mod.reddit.com/mail/perma/1mahgy\", \"id\": \"1mahgy\", \"subject\": \"test\"}, \"fjhnq\": {\"date\": \"2020-07-16T01:15:07.219000+0000\", \"permalink\": \"https://mod.reddit.com/mail/perma/fjhnq\", \"id\": \"fjhnq\", \"subject\": \"Spam\"}}, \"id\": \"t2_75u2lqkb\"}, \"modActions\": {}}" + }, + "headers": { + "Accept-Ranges": [ + "bytes" + ], + "Cache-Control": [ + "private, s-maxage=0, max-age=0, must-revalidate, no-store" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "6368" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Date": [ + "Tue, 11 Jul 2023 20:55:59 GMT" + ], + "Expires": [ + "-1" + ], + "NEL": [ + "{\"report_to\": \"w3-reporting-nel\", \"max_age\": 14400, \"include_subdomains\": false, \"success_fraction\": 1.0, \"failure_fraction\": 1.0}" + ], + "Report-To": [ + "{\"group\": \"w3-reporting-nel\", \"max_age\": 14400, \"include_subdomains\": true, \"endpoints\": [{ \"url\": \"https://w3-reporting-nel.reddit.com/reports\" }]}, {\"group\": \"w3-reporting\", \"max_age\": 14400, \"include_subdomains\": true, \"endpoints\": [{ \"url\": \"https://w3-reporting.reddit.com/reports\" }]}, {\"group\": \"w3-reporting-csp\", \"max_age\": 14400, \"include_subdomains\": true, \"endpoints\": [{ \"url\": \"https://w3-reporting-csp.reddit.com/reports\" }]}" + ], + "Server": [ + "snooserv" + ], + "Set-Cookie": [ + "session_tracker=iaapcfaqcqnjnnfopb.0.1689108959163.Z0FBQUFBQmtyY0hmV1RVVE5zaWJyRFJaczVrYUtjLVVuQk1qd1N3c2daTGNwazd0bjFSaUt5TUs2dWZoeldZMUlQcmR6YVZ2azJ4X2NrXzkxcnRpYzBfOC11dXNrX1l1TkhFaDg0QkMwUE1XSXhnZ3hyZ0h6UFV4eVFfWm1XYUdtUFNDdk1HczFtdGQ; Domain=reddit.com; Max-Age=7199; Path=/; expires=Tue, 11-Jul-2023 22:55:59 GMT; secure" + ], + "Strict-Transport-Security": [ + "max-age=31536000; includeSubdomains" + ], + "Vary": [ + "accept-encoding" + ], + "Via": [ + "1.1 varnish" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "X-XSS-Protection": [ + "1; mode=block" + ], + "x-moose": [ + "majestic" + ], + "x-ratelimit-remaining": [ + "994" + ], + "x-ratelimit-reset": [ + "241" + ], + "x-ratelimit-used": [ + "2" + ] + }, + "status": { + "code": 201, + "message": "Created" + }, + "url": "https://oauth.reddit.com/api/mod/conversations/1mahha?raw_json=1" + } + } + ], + "recorded_at": "2023-07-11T20:55:59", + "version": 1 +} diff --git a/tests/integration/models/reddit/test_modmail.py b/tests/integration/models/reddit/test_modmail.py index bd7791fa..115d2a36 100644 --- a/tests/integration/models/reddit/test_modmail.py +++ b/tests/integration/models/reddit/test_modmail.py @@ -62,6 +62,13 @@ async def test_reply(self, reddit): reply = await conversation.reply(body="A message") assert isinstance(reply, ModmailMessage) + async def test_reply__internal(self, reddit): + reddit.read_only = False + subreddit = Subreddit(reddit, "all") + conversation = await subreddit.modmail("1mahha") + reply = await conversation.reply(internal=True, body="A message") + assert isinstance(reply, ModmailMessage) + async def test_unarchive(self, reddit): reddit.read_only = False subreddit = Subreddit(reddit, "all")