From e4f1211d882c4c3747170627014c2c8af5a5d430 Mon Sep 17 00:00:00 2001 From: LilSpazJoekp <15524072+LilSpazJoekp@users.noreply.github.com> Date: Sat, 25 Nov 2023 17:37:05 -0600 Subject: [PATCH 1/2] Fix typing mistake and move change log entries --- CHANGES.rst | 15 ++++++--------- asyncpraw/models/reddit/redditor.py | 2 +- asyncpraw/objector.py | 2 +- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index c7fedda0..020e46dc 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -33,14 +33,14 @@ Unreleased - :func:`.stream_generator` now accepts the ``continue_after_id`` parameter, which starts the stream after a given item ID. -**Fixed** - -- XML parsing error when media uploads fail. - **Changed** - Drop support for Python 3.7, which is end-of-life on 2023-06-27. +**Fixed** + +- XML parsing error when media uploads fail. + 7.7.1 (2023/07/11) ------------------ @@ -149,6 +149,8 @@ Unreleased - Ability to use :class:`.CommentForest` as an asynchronous iterator. - :meth:`.CommentForest.list` no longer needs to be awaited. - :attr:`.Submission.comments` no longer needs to be awaited and is now a property. +- The keyword argument ``lazy`` has been replace by ``fetch`` to consolidate the keyword + argument used to explicitly perform a fetch when initializing an object. **Fixed** @@ -157,11 +159,6 @@ Unreleased - An import error when using Async PRAW in environments where ``libsqlite3-dev`` is needed to utilize ``aiosqlite`` package which depends on the ``sqlite3`` builtin. -**Deprecated** - -- The keyword argument ``lazy`` has been replace by ``fetch`` to consolidate the keyword - argument used to explicitly perform a fetch when initializing an object. - 7.4.0 (2021/07/30) ------------------ diff --git a/asyncpraw/models/reddit/redditor.py b/asyncpraw/models/reddit/redditor.py index 1dfb3f55..8b4332da 100644 --- a/asyncpraw/models/reddit/redditor.py +++ b/asyncpraw/models/reddit/redditor.py @@ -198,7 +198,7 @@ async def _fetch_username(self, fullname: str): ) return response[fullname]["name"] - async def _friend(self, *, data: dict[str:Any], method: str): + async def _friend(self, *, data: dict[str, Any], method: str): url = API_PATH["friend_v1"].format(user=self) await self._reddit.request(data=dumps(data), method=method, path=url) diff --git a/asyncpraw/objector.py b/asyncpraw/objector.py index acc94b74..9eafeb62 100644 --- a/asyncpraw/objector.py +++ b/asyncpraw/objector.py @@ -61,7 +61,7 @@ def __init__(self, reddit: asyncpraw.Reddit, parsers: dict[str, Any] | None = No self._reddit = reddit def _objectify_dict( # noqa: PLR0912,PLR0915 - self, data: dict[str:Any] + self, data: dict[str, Any] ) -> RedditBase: """Create :class:`.RedditBase` objects from dicts. From 72c309e774079c2aaa0e33df430bb226210ebb50 Mon Sep 17 00:00:00 2001 From: LilSpazJoekp <15524072+LilSpazJoekp@users.noreply.github.com> Date: Fri, 10 Nov 2023 14:33:43 -0600 Subject: [PATCH 2/2] Add support for new share URL format created from Reddit's mobile apps. (cherry picked from commit praw-dev/praw@61dfa9fb47f61ccef124e1773a9f7d43742053da) --- CHANGES.rst | 1 + asyncpraw/reddit.py | 15 + ...stComment.test_resolve_from_share_url.json | 279 ++++++++++++++++++ ...t_resolve_from_share_url__invalid_url.json | 179 +++++++++++ ...ubmission.test_resolve_from_share_url.json | 279 ++++++++++++++++++ ...t_resolve_from_share_url__invalid_url.json | 173 +++++++++++ .../integration/models/reddit/test_comment.py | 9 + .../models/reddit/test_submission.py | 11 +- 8 files changed, 945 insertions(+), 1 deletion(-) create mode 100644 tests/integration/cassettes/TestComment.test_resolve_from_share_url.json create mode 100644 tests/integration/cassettes/TestComment.test_resolve_from_share_url__invalid_url.json create mode 100644 tests/integration/cassettes/TestSubmission.test_resolve_from_share_url.json create mode 100644 tests/integration/cassettes/TestSubmission.test_resolve_from_share_url__invalid_url.json diff --git a/CHANGES.rst b/CHANGES.rst index 020e46dc..86ce2208 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -32,6 +32,7 @@ Unreleased - :func:`.stream_generator` now accepts the ``continue_after_id`` parameter, which starts the stream after a given item ID. +- Support for new share URL format created from Reddit's mobile apps. **Changed** diff --git a/asyncpraw/reddit.py b/asyncpraw/reddit.py index 2a60fba3..b91df0db 100644 --- a/asyncpraw/reddit.py +++ b/asyncpraw/reddit.py @@ -15,6 +15,7 @@ AsyncGenerator, Iterable, ) +from urllib.parse import urlparse from warnings import warn from asyncprawcore import ( @@ -706,6 +707,16 @@ async def close(self): """Close the requestor.""" await self.requestor.close() + async def _resolve_share_url(self, url: str) -> str: + """Return the canonical URL for a given share URL.""" + parts = urlparse(url).path.rstrip("/").split("/") + if "s" in parts: # handling new share urls from mobile apps + try: + await self.get(url) + except Redirect as e: + return e.response.headers.get("location") + return url + @_deprecate_args("id", "url", "fetch") @deprecate_lazy async def comment( @@ -738,6 +749,8 @@ async def comment( :meth:`~.Comment.refresh` on the returned :class:`.Comment`. """ + if url: + url = await self._resolve_share_url(url) comment = models.Comment(self, id=id, url=url) if fetch: await comment._fetch() @@ -1093,6 +1106,8 @@ async def submission( await submission.mod.remove() """ + if url: + url = await self._resolve_share_url(url) submission = models.Submission(self, id=id, url=url) if fetch: await submission._fetch() diff --git a/tests/integration/cassettes/TestComment.test_resolve_from_share_url.json b/tests/integration/cassettes/TestComment.test_resolve_from_share_url.json new file mode 100644 index 00000000..8a976c12 --- /dev/null +++ b/tests/integration/cassettes/TestComment.test_resolve_from_share_url.json @@ -0,0 +1,279 @@ +{ + "interactions": [ + { + "request": { + "body": [ + [ + "grant_type", + "client_credentials" + ] + ], + "headers": { + "AUTHORIZATION": [ + "Basic " + ], + "Accept-Encoding": [ + "identity" + ], + "Connection": [ + "close" + ], + "User-Agent": [ + " Async PRAW/7.7.2.dev0 asyncprawcore/2.3.1.dev0" + ] + }, + "method": "POST", + "uri": "https://www.reddit.com/api/v1/access_token" + }, + "response": { + "body": { + "string": "{\"access_token\": \"\", \"token_type\": \"bearer\", \"expires_in\": 86400, \"scope\": \"*\"}" + }, + "headers": { + "Accept-Ranges": [ + "bytes" + ], + "Cache-Control": [ + "private, max-age=3600" + ], + "Connection": [ + "close" + ], + "Content-Length": [ + "812" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Date": [ + "Sun, 26 Nov 2023 00:05:41 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=Prgl0bnMjJaCRFfLX9; Domain=reddit.com; Max-Age=63071999; Path=/; secure" + ], + "Strict-Transport-Security": [ + "max-age=31536000; includeSubdomains" + ], + "Vary": [ + "accept-encoding, Accept-Encoding" + ], + "Via": [ + "1.1 varnish" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "X-XSS-Protection": [ + "1; mode=block" + ], + "x-reddit-loid": [ + "000000000onw8qeka2.2.1700957141374.Z0FBQUFBQmxZb3ZWWE00aUR4YW1udDBBMjRCZENrU0gyV1B2LUQwN093N2NGNWs4ZTZPUW91OWRqYmw0ejB3cGh4bHk4WWlRRTBnQzdBX2lFeGtIdWRMVkpOaG43eHh3dEVTSklsN0lKcGVvc2dSYWV1Y0lRVS02MlIzODNucVZXNTI5LWp4eXQxaHk" + ] + }, + "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=Prgl0bnMjJaCRFfLX9" + ], + "User-Agent": [ + " Async PRAW/7.7.2.dev0 asyncprawcore/2.3.1.dev0" + ] + }, + "method": "GET", + "uri": "https://www.reddit.com/r/redditdev/s/nGnQE1QkLC?raw_json=1" + }, + "response": { + "body": { + "string": "Moved Permanently.\n\n" + }, + "headers": { + "Accept-Ranges": [ + "bytes" + ], + "Cache-Control": [ + "private, max-age=3600" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "275" + ], + "Content-Type": [ + "text/html; charset=utf-8" + ], + "Date": [ + "Sun, 26 Nov 2023 00:05:41 GMT" + ], + "Location": [ + "https://www.reddit.com/r/redditdev/comments/2gmzqe/praw_https_enabled_praw_testing_needed/cklhv0f/?context=3&share_id=vi8DOF9B0U5cJSzhFjDE9&utm_content=1&utm_medium=ios_app&utm_name=ioscss&utm_source=share&utm_term=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": [ + "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" + ] + }, + "status": { + "code": 301, + "message": "Moved Permanently" + }, + "url": "https://www.reddit.com/r/redditdev/s/nGnQE1QkLC?raw_json=1" + } + }, + { + "request": { + "body": null, + "headers": { + "Accept-Encoding": [ + "identity" + ], + "Authorization": [ + "bearer " + ], + "Cookie": [ + "csv=2; edgebucket=Prgl0bnMjJaCRFfLX9" + ], + "User-Agent": [ + " Async PRAW/7.7.2.dev0 asyncprawcore/2.3.1.dev0" + ] + }, + "method": "GET", + "uri": "https://oauth.reddit.com/api/info/?id=t1_cklhv0f&raw_json=1" + }, + "response": { + "body": { + "string": "{\"kind\": \"Listing\", \"data\": {\"after\": null, \"dist\": 1, \"modhash\": \"\", \"geo_filter\": \"\", \"children\": [{\"kind\": \"t1\", \"data\": {\"subreddit_id\": \"t5_2qizd\", \"approved_at_utc\": null, \"author_is_blocked\": false, \"comment_type\": null, \"edited\": false, \"mod_reason_by\": null, \"banned_by\": null, \"ups\": 1, \"num_reports\": null, \"author_flair_type\": \"text\", \"total_awards_received\": 0, \"subreddit\": \"redditdev\", \"author_flair_template_id\": null, \"likes\": null, \"replies\": \"\", \"user_reports\": [], \"saved\": false, \"id\": \"cklhv0f\", \"banned_at_utc\": null, \"mod_reason_title\": null, \"gilded\": 0, \"archived\": false, \"collapsed_reason_code\": null, \"no_follow\": true, \"author\": \"bboe\", \"can_mod_post\": false, \"send_replies\": true, \"parent_id\": \"t1_cklfmye\", \"score\": 1, \"author_fullname\": \"t2_3pz6e\", \"report_reasons\": null, \"removal_reason\": null, \"approved_by\": null, \"all_awardings\": [], \"body\": \"Yes it does. That fix is also in the master branch, we just haven't made a release for it (and we probably won't until 3.0).\", \"awarders\": [], \"top_awarded_type\": null, \"downs\": 0, \"author_flair_css_class\": \"\", \"author_patreon_flair\": false, \"collapsed\": false, \"author_flair_richtext\": [], \"is_submitter\": true, \"body_html\": \"\\u003Cdiv class=\\\"md\\\"\\u003E\\u003Cp\\u003EYes it does. That fix is also in the master branch, we just haven\\u0026#39;t made a release for it (and we probably won\\u0026#39;t until 3.0).\\u003C/p\\u003E\\n\\u003C/div\\u003E\", \"gildings\": {}, \"collapsed_reason\": null, \"associated_award\": null, \"stickied\": false, \"author_premium\": false, \"can_gild\": false, \"link_id\": \"t3_2gmzqe\", \"unrepliable_reason\": null, \"author_flair_text_color\": \"dark\", \"score_hidden\": false, \"permalink\": \"/r/redditdev/comments/2gmzqe/praw_https_enabled_praw_testing_needed/cklhv0f/\", \"subreddit_type\": \"public\", \"locked\": false, \"name\": \"t1_cklhv0f\", \"created\": 1411010034.0, \"author_flair_text\": \"PRAW Author\", \"treatment_tags\": [], \"created_utc\": 1411010034.0, \"subreddit_name_prefixed\": \"r/redditdev\", \"controversiality\": 0, \"author_flair_background_color\": \"\", \"collapsed_because_crowd_control\": null, \"mod_reports\": [], \"mod_note\": null, \"distinguished\": null}}], \"before\": null}}" + }, + "headers": { + "Accept-Ranges": [ + "bytes" + ], + "Access-Control-Allow-Origin": [ + "*" + ], + "Access-Control-Expose-Headers": [ + "X-Moose" + ], + "Cache-Control": [ + "private, max-age=3600" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "2161" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Date": [ + "Sun, 26 Nov 2023 00:05:42 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": [ + "loid=000000000onw8qeka2.2.1700957141374.Z0FBQUFBQmxZb3ZWX1ZPVUdsMFFvZFFKUjN5UmZxRXpaOHBwQ1NxRW1VQjdPREZNRnllT3N3LWZlYjVic0dEejlyNVBzMEVZaGliS1Z3cUV2UVQzeTRpS21ucGhIVHZheUxfa2EwMlJCSXRHUURoMWRsVWxGd3k0cEVLX01ob3FMUE1LejFYa3VuVjg; Domain=reddit.com; Max-Age=63071999; Path=/; expires=Tue, 25-Nov-2025 00:05:41 GMT; secure; SameSite=None; Secure", + "session_tracker=kfcarcqnhfihaqkjlk.0.1700957141953.Z0FBQUFBQmxZb3ZWUHg4Q21CbWdXcVRkdGtNc0FJaVcwamtPaUZQQzE0cVpSSlg3Nkl0ZHhvYjgwT3otb2E2U1VrUno4S3NwdFd4NDc3aFNycGM4bkh5LVU2WF85ZENRMWM2Zi1DZmFFZmp1dEJSMnFKeFhUemJneTFKazcwQjFFUm1EekU3S0JUNGw; Domain=reddit.com; Max-Age=7199; Path=/; expires=Sun, 26-Nov-2023 02:05:41 GMT; secure; SameSite=None; Secure" + ], + "Strict-Transport-Security": [ + "max-age=31536000; includeSubdomains" + ], + "Vary": [ + "accept-encoding, Accept-Encoding" + ], + "Via": [ + "1.1 varnish" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "X-XSS-Protection": [ + "1; mode=block" + ], + "x-ratelimit-remaining": [ + "599.0" + ], + "x-ratelimit-reset": [ + "259" + ], + "x-ratelimit-used": [ + "1" + ], + "x-ua-compatible": [ + "IE=edge" + ] + }, + "status": { + "code": 200, + "message": "OK" + }, + "url": "https://oauth.reddit.com/api/info/?id=t1_cklhv0f&raw_json=1" + } + } + ], + "recorded_at": "2023-11-26T00:05:41", + "version": 1 +} diff --git a/tests/integration/cassettes/TestComment.test_resolve_from_share_url__invalid_url.json b/tests/integration/cassettes/TestComment.test_resolve_from_share_url__invalid_url.json new file mode 100644 index 00000000..54ac0eb6 --- /dev/null +++ b/tests/integration/cassettes/TestComment.test_resolve_from_share_url__invalid_url.json @@ -0,0 +1,179 @@ +{ + "interactions": [ + { + "request": { + "body": [ + [ + "grant_type", + "client_credentials" + ] + ], + "headers": { + "AUTHORIZATION": [ + "Basic " + ], + "Accept-Encoding": [ + "identity" + ], + "Connection": [ + "close" + ], + "User-Agent": [ + " Async PRAW/7.7.2.dev0 asyncprawcore/2.3.1.dev0" + ] + }, + "method": "POST", + "uri": "https://www.reddit.com/api/v1/access_token" + }, + "response": { + "body": { + "string": "{\"access_token\": \"\", \"token_type\": \"bearer\", \"expires_in\": 86400, \"scope\": \"*\"}" + }, + "headers": { + "Accept-Ranges": [ + "bytes" + ], + "Cache-Control": [ + "private, max-age=3600" + ], + "Connection": [ + "close" + ], + "Content-Length": [ + "812" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Date": [ + "Sun, 26 Nov 2023 00:05:44 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=wiBMs8FRQgjC0C8KDG; Domain=reddit.com; Max-Age=63071999; Path=/; secure" + ], + "Strict-Transport-Security": [ + "max-age=31536000; includeSubdomains" + ], + "Vary": [ + "accept-encoding, Accept-Encoding" + ], + "Via": [ + "1.1 varnish" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "X-XSS-Protection": [ + "1; mode=block" + ], + "x-reddit-loid": [ + "000000000onw8rl8b1.2.1700957144671.Z0FBQUFBQmxZb3ZZQVkxSzFPVDJGc1Y5WEFuZ2RWLXVlOWxOd0xUUVRtMFlUTDR0MFlEOUtTMDE5aHF3OTZQbk1MenZhNHdRQWQ0MTFlZ0FETm5meTByVkJ5WlZiUHhpeFN2VktQOUxtdkVCWktOQUFWWm53U05WTDc3YmxIM0RzUkVaV3NVOVpDeDQ" + ] + }, + "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=wiBMs8FRQgjC0C8KDG" + ], + "User-Agent": [ + " Async PRAW/7.7.2.dev0 asyncprawcore/2.3.1.dev0" + ] + }, + "method": "GET", + "uri": "https://www.reddit.com/r/redditdev/s/WNauetbiNG?raw_json=1" + }, + "response": { + "body": { + "string": "Moved Permanently.\n\n" + }, + "headers": { + "Accept-Ranges": [ + "bytes" + ], + "Cache-Control": [ + "private, max-age=3600" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "253" + ], + "Content-Type": [ + "text/html; charset=utf-8" + ], + "Date": [ + "Sun, 26 Nov 2023 00:05:45 GMT" + ], + "Location": [ + "https://www.reddit.com/r/redditdev/comments/2gmzqe/praw_https_enabled_praw_testing_needed/?share_id=oqqXWtvgcCuonkcpck8yD&utm_content=1&utm_medium=ios_app&utm_name=ioscss&utm_source=share&utm_term=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": [ + "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" + ] + }, + "status": { + "code": 301, + "message": "Moved Permanently" + }, + "url": "https://www.reddit.com/r/redditdev/s/WNauetbiNG?raw_json=1" + } + } + ], + "recorded_at": "2023-11-26T00:05:44", + "version": 1 +} diff --git a/tests/integration/cassettes/TestSubmission.test_resolve_from_share_url.json b/tests/integration/cassettes/TestSubmission.test_resolve_from_share_url.json new file mode 100644 index 00000000..2909b062 --- /dev/null +++ b/tests/integration/cassettes/TestSubmission.test_resolve_from_share_url.json @@ -0,0 +1,279 @@ +{ + "interactions": [ + { + "request": { + "body": [ + [ + "grant_type", + "client_credentials" + ] + ], + "headers": { + "AUTHORIZATION": [ + "Basic " + ], + "Accept-Encoding": [ + "identity" + ], + "Connection": [ + "close" + ], + "User-Agent": [ + " Async PRAW/7.7.2.dev0 asyncprawcore/2.3.1.dev0" + ] + }, + "method": "POST", + "uri": "https://www.reddit.com/api/v1/access_token" + }, + "response": { + "body": { + "string": "{\"access_token\": \"\", \"token_type\": \"bearer\", \"expires_in\": 86400, \"scope\": \"*\"}" + }, + "headers": { + "Accept-Ranges": [ + "bytes" + ], + "Cache-Control": [ + "private, max-age=3600" + ], + "Connection": [ + "close" + ], + "Content-Length": [ + "812" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Date": [ + "Sun, 26 Nov 2023 00:06:01 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=dDLVAIQqnsj9cvevwl; Domain=reddit.com; Max-Age=63071999; Path=/; secure" + ], + "Strict-Transport-Security": [ + "max-age=31536000; includeSubdomains" + ], + "Vary": [ + "accept-encoding, Accept-Encoding" + ], + "Via": [ + "1.1 varnish" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "X-XSS-Protection": [ + "1; mode=block" + ], + "x-reddit-loid": [ + "000000000onwa1agpt.2.1700957161439.Z0FBQUFBQmxZb3Zwd3BjWXVPa00zWUJ1MDcyNHA0S3UzcFA3bkxsMTVNSDc5NWc0NHlnRGFJSmloZ0FpQi1YQUtDdjVGUFFaeWxvSHdfLWVEX05vaXlNRXRmOXV3VUhHQkFXMEhrQXFoYnk2N25sQUtwU1A3VndkVGZqNnhRVG1HRElreFdQYW8yd08" + ] + }, + "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=dDLVAIQqnsj9cvevwl" + ], + "User-Agent": [ + " Async PRAW/7.7.2.dev0 asyncprawcore/2.3.1.dev0" + ] + }, + "method": "GET", + "uri": "https://www.reddit.com/r/redditdev/s/WNauetbiNG?raw_json=1" + }, + "response": { + "body": { + "string": "Moved Permanently.\n\n" + }, + "headers": { + "Accept-Ranges": [ + "bytes" + ], + "Cache-Control": [ + "private, max-age=3600" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "253" + ], + "Content-Type": [ + "text/html; charset=utf-8" + ], + "Date": [ + "Sun, 26 Nov 2023 00:06:01 GMT" + ], + "Location": [ + "https://www.reddit.com/r/redditdev/comments/2gmzqe/praw_https_enabled_praw_testing_needed/?share_id=oqqXWtvgcCuonkcpck8yD&utm_content=1&utm_medium=ios_app&utm_name=ioscss&utm_source=share&utm_term=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": [ + "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" + ] + }, + "status": { + "code": 301, + "message": "Moved Permanently" + }, + "url": "https://www.reddit.com/r/redditdev/s/WNauetbiNG?raw_json=1" + } + }, + { + "request": { + "body": null, + "headers": { + "Accept-Encoding": [ + "identity" + ], + "Authorization": [ + "bearer " + ], + "Cookie": [ + "csv=2; edgebucket=dDLVAIQqnsj9cvevwl" + ], + "User-Agent": [ + " Async PRAW/7.7.2.dev0 asyncprawcore/2.3.1.dev0" + ] + }, + "method": "GET", + "uri": "https://oauth.reddit.com/comments/2gmzqe/?limit=2048&sort=confidence&raw_json=1" + }, + "response": { + "body": { + "string": "[{\"kind\": \"Listing\", \"data\": {\"after\": null, \"dist\": 1, \"modhash\": \"\", \"geo_filter\": \"\", \"children\": [{\"kind\": \"t3\", \"data\": {\"approved_at_utc\": null, \"subreddit\": \"redditdev\", \"selftext\": \"PRAW client developers,\\n\\nI have made a PRAW branch to test using only HTTPS over the API. This change requires some testers to see if there any issues that did not come up from our set of unit tests. This is the first of a few improvements that will (hopefully soon) be released with PRAW version 3. If you want to start using HTTPS exclusively through PRAW please update via the following:\\n\\n pip install git+git://github.com/praw-dev/praw.git@praw3\\n\\nIf you experience any issues feel free to report them here, however filing a bug on github (https://github.com/praw-dev/praw/issues) would be ideal. Thanks!\", \"user_reports\": [], \"saved\": false, \"mod_reason_title\": null, \"gilded\": 1, \"clicked\": false, \"title\": \"[PRAW] HTTPS enabled PRAW testing needed\", \"link_flair_richtext\": [], \"subreddit_name_prefixed\": \"r/redditdev\", \"hidden\": false, \"pwls\": 6, \"link_flair_css_class\": null, \"downs\": 0, \"thumbnail_height\": null, \"top_awarded_type\": null, \"parent_whitelist_status\": \"all_ads\", \"hide_score\": false, \"name\": \"t3_2gmzqe\", \"quarantine\": false, \"link_flair_text_color\": null, \"upvote_ratio\": 0.94, \"author_flair_background_color\": \"\", \"subreddit_type\": \"public\", \"ups\": 13, \"total_awards_received\": 0, \"media_embed\": {}, \"thumbnail_width\": null, \"author_flair_template_id\": null, \"is_original_content\": false, \"author_fullname\": \"t2_3pz6e\", \"secure_media\": null, \"is_reddit_media_domain\": false, \"is_meta\": false, \"category\": null, \"secure_media_embed\": {}, \"link_flair_text\": \"PRAW\", \"can_mod_post\": false, \"score\": 13, \"approved_by\": null, \"is_created_from_ads_ui\": false, \"author_premium\": false, \"thumbnail\": \"self\", \"edited\": false, \"author_flair_css_class\": \"\", \"author_flair_richtext\": [], \"gildings\": {}, \"content_categories\": null, \"is_self\": true, \"mod_note\": null, \"created\": 1410935671.0, \"link_flair_type\": \"text\", \"wls\": 6, \"removed_by_category\": null, \"banned_by\": null, \"author_flair_type\": \"text\", \"domain\": \"self.redditdev\", \"allow_live_comments\": false, \"selftext_html\": \"\\u003C!-- SC_OFF --\\u003E\\u003Cdiv class=\\\"md\\\"\\u003E\\u003Cp\\u003EPRAW client developers,\\u003C/p\\u003E\\n\\n\\u003Cp\\u003EI have made a PRAW branch to test using only HTTPS over the API. This change requires some testers to see if there any issues that did not come up from our set of unit tests. This is the first of a few improvements that will (hopefully soon) be released with PRAW version 3. If you want to start using HTTPS exclusively through PRAW please update via the following:\\u003C/p\\u003E\\n\\n\\u003Cpre\\u003E\\u003Ccode\\u003Epip install git+git://github.com/praw-dev/praw.git@praw3\\n\\u003C/code\\u003E\\u003C/pre\\u003E\\n\\n\\u003Cp\\u003EIf you experience any issues feel free to report them here, however filing a bug on github (\\u003Ca href=\\\"https://github.com/praw-dev/praw/issues\\\"\\u003Ehttps://github.com/praw-dev/praw/issues\\u003C/a\\u003E) would be ideal. Thanks!\\u003C/p\\u003E\\n\\u003C/div\\u003E\\u003C!-- SC_ON --\\u003E\", \"likes\": null, \"suggested_sort\": null, \"banned_at_utc\": null, \"view_count\": null, \"archived\": false, \"no_follow\": false, \"is_crosspostable\": false, \"pinned\": false, \"over_18\": false, \"all_awardings\": [], \"awarders\": [], \"media_only\": false, \"can_gild\": false, \"spoiler\": false, \"locked\": false, \"author_flair_text\": \"PRAW Author\", \"treatment_tags\": [], \"visited\": false, \"removed_by\": null, \"num_reports\": null, \"distinguished\": null, \"subreddit_id\": \"t5_2qizd\", \"author_is_blocked\": false, \"mod_reason_by\": null, \"removal_reason\": null, \"link_flair_background_color\": null, \"id\": \"2gmzqe\", \"is_robot_indexable\": true, \"num_duplicates\": 0, \"report_reasons\": null, \"author\": \"bboe\", \"discussion_type\": null, \"num_comments\": 2, \"send_replies\": true, \"media\": null, \"contest_mode\": false, \"author_patreon_flair\": false, \"author_flair_text_color\": \"dark\", \"permalink\": \"/r/redditdev/comments/2gmzqe/praw_https_enabled_praw_testing_needed/\", \"whitelist_status\": \"all_ads\", \"stickied\": false, \"url\": \"https://www.reddit.com/r/redditdev/comments/2gmzqe/praw_https_enabled_praw_testing_needed/\", \"subreddit_subscribers\": 73993, \"created_utc\": 1410935671.0, \"num_crossposts\": 0, \"mod_reports\": [], \"is_video\": false}}], \"before\": null}}, {\"kind\": \"Listing\", \"data\": {\"after\": null, \"dist\": null, \"modhash\": \"\", \"geo_filter\": \"\", \"children\": [{\"kind\": \"t1\", \"data\": {\"subreddit_id\": \"t5_2qizd\", \"approved_at_utc\": null, \"author_is_blocked\": false, \"comment_type\": null, \"awarders\": [], \"mod_reason_by\": null, \"banned_by\": null, \"author_flair_type\": \"text\", \"total_awards_received\": 0, \"subreddit\": \"redditdev\", \"author_flair_template_id\": null, \"likes\": null, \"replies\": {\"kind\": \"Listing\", \"data\": {\"after\": null, \"dist\": null, \"modhash\": \"\", \"geo_filter\": \"\", \"children\": [{\"kind\": \"t1\", \"data\": {\"subreddit_id\": \"t5_2qizd\", \"approved_at_utc\": null, \"author_is_blocked\": false, \"comment_type\": null, \"awarders\": [], \"mod_reason_by\": null, \"banned_by\": null, \"author_flair_type\": \"text\", \"total_awards_received\": 0, \"subreddit\": \"redditdev\", \"author_flair_template_id\": null, \"likes\": null, \"replies\": \"\", \"user_reports\": [], \"saved\": false, \"id\": \"cklhv0f\", \"banned_at_utc\": null, \"mod_reason_title\": null, \"gilded\": 0, \"archived\": false, \"collapsed_reason_code\": null, \"no_follow\": true, \"author\": \"bboe\", \"can_mod_post\": false, \"created_utc\": 1411010034.0, \"send_replies\": true, \"parent_id\": \"t1_cklfmye\", \"score\": 1, \"author_fullname\": \"t2_3pz6e\", \"removal_reason\": null, \"approved_by\": null, \"mod_note\": null, \"all_awardings\": [], \"body\": \"Yes it does. That fix is also in the master branch, we just haven't made a release for it (and we probably won't until 3.0).\", \"edited\": false, \"top_awarded_type\": null, \"author_flair_css_class\": \"\", \"name\": \"t1_cklhv0f\", \"is_submitter\": true, \"downs\": 0, \"author_flair_richtext\": [], \"author_patreon_flair\": false, \"body_html\": \"\\u003Cdiv class=\\\"md\\\"\\u003E\\u003Cp\\u003EYes it does. That fix is also in the master branch, we just haven\\u0026#39;t made a release for it (and we probably won\\u0026#39;t until 3.0).\\u003C/p\\u003E\\n\\u003C/div\\u003E\", \"gildings\": {}, \"collapsed_reason\": null, \"distinguished\": null, \"associated_award\": null, \"stickied\": false, \"author_premium\": false, \"can_gild\": false, \"link_id\": \"t3_2gmzqe\", \"unrepliable_reason\": null, \"author_flair_text_color\": \"dark\", \"score_hidden\": false, \"permalink\": \"/r/redditdev/comments/2gmzqe/praw_https_enabled_praw_testing_needed/cklhv0f/\", \"subreddit_type\": \"public\", \"locked\": false, \"report_reasons\": null, \"created\": 1411010034.0, \"author_flair_text\": \"PRAW Author\", \"treatment_tags\": [], \"collapsed\": false, \"subreddit_name_prefixed\": \"r/redditdev\", \"controversiality\": 0, \"depth\": 1, \"author_flair_background_color\": \"\", \"collapsed_because_crowd_control\": null, \"mod_reports\": [], \"num_reports\": null, \"ups\": 1}}], \"before\": null}}, \"user_reports\": [], \"saved\": false, \"id\": \"cklfmye\", \"banned_at_utc\": null, \"mod_reason_title\": null, \"gilded\": 0, \"archived\": false, \"collapsed_reason_code\": null, \"no_follow\": true, \"author\": \"paneer_burrito\", \"can_mod_post\": false, \"created_utc\": 1411005112.0, \"send_replies\": true, \"parent_id\": \"t3_2gmzqe\", \"score\": 1, \"author_fullname\": \"t2_gy2i1\", \"approved_by\": null, \"mod_note\": null, \"all_awardings\": [], \"collapsed\": false, \"body\": \"Quick question: I remember reading about an issue where the proxy settings for https requests were not getting picked up from the environment variables. Does this branch have that fix? Thanks\", \"edited\": false, \"top_awarded_type\": null, \"author_flair_css_class\": null, \"name\": \"t1_cklfmye\", \"is_submitter\": false, \"downs\": 0, \"author_flair_richtext\": [], \"author_patreon_flair\": false, \"body_html\": \"\\u003Cdiv class=\\\"md\\\"\\u003E\\u003Cp\\u003EQuick question: I remember reading about an issue where the proxy settings for https requests were not getting picked up from the environment variables. Does this branch have that fix? Thanks\\u003C/p\\u003E\\n\\u003C/div\\u003E\", \"removal_reason\": null, \"collapsed_reason\": null, \"distinguished\": null, \"associated_award\": null, \"stickied\": false, \"author_premium\": false, \"can_gild\": false, \"gildings\": {}, \"unrepliable_reason\": null, \"author_flair_text_color\": null, \"score_hidden\": false, \"permalink\": \"/r/redditdev/comments/2gmzqe/praw_https_enabled_praw_testing_needed/cklfmye/\", \"subreddit_type\": \"public\", \"locked\": false, \"report_reasons\": null, \"created\": 1411005112.0, \"author_flair_text\": null, \"treatment_tags\": [], \"link_id\": \"t3_2gmzqe\", \"subreddit_name_prefixed\": \"r/redditdev\", \"controversiality\": 0, \"depth\": 0, \"author_flair_background_color\": null, \"collapsed_because_crowd_control\": null, \"mod_reports\": [], \"num_reports\": null, \"ups\": 1}}], \"before\": null}}]" + }, + "headers": { + "Accept-Ranges": [ + "bytes" + ], + "Access-Control-Allow-Origin": [ + "*" + ], + "Access-Control-Expose-Headers": [ + "X-Moose" + ], + "Cache-Control": [ + "private, max-age=3600" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "8825" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Date": [ + "Sun, 26 Nov 2023 00:06:01 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": [ + "loid=000000000onwa1agpt.2.1700957161439.Z0FBQUFBQmxZb3ZwaVBXZm1zUjhEdFlRc2U0Zlh0TC1IRGY0eGV4MzFxeTZCWFZrTnV6QVdzbk1OMU9aeUNkTk1yXzFkV3hFZUZEWGNpbjVRZEozV24yblIyU2lVamRNZGp5bmFMajBnVi1ERkptN3NxcjZyOUdRcUJUOFlpMTVMZGVob2dweXRXaU8; Domain=reddit.com; Max-Age=63071999; Path=/; expires=Tue, 25-Nov-2025 00:06:01 GMT; secure; SameSite=None; Secure", + "session_tracker=brcordoreofcdkmbij.0.1700957161847.Z0FBQUFBQmxZb3ZwZDE1Z2RSTDZCeEM1enNqR2xjUFk3NEg3VnlzZk5WdWlua1N2ejZfaGw0M0diLUE1bkxpVGo2RXU1ZlNjMlNrSldyQjIzTkdqc1BteVNSWFVPNXQxR01mVTVDMDR6dGUwSXVycnhnZHQtbllEOWV4ajhOS1BTaTFhV3JYNUlpSVc; Domain=reddit.com; Max-Age=7199; Path=/; expires=Sun, 26-Nov-2023 02:06:01 GMT; secure; SameSite=None; Secure" + ], + "Strict-Transport-Security": [ + "max-age=31536000; includeSubdomains" + ], + "Vary": [ + "accept-encoding, Accept-Encoding" + ], + "Via": [ + "1.1 varnish" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "X-XSS-Protection": [ + "1; mode=block" + ], + "x-ratelimit-remaining": [ + "598.0" + ], + "x-ratelimit-reset": [ + "239" + ], + "x-ratelimit-used": [ + "2" + ], + "x-ua-compatible": [ + "IE=edge" + ] + }, + "status": { + "code": 200, + "message": "OK" + }, + "url": "https://oauth.reddit.com/comments/2gmzqe/?limit=2048&sort=confidence&raw_json=1" + } + } + ], + "recorded_at": "2023-11-26T00:06:01", + "version": 1 +} diff --git a/tests/integration/cassettes/TestSubmission.test_resolve_from_share_url__invalid_url.json b/tests/integration/cassettes/TestSubmission.test_resolve_from_share_url__invalid_url.json new file mode 100644 index 00000000..ff0b74a2 --- /dev/null +++ b/tests/integration/cassettes/TestSubmission.test_resolve_from_share_url__invalid_url.json @@ -0,0 +1,173 @@ +{ + "interactions": [ + { + "request": { + "body": [ + [ + "grant_type", + "client_credentials" + ] + ], + "headers": { + "AUTHORIZATION": [ + "Basic " + ], + "Accept-Encoding": [ + "identity" + ], + "Connection": [ + "close" + ], + "User-Agent": [ + " Async PRAW/7.7.2.dev0 asyncprawcore/2.3.1.dev0" + ] + }, + "method": "POST", + "uri": "https://www.reddit.com/api/v1/access_token" + }, + "response": { + "body": { + "string": "{\"access_token\": \"\", \"token_type\": \"bearer\", \"expires_in\": 86400, \"scope\": \"*\"}" + }, + "headers": { + "Accept-Ranges": [ + "bytes" + ], + "Cache-Control": [ + "private, max-age=3600" + ], + "Connection": [ + "close" + ], + "Content-Length": [ + "812" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Date": [ + "Sun, 26 Nov 2023 00:06:02 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=CNYmtpNGV1920ysSwk; Domain=reddit.com; Max-Age=63071999; Path=/; secure" + ], + "Strict-Transport-Security": [ + "max-age=31536000; includeSubdomains" + ], + "Vary": [ + "accept-encoding, Accept-Encoding" + ], + "Via": [ + "1.1 varnish" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "X-XSS-Protection": [ + "1; mode=block" + ], + "x-reddit-loid": [ + "000000000onwa26jwg.2.1700957162500.Z0FBQUFBQmxZb3ZxOGhELTNkZEI4RGZKNUpZdUo5ZXdLeE1RbEJ0RUJHTHVJVV9qelF5bWFZZmNKbFB1RE42SFBCQzJrWnRpUW9uVTUtY1c3ekhSM0l5Y3NrT2tmbmp6Y01xRVh2dUJiQUtacTJROWJXZDRTRFZYcGozMVN6b0hrTjZ2cktWNnV4OU0" + ] + }, + "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=CNYmtpNGV1920ysSwk" + ], + "User-Agent": [ + " Async PRAW/7.7.2.dev0 asyncprawcore/2.3.1.dev0" + ] + }, + "method": "GET", + "uri": "https://reddit.com/r/space/s/?raw_json=1" + }, + "response": { + "body": { + "string": "" + }, + "headers": { + "Accept-Ranges": [ + "bytes" + ], + "Cache-Control": [ + "private, max-age=3600" + ], + "Connection": [ + "close" + ], + "Content-Length": [ + "0" + ], + "Date": [ + "Sun, 26 Nov 2023 00:06:02 GMT" + ], + "Location": [ + "https://www.reddit.com/r/space/s/?raw_json=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\" }]}" + ], + "Retry-After": [ + "0" + ], + "Server": [ + "snooserv" + ], + "Strict-Transport-Security": [ + "max-age=31536000; includeSubdomains; preload" + ], + "Via": [ + "1.1 varnish" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "X-XSS-Protection": [ + "1; mode=block" + ] + }, + "status": { + "code": 301, + "message": "Moved Permanently" + }, + "url": "https://reddit.com/r/space/s/?raw_json=1" + } + } + ], + "recorded_at": "2023-11-26T00:06:02", + "version": 1 +} diff --git a/tests/integration/models/reddit/test_comment.py b/tests/integration/models/reddit/test_comment.py index fcceb361..128ab032 100644 --- a/tests/integration/models/reddit/test_comment.py +++ b/tests/integration/models/reddit/test_comment.py @@ -218,6 +218,15 @@ async def test_report(self, reddit): reddit.read_only = False await Comment(reddit, "fx1it87").report("custom") + async def test_resolve_from_share_url(self, reddit): + url = "https://www.reddit.com/r/redditdev/s/nGnQE1QkLC" + assert await reddit.comment(url=url) == "cklhv0f", url + + async def test_resolve_from_share_url__invalid_url(self, reddit): + url = "https://www.reddit.com/r/redditdev/s/WNauetbiNG" + with pytest.raises(ClientException): + await reddit.comment(url=url) + async def test_save(self, reddit): reddit.read_only = False await Comment(reddit, "fx19hsi").save(category="foo") diff --git a/tests/integration/models/reddit/test_submission.py b/tests/integration/models/reddit/test_submission.py index a088c2ee..882ae662 100644 --- a/tests/integration/models/reddit/test_submission.py +++ b/tests/integration/models/reddit/test_submission.py @@ -1,6 +1,6 @@ import pytest -from asyncpraw.exceptions import RedditAPIException +from asyncpraw.exceptions import RedditAPIException, ClientException from asyncpraw.models import Comment, InlineGif, InlineImage, InlineVideo, Submission from ... import IntegrationTest @@ -306,6 +306,15 @@ async def test_report(self, reddit): reddit.read_only = False await Submission(reddit, "hmkbt8").report("praw") + async def test_resolve_from_share_url(self, reddit): + url = "https://www.reddit.com/r/redditdev/s/WNauetbiNG" + assert await reddit.submission(url=url) == "2gmzqe", url + + async def test_resolve_from_share_url__invalid_url(self, reddit): + url = "https://reddit.com/r/space/s/" + with pytest.raises(ClientException): + await reddit.submission(url=url) + async def test_save(self, reddit): reddit.read_only = False await Submission(reddit, "hmkbt8").save()