From 8a64689ac936d046ee4f03fa7a7641c6049abb53 Mon Sep 17 00:00:00 2001 From: nathan smith Date: Mon, 26 Jun 2023 09:56:39 -0500 Subject: [PATCH] Added support for reordering flairs through reddit.flair.reorder (cherry picked from commit praw-dev/praw@32eefbf6e2f25983a1c72f5d88d6d0def884e75a) --- CHANGES.rst | 7 + asyncpraw/endpoints.py | 1 + asyncpraw/models/reddit/subreddit.py | 44 ++ asyncpraw/reddit.py | 17 +- ...tSubredditFlairTemplates.test_reorder.json | 495 ++++++++++++++++++ ...redditLinkFlairTemplates.test_reorder.json | 486 +++++++++++++++++ .../models/reddit/test_subreddit.py | 20 + 7 files changed, 1063 insertions(+), 7 deletions(-) create mode 100644 tests/integration/cassettes/TestSubredditFlairTemplates.test_reorder.json create mode 100644 tests/integration/cassettes/TestSubredditLinkFlairTemplates.test_reorder.json diff --git a/CHANGES.rst b/CHANGES.rst index 40fd8fd6..88d82edb 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,6 +6,13 @@ Async PRAW follows `semantic versioning `_. Unreleased ---------- +**Added** + +- :meth:`~.SubredditLinkFlairTemplates.reorder` to reorder a subreddit's link flair + templates. +- :meth:`~.SubredditRedditorFlairTemplates.reorder` to reorder a subreddit's redditor + flair templates. + **Fixed** - XML parsing error when media uploads fail. diff --git a/asyncpraw/endpoints.py b/asyncpraw/endpoints.py index 104d2141..eaef33a6 100644 --- a/asyncpraw/endpoints.py +++ b/asyncpraw/endpoints.py @@ -63,6 +63,7 @@ "flairtemplate_v2": "r/{subreddit}/api/flairtemplate_v2", "flairtemplateclear": "r/{subreddit}/api/clearflairtemplates/", "flairtemplatedelete": "r/{subreddit}/api/deleteflairtemplate/", + "flairtemplatereorder": "r/{subreddit}/api/flair_template_order", "friend": "r/{subreddit}/api/friend/", "friend_v1": "api/v1/me/friends/{user}", "friends": "api/v1/me/friends/", diff --git a/asyncpraw/models/reddit/subreddit.py b/asyncpraw/models/reddit/subreddit.py index 66894911..4ab961d1 100644 --- a/asyncpraw/models/reddit/subreddit.py +++ b/asyncpraw/models/reddit/subreddit.py @@ -2371,6 +2371,17 @@ async def delete(self, template_id: str): url = API_PATH["flairtemplatedelete"].format(subreddit=self.subreddit) await self.subreddit._reddit.post(url, data={"flair_template_id": template_id}) + async def _reorder(self, flair_list: list, *, is_link: Optional[bool] = None): + url = API_PATH["flairtemplatereorder"].format(subreddit=self.subreddit) + await self.subreddit._reddit.patch( + url, + params={ + "flair_type": self.flair_type(is_link), + "subreddit": self.subreddit.display_name, + }, + json=flair_list, + ) + @_deprecate_args( "template_id", "text", @@ -4400,6 +4411,22 @@ async def clear(self): """ await self._clear(is_link=True) + async def reorder(self, flair_list: List[str]): + """Reorder a list of flairs. + + :param flair_list: A list of flair IDs. + + For example, to reverse the order of the link flair list try: + + .. code-block:: python + + subreddit = await reddit.subreddit("test") + flairs = [flair["id"] async for flair in subreddit.flair.link_templates] + await subreddit.flair.link_templates.reorder(list(reversed(flairs))) + + """ + await self._reorder(flair_list, is_link=True) + async def user_selectable( self, ) -> AsyncGenerator[Dict[str, Union[str, bool]], None]: @@ -4520,3 +4547,20 @@ async def clear(self): """ await self._clear(is_link=False) + + async def reorder(self, flair_list: List[str]): + """Reorder a list of flairs. + + :param flair_list: A list of flair IDs. + + For example, to reverse the order of the :class:`.Redditor` flair templates list + try: + + .. code-block:: python + + subreddit = reddit.subreddit("test") + flairs = [flair["id"] for flair in subreddit.flair.templates] + subreddit.flair.templates.reorder(list(reversed(flairs))) + + """ + await self._reorder(flair_list, is_link=False) diff --git a/asyncpraw/reddit.py b/asyncpraw/reddit.py index 9f4d77b3..51d70128 100644 --- a/asyncpraw/reddit.py +++ b/asyncpraw/reddit.py @@ -13,6 +13,7 @@ AsyncGenerator, Dict, Iterable, + List, Optional, Type, Union, @@ -543,7 +544,7 @@ async def _objectify_request( *, data: Optional[Union[Dict[str, Union[str, Any]], bytes, IO, str]] = None, files: Optional[Dict[str, IO]] = None, - json: Optional[Dict[Any, Any]] = None, + json: Optional[Union[Dict[Any, Any], List[Any]]] = None, method: str = "", params: Optional[Union[str, Dict[str, str]]] = None, path: str = "", @@ -743,7 +744,7 @@ async def delete( path: str, *, data: Optional[Union[Dict[str, Union[str, Any]], bytes, IO, str]] = None, - json: Optional[Dict[Any, Any]] = None, + json: Optional[Union[Dict[Any, Any], List[Any]]] = None, params: Optional[Union[str, Dict[str, str]]] = None, ) -> Any: """Return parsed objects returned from a DELETE request to ``path``. @@ -870,7 +871,8 @@ async def patch( path: str, *, data: Optional[Union[Dict[str, Union[str, Any]], bytes, IO, str]] = None, - json: Optional[Dict[Any, Any]] = None, + json: Optional[Union[Dict[Any, Any], List[Any]]] = None, + params: Optional[Union[str, Dict[str, str]]] = None, ) -> Any: """Return parsed objects returned from a PATCH request to ``path``. @@ -880,10 +882,11 @@ async def patch( :param json: JSON-serializable object to send in the body of the request with a Content-Type header of application/json (default: ``None``). If ``json`` is provided, ``data`` should not be. + :param params: The query parameters to add to the request (default: ``None``). """ return await self._objectify_request( - data=data, json=json, method="PATCH", path=path + data=data, json=json, method="PATCH", params=params, path=path ) @_deprecate_args("path", "data", "files", "params", "json") @@ -893,7 +896,7 @@ async def post( *, data: Optional[Union[Dict[str, Union[str, Any]], bytes, IO, str]] = None, files: Optional[Dict[str, IO]] = None, - json: Optional[Dict[Any, Any]] = None, + json: Optional[Union[Dict[Any, Any], List[Any]]] = None, params: Optional[Union[str, Dict[str, str]]] = None, ) -> Any: """Return parsed objects returned from a POST request to ``path``. @@ -941,7 +944,7 @@ async def put( path: str, *, data: Optional[Union[Dict[str, Union[str, Any]], bytes, IO, str]] = None, - json: Optional[Dict[Any, Any]] = None, + json: Optional[Union[Dict[Any, Any], List[Any]]] = None, ): """Return parsed objects returned from a PUT request to ``path``. @@ -1006,7 +1009,7 @@ async def request( *, data: Optional[Union[Dict[str, Union[str, Any]], bytes, IO, str]] = None, files: Optional[Dict[str, IO]] = None, - json: Optional[Dict[Any, Any]] = None, + json: Optional[Union[Dict[Any, Any], List[Any]]] = None, method: str, params: Optional[Union[str, Dict[str, Union[str, int]]]] = None, path: str, diff --git a/tests/integration/cassettes/TestSubredditFlairTemplates.test_reorder.json b/tests/integration/cassettes/TestSubredditFlairTemplates.test_reorder.json new file mode 100644 index 00000000..c851679c --- /dev/null +++ b/tests/integration/cassettes/TestSubredditFlairTemplates.test_reorder.json @@ -0,0 +1,495 @@ +{ + "interactions": [ + { + "request": { + "body": [ + [ + "grant_type", + "refresh_token" + ], + [ + "refresh_token", + "" + ] + ], + "headers": { + "AUTHORIZATION": [ + "Basic " + ], + "Accept-Encoding": [ + "identity" + ], + "Connection": [ + "close" + ], + "User-Agent": [ + " Async PRAW/7.7.2.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\": \"*\"}" + }, + "headers": { + "Accept-Ranges": [ + "bytes" + ], + "Cache-Control": [ + "private, max-age=3600" + ], + "Connection": [ + "close" + ], + "Content-Length": [ + "960" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Date": [ + "Fri, 13 Oct 2023 19:33:25 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=9orqOkKoXniBU86A6p; 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=9orqOkKoXniBU86A6p" + ], + "User-Agent": [ + " Async PRAW/7.7.2.dev0 asyncprawcore/2.3.0" + ] + }, + "method": "GET", + "uri": "https://oauth.reddit.com/r//api/user_flair_v2?unique=0&raw_json=1" + }, + "response": { + "body": { + "string": "[{\"allowable_content\": \"all\", \"text\": \"PRAW\", \"text_color\": \"dark\", \"mod_only\": false, \"background_color\": \"#abcdef\", \"id\": \"3c602924-4450-11ee-a33f-2667db42e4a6\", \"css_class\": \"myCSS\", \"max_emojis\": 10, \"richtext\": [], \"text_editable\": false, \"override_css\": false, \"type\": \"text\"}, {\"allowable_content\": \"all\", \"text\": \"PRAW2\", \"text_color\": \"dark\", \"mod_only\": false, \"background_color\": \"#abcdef\", \"id\": \"3c90fd74-4450-11ee-8287-eee2453f66ac\", \"css_class\": \"myCSS\", \"max_emojis\": 10, \"richtext\": [], \"text_editable\": false, \"override_css\": false, \"type\": \"text\"}, {\"allowable_content\": \"all\", \"text\": \"PRAW3\", \"text_color\": \"dark\", \"mod_only\": false, \"background_color\": \"#abcdef\", \"id\": \"3cd3a25a-4450-11ee-a8ca-b28ede539ab9\", \"css_class\": \"myCSS\", \"max_emojis\": 10, \"richtext\": [], \"text_editable\": false, \"override_css\": false, \"type\": \"text\"}]" + }, + "headers": { + "Accept-Ranges": [ + "bytes" + ], + "Cache-Control": [ + "private, s-maxage=0, max-age=0, must-revalidate, no-store" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "851" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Date": [ + "Fri, 13 Oct 2023 19:33:25 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.Z0FBQUFBQmxLWnVGWnJ2R0dmWmQ0bnNQZFVKU2Z4cHZtM2VwVFpPTUJ3Y2NHZUVNb1REWU1LcXBzWWdYYlFqc1czem91UG03QkRveENOX1FMMzF3Q09UZ0c4RlNpUy00a3ZzR3hKQnVJdy0weDBtRG0tdE9IZF96UjlyWFJyc3NlMENFQ2Q0X19KWlQ; Domain=reddit.com; Max-Age=63071999; Path=/; expires=Sun, 12-Oct-2025 19:33:25 GMT; secure; SameSite=None; Secure", + "session_tracker=lkfeqfoqkrjplqbirb.0.1697225605430.Z0FBQUFBQmxLWnVGek93eFduOVNEMkw4T0JQWl9sbkNnYk5jVkRFOTg5a1BaSFBZRzhfMjBwWVVfeHpnMnFrMWlLcVJYQ0g5MFA3eFMwMXNCRndCRWNYX0VzbkhRejdvM01pZ0J3MTF2NkRUNnVoMDBkUkxmSzZYZ3F0LVg0QlM0dk14TC1ZNjRkSzU; Domain=reddit.com; Max-Age=7199; Path=/; expires=Fri, 13-Oct-2023 21:33:25 GMT; secure; SameSite=None; Secure", + "redesign_optout=true; Domain=reddit.com; Max-Age=94607999; Path=/; expires=Mon, 12-Oct-2026 19:33:25 GMT; 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": [ + "993" + ], + "x-ratelimit-reset": [ + "395" + ], + "x-ratelimit-used": [ + "3" + ], + "x-ua-compatible": [ + "IE=edge" + ] + }, + "status": { + "code": 200, + "message": "OK" + }, + "url": "https://oauth.reddit.com/r//api/user_flair_v2?unique=0&raw_json=1" + } + }, + { + "request": { + "body": null, + "headers": { + "Accept-Encoding": [ + "identity" + ], + "Authorization": [ + "bearer " + ], + "Cookie": [ + "csv=2; edgebucket=9orqOkKoXniBU86A6p; loid=0000000000000o77bz.2.1434669370561.Z0FBQUFBQmxLWnVGWnJ2R0dmWmQ0bnNQZFVKU2Z4cHZtM2VwVFpPTUJ3Y2NHZUVNb1REWU1LcXBzWWdYYlFqc1czem91UG03QkRveENOX1FMMzF3Q09UZ0c4RlNpUy00a3ZzR3hKQnVJdy0weDBtRG0tdE9IZF96UjlyWFJyc3NlMENFQ2Q0X19KWlQ; redesign_optout=true; session_tracker=lkfeqfoqkrjplqbirb.0.1697225605430.Z0FBQUFBQmxLWnVGek93eFduOVNEMkw4T0JQWl9sbkNnYk5jVkRFOTg5a1BaSFBZRzhfMjBwWVVfeHpnMnFrMWlLcVJYQ0g5MFA3eFMwMXNCRndCRWNYX0VzbkhRejdvM01pZ0J3MTF2NkRUNnVoMDBkUkxmSzZYZ3F0LVg0QlM0dk14TC1ZNjRkSzU" + ], + "User-Agent": [ + " Async PRAW/7.7.2.dev0 asyncprawcore/2.3.0" + ] + }, + "method": "GET", + "uri": "https://oauth.reddit.com/r//api/user_flair_v2?unique=1&raw_json=1" + }, + "response": { + "body": { + "string": "[{\"allowable_content\": \"all\", \"text\": \"PRAW\", \"text_color\": \"dark\", \"mod_only\": false, \"background_color\": \"#abcdef\", \"id\": \"3c602924-4450-11ee-a33f-2667db42e4a6\", \"css_class\": \"myCSS\", \"max_emojis\": 10, \"richtext\": [], \"text_editable\": false, \"override_css\": false, \"type\": \"text\"}, {\"allowable_content\": \"all\", \"text\": \"PRAW2\", \"text_color\": \"dark\", \"mod_only\": false, \"background_color\": \"#abcdef\", \"id\": \"3c90fd74-4450-11ee-8287-eee2453f66ac\", \"css_class\": \"myCSS\", \"max_emojis\": 10, \"richtext\": [], \"text_editable\": false, \"override_css\": false, \"type\": \"text\"}, {\"allowable_content\": \"all\", \"text\": \"PRAW3\", \"text_color\": \"dark\", \"mod_only\": false, \"background_color\": \"#abcdef\", \"id\": \"3cd3a25a-4450-11ee-a8ca-b28ede539ab9\", \"css_class\": \"myCSS\", \"max_emojis\": 10, \"richtext\": [], \"text_editable\": false, \"override_css\": false, \"type\": \"text\"}]" + }, + "headers": { + "Accept-Ranges": [ + "bytes" + ], + "Cache-Control": [ + "private, s-maxage=0, max-age=0, must-revalidate, no-store" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "851" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Date": [ + "Fri, 13 Oct 2023 19:33:25 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=lkfeqfoqkrjplqbirb.0.1697225605559.Z0FBQUFBQmxLWnVGVEp0ZU02ZDRDNUxpYjB1Y3gwYlJQT2tYZUZ4YjZpSkh1aGNXWU9sUDBXVWJCM0w4SzVfdmE5TF9ub1VwYkJwenZ1UFBVZkI1Z2JfZ2s1a3JQaXRnMTE5azBrSUNySEVDUGoyNDgxWmxySlducWJlQ2NqMl9TdGxobnozdENxY04; Domain=reddit.com; Max-Age=7199; Path=/; expires=Fri, 13-Oct-2023 21:33:25 GMT; secure; SameSite=None; 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": [ + "992" + ], + "x-ratelimit-reset": [ + "395" + ], + "x-ratelimit-used": [ + "4" + ], + "x-ua-compatible": [ + "IE=edge" + ] + }, + "status": { + "code": 200, + "message": "OK" + }, + "url": "https://oauth.reddit.com/r//api/user_flair_v2?unique=1&raw_json=1" + } + }, + { + "request": { + "body": null, + "headers": { + "Accept-Encoding": [ + "identity" + ], + "Authorization": [ + "bearer " + ], + "Cookie": [ + "csv=2; edgebucket=9orqOkKoXniBU86A6p; loid=0000000000000o77bz.2.1434669370561.Z0FBQUFBQmxLWnVGWnJ2R0dmWmQ0bnNQZFVKU2Z4cHZtM2VwVFpPTUJ3Y2NHZUVNb1REWU1LcXBzWWdYYlFqc1czem91UG03QkRveENOX1FMMzF3Q09UZ0c4RlNpUy00a3ZzR3hKQnVJdy0weDBtRG0tdE9IZF96UjlyWFJyc3NlMENFQ2Q0X19KWlQ; redesign_optout=true; session_tracker=lkfeqfoqkrjplqbirb.0.1697225605559.Z0FBQUFBQmxLWnVGVEp0ZU02ZDRDNUxpYjB1Y3gwYlJQT2tYZUZ4YjZpSkh1aGNXWU9sUDBXVWJCM0w4SzVfdmE5TF9ub1VwYkJwenZ1UFBVZkI1Z2JfZ2s1a3JQaXRnMTE5azBrSUNySEVDUGoyNDgxWmxySlducWJlQ2NqMl9TdGxobnozdENxY04" + ], + "User-Agent": [ + " Async PRAW/7.7.2.dev0 asyncprawcore/2.3.0" + ] + }, + "method": "PATCH", + "uri": "https://oauth.reddit.com/r//api/flair_template_order?flair_type=USER_FLAIR&subreddit=&raw_json=1" + }, + "response": { + "body": { + "string": "" + }, + "headers": { + "Accept-Ranges": [ + "bytes" + ], + "Cache-Control": [ + "private, s-maxage=0, max-age=0, must-revalidate, no-store" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "0" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Date": [ + "Fri, 13 Oct 2023 19:33:25 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=lkfeqfoqkrjplqbirb.0.1697225605683.Z0FBQUFBQmxLWnVGWjRXN0lodlV6RXJseDdQNnBxYkJLeC03bTJkWEFyUGR4SjFwS21hcGl0eWdwUWVnZS1YaDlQSjFlejNtcUlVZG1nTlA5SEh5NV9QRThhVEJ2RUY2SWtRcHpHLWh1OXJscVgxeFJPcF9FZkV3MXhPcmFjc2dhUGZhdm04cmtkV2Y; Domain=reddit.com; Max-Age=7199; Path=/; expires=Fri, 13-Oct-2023 21:33:25 GMT; secure" + ], + "Strict-Transport-Security": [ + "max-age=31536000; includeSubdomains" + ], + "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": [ + "991" + ], + "x-ratelimit-reset": [ + "395" + ], + "x-ratelimit-used": [ + "5" + ], + "x-ua-compatible": [ + "IE=edge" + ] + }, + "status": { + "code": 200, + "message": "OK" + }, + "url": "https://oauth.reddit.com/r//api/flair_template_order?flair_type=USER_FLAIR&subreddit=&raw_json=1" + } + }, + { + "request": { + "body": null, + "headers": { + "Accept-Encoding": [ + "identity" + ], + "Authorization": [ + "bearer " + ], + "Cookie": [ + "csv=2; edgebucket=9orqOkKoXniBU86A6p; loid=0000000000000o77bz.2.1434669370561.Z0FBQUFBQmxLWnVGWnJ2R0dmWmQ0bnNQZFVKU2Z4cHZtM2VwVFpPTUJ3Y2NHZUVNb1REWU1LcXBzWWdYYlFqc1czem91UG03QkRveENOX1FMMzF3Q09UZ0c4RlNpUy00a3ZzR3hKQnVJdy0weDBtRG0tdE9IZF96UjlyWFJyc3NlMENFQ2Q0X19KWlQ; redesign_optout=true; session_tracker=lkfeqfoqkrjplqbirb.0.1697225605683.Z0FBQUFBQmxLWnVGWjRXN0lodlV6RXJseDdQNnBxYkJLeC03bTJkWEFyUGR4SjFwS21hcGl0eWdwUWVnZS1YaDlQSjFlejNtcUlVZG1nTlA5SEh5NV9QRThhVEJ2RUY2SWtRcHpHLWh1OXJscVgxeFJPcF9FZkV3MXhPcmFjc2dhUGZhdm04cmtkV2Y" + ], + "User-Agent": [ + " Async PRAW/7.7.2.dev0 asyncprawcore/2.3.0" + ] + }, + "method": "GET", + "uri": "https://oauth.reddit.com/r//api/user_flair_v2?unique=2&raw_json=1" + }, + "response": { + "body": { + "string": "[{\"allowable_content\": \"all\", \"text\": \"PRAW3\", \"text_color\": \"dark\", \"mod_only\": false, \"background_color\": \"#abcdef\", \"id\": \"3cd3a25a-4450-11ee-a8ca-b28ede539ab9\", \"css_class\": \"myCSS\", \"max_emojis\": 10, \"richtext\": [], \"text_editable\": false, \"override_css\": false, \"type\": \"text\"}, {\"allowable_content\": \"all\", \"text\": \"PRAW2\", \"text_color\": \"dark\", \"mod_only\": false, \"background_color\": \"#abcdef\", \"id\": \"3c90fd74-4450-11ee-8287-eee2453f66ac\", \"css_class\": \"myCSS\", \"max_emojis\": 10, \"richtext\": [], \"text_editable\": false, \"override_css\": false, \"type\": \"text\"}, {\"allowable_content\": \"all\", \"text\": \"PRAW\", \"text_color\": \"dark\", \"mod_only\": false, \"background_color\": \"#abcdef\", \"id\": \"3c602924-4450-11ee-a33f-2667db42e4a6\", \"css_class\": \"myCSS\", \"max_emojis\": 10, \"richtext\": [], \"text_editable\": false, \"override_css\": false, \"type\": \"text\"}]" + }, + "headers": { + "Accept-Ranges": [ + "bytes" + ], + "Cache-Control": [ + "private, s-maxage=0, max-age=0, must-revalidate, no-store" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "851" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Date": [ + "Fri, 13 Oct 2023 19:33:25 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=lkfeqfoqkrjplqbirb.0.1697225605840.Z0FBQUFBQmxLWnVGMEtQdkRoRGtnakJpcl9CbFZEMW4xQVBLR0QybHJ5dE1ER0xKWlZHZU9tS2d5bjE4RWM2OE1SNm9nVE96TE1qZHhkYWlDeW1iMklwdEF4UHJESjNCNkxicW0yZ1o3ZzBud2JPVDNfdlRBV0M3VUV1OVdqaE1jTDBDdDZWZmdpa2Y; Domain=reddit.com; Max-Age=7199; Path=/; expires=Fri, 13-Oct-2023 21:33:25 GMT; secure; SameSite=None; 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": [ + "990" + ], + "x-ratelimit-reset": [ + "395" + ], + "x-ratelimit-used": [ + "6" + ], + "x-ua-compatible": [ + "IE=edge" + ] + }, + "status": { + "code": 200, + "message": "OK" + }, + "url": "https://oauth.reddit.com/r//api/user_flair_v2?unique=2&raw_json=1" + } + } + ], + "recorded_at": "2023-10-13T19:33:25", + "version": 1 +} diff --git a/tests/integration/cassettes/TestSubredditLinkFlairTemplates.test_reorder.json b/tests/integration/cassettes/TestSubredditLinkFlairTemplates.test_reorder.json new file mode 100644 index 00000000..ca3bffa4 --- /dev/null +++ b/tests/integration/cassettes/TestSubredditLinkFlairTemplates.test_reorder.json @@ -0,0 +1,486 @@ +{ + "interactions": [ + { + "request": { + "body": [ + [ + "grant_type", + "refresh_token" + ], + [ + "refresh_token", + "" + ] + ], + "headers": { + "AUTHORIZATION": [ + "Basic " + ], + "Accept-Encoding": [ + "identity" + ], + "Connection": [ + "close" + ], + "User-Agent": [ + " Async PRAW/7.7.2.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\": \"*\"}" + }, + "headers": { + "Accept-Ranges": [ + "bytes" + ], + "Cache-Control": [ + "private, max-age=3600" + ], + "Connection": [ + "close" + ], + "Content-Length": [ + "960" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Date": [ + "Fri, 13 Oct 2023 19:34:16 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=Ku8LXeU9okoMVFhuCP; 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=Ku8LXeU9okoMVFhuCP" + ], + "User-Agent": [ + " Async PRAW/7.7.2.dev0 asyncprawcore/2.3.0" + ] + }, + "method": "GET", + "uri": "https://oauth.reddit.com/r//api/link_flair_v2?raw_json=1" + }, + "response": { + "body": { + "string": "[{\"type\": \"text\", \"text_editable\": true, \"allowable_content\": \"all\", \"text\": \"another\", \"max_emojis\": 10, \"text_color\": \"dark\", \"mod_only\": false, \"css_class\": \"\", \"richtext\": [], \"background_color\": \"\", \"id\": \"aa80b3be-f56b-11eb-8c89-1a66d9a33ef0\"}, {\"type\": \"text\", \"text_editable\": true, \"allowable_content\": \"all\", \"text\": \"test\", \"max_emojis\": 10, \"text_color\": \"dark\", \"mod_only\": false, \"css_class\": \"\", \"richtext\": [], \"background_color\": \"#dadada\", \"id\": \"6fc213da-cae7-11ea-9274-0e2407099e45\"}]" + }, + "headers": { + "Accept-Ranges": [ + "bytes" + ], + "Cache-Control": [ + "private, s-maxage=0, max-age=0, must-revalidate, no-store" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "504" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Date": [ + "Fri, 13 Oct 2023 19:34:16 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.Z0FBQUFBQmxLWnU0a3BLTElXZWhTalBhOGtSeUVOS2RvSUtDMDlEZ1VybEFYRUswU1RhUWVLMlFhanl5NkpVZFBhZDIzNHcwbXlRQmtUaGVRc1h4b3N1V1hadEU2VnlpemhvSnpod2FPZkR1MXJpUDNFNkIwR2VZR09pY2dTMlJvU2hUQnJZRW5mOVE; Domain=reddit.com; Max-Age=63071999; Path=/; expires=Sun, 12-Oct-2025 19:34:16 GMT; secure; SameSite=None; Secure", + "session_tracker=omnqccermpnhjmcobh.0.1697225656530.Z0FBQUFBQmxLWnU0elU4R3ZhTlAxbWNsaXBhSGxhaGx3aXdORVZGRUF5eFQ2akZ3dnRiZnk5SmtYb1A5NEZ1ejVPSDJwSmo1RnR2anQzeEhvX0FLZk1Xd3ZnNG5aU3Fyb3RJanFqaU9ZRWVwWjdHd2pqNVRMWk9GNlFTY2lEN3lMdjhLbVFIM0VTbW0; Domain=reddit.com; Max-Age=7199; Path=/; expires=Fri, 13-Oct-2023 21:34:16 GMT; secure; SameSite=None; Secure", + "redesign_optout=true; Domain=reddit.com; Max-Age=94607999; Path=/; expires=Mon, 12-Oct-2026 19:34:16 GMT; secure", + "csv=2; Max-Age=63072000; Domain=.reddit.com; Path=/; Secure; SameSite=None" + ], + "Strict-Transport-Security": [ + "max-age=31536000; includeSubdomains" + ], + "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": [ + "986" + ], + "x-ratelimit-reset": [ + "344" + ], + "x-ratelimit-used": [ + "10" + ], + "x-ua-compatible": [ + "IE=edge" + ] + }, + "status": { + "code": 200, + "message": "OK" + }, + "url": "https://oauth.reddit.com/r//api/link_flair_v2?raw_json=1" + } + }, + { + "request": { + "body": null, + "headers": { + "Accept-Encoding": [ + "identity" + ], + "Authorization": [ + "bearer " + ], + "Cookie": [ + "csv=2; edgebucket=Ku8LXeU9okoMVFhuCP; loid=0000000000000o77bz.2.1434669370561.Z0FBQUFBQmxLWnU0a3BLTElXZWhTalBhOGtSeUVOS2RvSUtDMDlEZ1VybEFYRUswU1RhUWVLMlFhanl5NkpVZFBhZDIzNHcwbXlRQmtUaGVRc1h4b3N1V1hadEU2VnlpemhvSnpod2FPZkR1MXJpUDNFNkIwR2VZR09pY2dTMlJvU2hUQnJZRW5mOVE; redesign_optout=true; session_tracker=omnqccermpnhjmcobh.0.1697225656530.Z0FBQUFBQmxLWnU0elU4R3ZhTlAxbWNsaXBhSGxhaGx3aXdORVZGRUF5eFQ2akZ3dnRiZnk5SmtYb1A5NEZ1ejVPSDJwSmo1RnR2anQzeEhvX0FLZk1Xd3ZnNG5aU3Fyb3RJanFqaU9ZRWVwWjdHd2pqNVRMWk9GNlFTY2lEN3lMdjhLbVFIM0VTbW0" + ], + "User-Agent": [ + " Async PRAW/7.7.2.dev0 asyncprawcore/2.3.0" + ] + }, + "method": "GET", + "uri": "https://oauth.reddit.com/r//api/link_flair_v2?raw_json=1" + }, + "response": { + "body": { + "string": "[{\"type\": \"text\", \"text_editable\": true, \"allowable_content\": \"all\", \"text\": \"another\", \"max_emojis\": 10, \"text_color\": \"dark\", \"mod_only\": false, \"css_class\": \"\", \"richtext\": [], \"background_color\": \"\", \"id\": \"aa80b3be-f56b-11eb-8c89-1a66d9a33ef0\"}, {\"type\": \"text\", \"text_editable\": true, \"allowable_content\": \"all\", \"text\": \"test\", \"max_emojis\": 10, \"text_color\": \"dark\", \"mod_only\": false, \"css_class\": \"\", \"richtext\": [], \"background_color\": \"#dadada\", \"id\": \"6fc213da-cae7-11ea-9274-0e2407099e45\"}]" + }, + "headers": { + "Accept-Ranges": [ + "bytes" + ], + "Cache-Control": [ + "private, s-maxage=0, max-age=0, must-revalidate, no-store" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "504" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Date": [ + "Fri, 13 Oct 2023 19:34:16 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=omnqccermpnhjmcobh.0.1697225656665.Z0FBQUFBQmxLWnU0UXFlV1dSQlQ1aUtUSXFqcmpJZ3NTWDZBTGdvUWJjdW9rNHZKbThIUzdDQlFicW5QdllmeVU1SU5RMGpReWpCRUNvU3lCVXVlRXRiMGdiZFJhVkg2MFNCNzFDUEE0TzRwbERnOFB0enRZX3lKN3FwNjRSQmF5bFE5WC1SMDRuSlQ; Domain=reddit.com; Max-Age=7199; Path=/; expires=Fri, 13-Oct-2023 21:34:16 GMT; secure; SameSite=None; Secure" + ], + "Strict-Transport-Security": [ + "max-age=31536000; includeSubdomains" + ], + "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": [ + "985" + ], + "x-ratelimit-reset": [ + "344" + ], + "x-ratelimit-used": [ + "11" + ], + "x-ua-compatible": [ + "IE=edge" + ] + }, + "status": { + "code": 200, + "message": "OK" + }, + "url": "https://oauth.reddit.com/r//api/link_flair_v2?raw_json=1" + } + }, + { + "request": { + "body": null, + "headers": { + "Accept-Encoding": [ + "identity" + ], + "Authorization": [ + "bearer " + ], + "Cookie": [ + "csv=2; edgebucket=Ku8LXeU9okoMVFhuCP; loid=0000000000000o77bz.2.1434669370561.Z0FBQUFBQmxLWnU0a3BLTElXZWhTalBhOGtSeUVOS2RvSUtDMDlEZ1VybEFYRUswU1RhUWVLMlFhanl5NkpVZFBhZDIzNHcwbXlRQmtUaGVRc1h4b3N1V1hadEU2VnlpemhvSnpod2FPZkR1MXJpUDNFNkIwR2VZR09pY2dTMlJvU2hUQnJZRW5mOVE; redesign_optout=true; session_tracker=omnqccermpnhjmcobh.0.1697225656665.Z0FBQUFBQmxLWnU0UXFlV1dSQlQ1aUtUSXFqcmpJZ3NTWDZBTGdvUWJjdW9rNHZKbThIUzdDQlFicW5QdllmeVU1SU5RMGpReWpCRUNvU3lCVXVlRXRiMGdiZFJhVkg2MFNCNzFDUEE0TzRwbERnOFB0enRZX3lKN3FwNjRSQmF5bFE5WC1SMDRuSlQ" + ], + "User-Agent": [ + " Async PRAW/7.7.2.dev0 asyncprawcore/2.3.0" + ] + }, + "method": "PATCH", + "uri": "https://oauth.reddit.com/r//api/flair_template_order?flair_type=LINK_FLAIR&subreddit=&raw_json=1" + }, + "response": { + "body": { + "string": "" + }, + "headers": { + "Accept-Ranges": [ + "bytes" + ], + "Cache-Control": [ + "private, s-maxage=0, max-age=0, must-revalidate, no-store" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "0" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Date": [ + "Fri, 13 Oct 2023 19:34:16 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=omnqccermpnhjmcobh.0.1697225656822.Z0FBQUFBQmxLWnU0SmJGaktTX1lmSkdkZGdtemZsUFduTVBORkdTTkNkTmNZVmZ0OGpiS05vYjhBYWRGQVJYSmxQRGpONENpLUpYSng5dVFVQS0yX0Zhb0U3bTlEWE5JU0ktU2otRU1KQS00WFcxRzh2X0IyeTB3MFlqMFZpcl8xTXpPOVZwa0xRTWI; Domain=reddit.com; Max-Age=7199; Path=/; expires=Fri, 13-Oct-2023 21:34:16 GMT; secure" + ], + "Strict-Transport-Security": [ + "max-age=31536000; includeSubdomains" + ], + "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": [ + "984" + ], + "x-ratelimit-reset": [ + "344" + ], + "x-ratelimit-used": [ + "12" + ], + "x-ua-compatible": [ + "IE=edge" + ] + }, + "status": { + "code": 200, + "message": "OK" + }, + "url": "https://oauth.reddit.com/r//api/flair_template_order?flair_type=LINK_FLAIR&subreddit=&raw_json=1" + } + }, + { + "request": { + "body": null, + "headers": { + "Accept-Encoding": [ + "identity" + ], + "Authorization": [ + "bearer " + ], + "Cookie": [ + "csv=2; edgebucket=Ku8LXeU9okoMVFhuCP; loid=0000000000000o77bz.2.1434669370561.Z0FBQUFBQmxLWnU0a3BLTElXZWhTalBhOGtSeUVOS2RvSUtDMDlEZ1VybEFYRUswU1RhUWVLMlFhanl5NkpVZFBhZDIzNHcwbXlRQmtUaGVRc1h4b3N1V1hadEU2VnlpemhvSnpod2FPZkR1MXJpUDNFNkIwR2VZR09pY2dTMlJvU2hUQnJZRW5mOVE; redesign_optout=true; session_tracker=omnqccermpnhjmcobh.0.1697225656822.Z0FBQUFBQmxLWnU0SmJGaktTX1lmSkdkZGdtemZsUFduTVBORkdTTkNkTmNZVmZ0OGpiS05vYjhBYWRGQVJYSmxQRGpONENpLUpYSng5dVFVQS0yX0Zhb0U3bTlEWE5JU0ktU2otRU1KQS00WFcxRzh2X0IyeTB3MFlqMFZpcl8xTXpPOVZwa0xRTWI" + ], + "User-Agent": [ + " Async PRAW/7.7.2.dev0 asyncprawcore/2.3.0" + ] + }, + "method": "GET", + "uri": "https://oauth.reddit.com/r//api/link_flair_v2?raw_json=1" + }, + "response": { + "body": { + "string": "[{\"type\": \"text\", \"text_editable\": true, \"allowable_content\": \"all\", \"text\": \"test\", \"max_emojis\": 10, \"text_color\": \"dark\", \"mod_only\": false, \"css_class\": \"\", \"richtext\": [], \"background_color\": \"#dadada\", \"id\": \"6fc213da-cae7-11ea-9274-0e2407099e45\"}, {\"type\": \"text\", \"text_editable\": true, \"allowable_content\": \"all\", \"text\": \"another\", \"max_emojis\": 10, \"text_color\": \"dark\", \"mod_only\": false, \"css_class\": \"\", \"richtext\": [], \"background_color\": \"\", \"id\": \"aa80b3be-f56b-11eb-8c89-1a66d9a33ef0\"}]" + }, + "headers": { + "Accept-Ranges": [ + "bytes" + ], + "Cache-Control": [ + "private, s-maxage=0, max-age=0, must-revalidate, no-store" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "504" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Date": [ + "Fri, 13 Oct 2023 19:34:17 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=omnqccermpnhjmcobh.0.1697225656958.Z0FBQUFBQmxLWnU0aUZ6WEtUemxKQjlxWGlITHhBYi01dWVBTF8wZFdVQ195cFk0ZHNjc1pMTlMwME5zb2NaT1Zrbi1JbGlsTFBzclFhcTZGQWs5U3NjRDBlbzhpUy1neXN0akp0NE1jbjhNYi04WmV2cjg1VVdQcVQ2cGpkZ1d2cTQ4Yk5tLWVDRFk; Domain=reddit.com; Max-Age=7199; Path=/; expires=Fri, 13-Oct-2023 21:34:16 GMT; secure; SameSite=None; Secure" + ], + "Strict-Transport-Security": [ + "max-age=31536000; includeSubdomains" + ], + "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": [ + "983" + ], + "x-ratelimit-reset": [ + "344" + ], + "x-ratelimit-used": [ + "13" + ], + "x-ua-compatible": [ + "IE=edge" + ] + }, + "status": { + "code": 200, + "message": "OK" + }, + "url": "https://oauth.reddit.com/r//api/link_flair_v2?raw_json=1" + } + } + ], + "recorded_at": "2023-10-13T19:34:16", + "version": 1 +} diff --git a/tests/integration/models/reddit/test_subreddit.py b/tests/integration/models/reddit/test_subreddit.py index 9ea4c15c..bc470cac 100644 --- a/tests/integration/models/reddit/test_subreddit.py +++ b/tests/integration/models/reddit/test_subreddit.py @@ -240,6 +240,16 @@ async def test_delete(self, reddit): template = next(iter(await self.async_list(subreddit.flair.templates))) await subreddit.flair.templates.delete(template["id"]) + async def test_reorder(self, reddit): + reddit.read_only = False + subreddit = await reddit.subreddit(pytest.placeholders.test_subreddit) + original = await self.async_list(subreddit.flair.templates) + flairs = [flair["id"] async for flair in subreddit.flair.templates] + await subreddit.flair.templates.reorder(list(reversed(flairs))) + assert (await self.async_list(subreddit.flair.templates)) == list( + reversed(original) + ) + async def test_update(self, reddit): reddit.read_only = False subreddit = await reddit.subreddit(pytest.placeholders.test_subreddit) @@ -369,6 +379,16 @@ async def test_clear(self, reddit): subreddit = await reddit.subreddit(pytest.placeholders.test_subreddit) await subreddit.flair.link_templates.clear() + async def test_reorder(self, reddit): + reddit.read_only = False + subreddit = await reddit.subreddit(pytest.placeholders.test_subreddit) + original = await self.async_list(subreddit.flair.link_templates) + flairs = [flair["id"] async for flair in subreddit.flair.link_templates] + await subreddit.flair.link_templates.reorder(list(reversed(flairs))) + assert (await self.async_list(subreddit.flair.link_templates)) == list( + reversed(original) + ) + async def test_user_selectable(self, reddit): reddit.read_only = False subreddit = await reddit.subreddit(pytest.placeholders.test_subreddit)