From c559a3fb1f92fd1ba11def7d3d2b5062c690b62e Mon Sep 17 00:00:00 2001 From: nathan smith Date: Mon, 26 Jun 2023 15:56:39 +0100 Subject: [PATCH] Added support for reordering flairs through reddit.flair.reorder --- CHANGES.rst | 7 + praw/endpoints.py | 1 + praw/models/reddit/subreddit.py | 51 +- praw/reddit.py | 19 +- ...tSubredditFlairTemplates.test_reorder.json | 548 ++++++++++++++++++ ...redditLinkFlairTemplates.test_reorder.json | 539 +++++++++++++++++ .../models/reddit/test_subreddit.py | 16 + 7 files changed, 1173 insertions(+), 8 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 b5cea8564..1320efeea 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,6 +6,13 @@ 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. + 7.7.1 (2023/07/11) ------------------ diff --git a/praw/endpoints.py b/praw/endpoints.py index 104d2141f..eaef33a6d 100644 --- a/praw/endpoints.py +++ b/praw/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/praw/models/reddit/subreddit.py b/praw/models/reddit/subreddit.py index 73f0a6691..d4ffc7e44 100644 --- a/praw/models/reddit/subreddit.py +++ b/praw/models/reddit/subreddit.py @@ -830,6 +830,11 @@ def _fetch(self): self.__dict__.update(other.__dict__) self._fetched = True + def _fetch_data(self) -> dict: + name, fields, params = self._fetch_info() + path = API_PATH[name].format(**fields) + return self._reddit.request(method="GET", params=params, path=path) + def _fetch_info(self): return "subreddit_about", {"subreddit": self}, None @@ -2225,6 +2230,17 @@ def delete(self, template_id: str): url = API_PATH["flairtemplatedelete"].format(subreddit=self.subreddit) self.subreddit._reddit.post(url, data={"flair_template_id": template_id}) + def _reorder(self, flair_list: list, *, is_link: Optional[bool] = None): + url = API_PATH["flairtemplatereorder"].format(subreddit=self.subreddit) + 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", @@ -2728,7 +2744,7 @@ def update( :param submit_text_label: Custom label for submit text post button (``None`` for default). :param subreddit_type: One of ``"archived"``, ``"employees_only"``, - ``"gold_only"``, ``"gold_restricted"``, ``"private"``, ``"public"``, or + ``"gold_only"``, ``gold_restricted``, ``"private"``, ``"public"``, or ``"restricted"``. :param suggested_comment_sort: All comment threads will use this sorting method by default. Leave ``None``, or choose one of ``"confidence"``, @@ -4130,6 +4146,22 @@ def clear(self): """ self._clear(is_link=True) + 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 = reddit.subreddit("test") + flairs = [flair["id"] for flair in subreddit.flair.link_templates] + subreddit.flair.link_templates.reorder(list(reversed(flairs))) + + """ + self._reorder(flair_list, is_link=True) + def user_selectable( self, ) -> Generator[Dict[str, Union[str, bool]], None, None]: @@ -4245,3 +4277,20 @@ def clear(self): """ self._clear(is_link=False) + + 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))) + + """ + self._reorder(flair_list, is_link=False) diff --git a/praw/reddit.py b/praw/reddit.py index 9364f5b89..cca57caf0 100644 --- a/praw/reddit.py +++ b/praw/reddit.py @@ -13,6 +13,7 @@ Dict, Generator, Iterable, + List, Optional, Type, Union, @@ -493,7 +494,7 @@ 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 = "", @@ -670,7 +671,7 @@ 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``. @@ -794,7 +795,8 @@ 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``. @@ -804,9 +806,12 @@ 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 self._objectify_request(data=data, json=json, method="PATCH", path=path) + return self._objectify_request( + data=data, json=json, method="PATCH", params=params, path=path + ) @_deprecate_args("path", "data", "files", "params", "json") def post( @@ -815,7 +820,7 @@ 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``. @@ -863,7 +868,7 @@ 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``. @@ -913,7 +918,7 @@ 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 000000000..cd85da340 --- /dev/null +++ b/tests/integration/cassettes/TestSubredditFlairTemplates.test_reorder.json @@ -0,0 +1,548 @@ +{ + "http_interactions": [ + { + "recorded_at": "2023-08-26T20:37:00", + "request": { + "body": { + "encoding": "utf-8", + "string": "grant_type=refresh_token&refresh_token=" + }, + "headers": { + "Accept": [ + "*/*" + ], + "Accept-Encoding": [ + "identity" + ], + "Authorization": [ + "Basic " + ], + "Connection": [ + "close" + ], + "Content-Length": [ + "82" + ], + "Content-Type": [ + "application/x-www-form-urlencoded" + ], + "User-Agent": [ + " PRAW/7.7.2.dev0 prawcore/2.3.0" + ] + }, + "method": "POST", + "uri": "https://www.reddit.com/api/v1/access_token" + }, + "response": { + "body": { + "encoding": "UTF-8", + "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 read privatemessages report identity livemanage account modtraffic wikiread edit modwiki modself history flair\"}" + }, + "headers": { + "Accept-Ranges": [ + "bytes" + ], + "Cache-Control": [ + "private, max-age=3600" + ], + "Connection": [ + "close" + ], + "Content-Length": [ + "1527" + ], + "Date": [ + "Sat, 26 Aug 2023 20:37:00 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=WpJSHDtulMun2MXHSv; 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" + ], + "content-type": [ + "application/json; charset=UTF-8" + ], + "x-moose": [ + "majestic" + ] + }, + "status": { + "code": 200, + "message": "OK" + }, + "url": "https://www.reddit.com/api/v1/access_token" + } + }, + { + "recorded_at": "2023-08-26T20:37:00", + "request": { + "body": { + "encoding": "utf-8", + "string": "" + }, + "headers": { + "Accept": [ + "*/*" + ], + "Accept-Encoding": [ + "identity" + ], + "Authorization": [ + "bearer " + ], + "Connection": [ + "keep-alive" + ], + "Cookie": [ + "edgebucket=WpJSHDtulMun2MXHSv" + ], + "User-Agent": [ + " PRAW/7.7.2.dev0 prawcore/2.3.0" + ] + }, + "method": "GET", + "uri": "https://oauth.reddit.com/r//api/user_flair_v2?unique=0&raw_json=1" + }, + "response": { + "body": { + "encoding": "UTF-8", + "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" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "851" + ], + "Date": [ + "Sat, 26 Aug 2023 20:37:00 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=000000000075u2lqkb.2.1593898363221.Z0FBQUFBQms2bUpzODE1QWVOZnIwc2p6cDJUUE81dVVnRHYwdkhkeDhUdlZPQXFGLVpSUEJMN3AwUW9qSkN3eEpkY1ZkYzRxWUNjRDRTbVcwcVBpMWVEUlBBTko4dGJUNDIxbDFiVjFPVkYzYVQxN2I0dG1VRnI0bklGRGJYb2h3SGliX3NFR1J3TXA; Domain=reddit.com; Max-Age=63071999; Path=/; expires=Mon, 25-Aug-2025 20:37:00 GMT; secure; SameSite=None; Secure", + "session_tracker=bnijfmibicgkrfmorm.0.1693082220421.Z0FBQUFBQms2bUpzUnJrOWU1WmFsaGlaSm1qVWVYRTRuTE1oU191YjlFMERWdXl6bi1Wc3I3dTQycmVWSXNDRklZMmNmaEdOd1dnUWhTTFdHcDZtbzFPY0JDRV9kb2V5eU5aVnhlUWFKNGNuaDhEY3pYaGRZYU1QNFZUV2lsUmVrZ2stVUlfVlMtbWk; Domain=reddit.com; Max-Age=7199; Path=/; expires=Sat, 26-Aug-2023 22:37:00 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" + ], + "cache-control": [ + "private, s-maxage=0, max-age=0, must-revalidate, no-store" + ], + "content-type": [ + "application/json; charset=UTF-8" + ], + "expires": [ + "-1" + ], + "x-moose": [ + "majestic" + ], + "x-ratelimit-remaining": [ + "971" + ], + "x-ratelimit-reset": [ + "180" + ], + "x-ratelimit-used": [ + "25" + ], + "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" + } + }, + { + "recorded_at": "2023-08-26T20:37:00", + "request": { + "body": { + "encoding": "utf-8", + "string": "" + }, + "headers": { + "Accept": [ + "*/*" + ], + "Accept-Encoding": [ + "identity" + ], + "Authorization": [ + "bearer " + ], + "Connection": [ + "keep-alive" + ], + "Cookie": [ + "edgebucket=WpJSHDtulMun2MXHSv; loid=000000000075u2lqkb.2.1593898363221.Z0FBQUFBQms2bUpzODE1QWVOZnIwc2p6cDJUUE81dVVnRHYwdkhkeDhUdlZPQXFGLVpSUEJMN3AwUW9qSkN3eEpkY1ZkYzRxWUNjRDRTbVcwcVBpMWVEUlBBTko4dGJUNDIxbDFiVjFPVkYzYVQxN2I0dG1VRnI0bklGRGJYb2h3SGliX3NFR1J3TXA; session_tracker=bnijfmibicgkrfmorm.0.1693082220421.Z0FBQUFBQms2bUpzUnJrOWU1WmFsaGlaSm1qVWVYRTRuTE1oU191YjlFMERWdXl6bi1Wc3I3dTQycmVWSXNDRklZMmNmaEdOd1dnUWhTTFdHcDZtbzFPY0JDRV9kb2V5eU5aVnhlUWFKNGNuaDhEY3pYaGRZYU1QNFZUV2lsUmVrZ2stVUlfVlMtbWk; csv=2" + ], + "User-Agent": [ + " PRAW/7.7.2.dev0 prawcore/2.3.0" + ] + }, + "method": "GET", + "uri": "https://oauth.reddit.com/r//api/user_flair_v2?unique=1&raw_json=1" + }, + "response": { + "body": { + "encoding": "UTF-8", + "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" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "851" + ], + "Date": [ + "Sat, 26 Aug 2023 20:37:00 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": [ + "session_tracker=bnijfmibicgkrfmorm.0.1693082220757.Z0FBQUFBQms2bUpzcjB2WHVzTzJhMk1JWmhiRnJ3ZzNHeHdtdnMyM0Q2amxrNjFQZGJIRllwUDhKS0lRSFo0RWp5VTJzYTk5TWUzX05aQ1UyR2ZReUhxRjZiWnp3b252cHh4OV9HMVB6U04yMnU2cVNkeHR3d3h5dk05SDlPOTJEbzVCZGM3bF9XdTk; Domain=reddit.com; Max-Age=7199; Path=/; expires=Sat, 26-Aug-2023 22:37:00 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" + ], + "cache-control": [ + "private, s-maxage=0, max-age=0, must-revalidate, no-store" + ], + "content-type": [ + "application/json; charset=UTF-8" + ], + "expires": [ + "-1" + ], + "x-moose": [ + "majestic" + ], + "x-ratelimit-remaining": [ + "970" + ], + "x-ratelimit-reset": [ + "180" + ], + "x-ratelimit-used": [ + "26" + ], + "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" + } + }, + { + "recorded_at": "2023-08-26T20:37:00", + "request": { + "body": { + "encoding": "utf-8", + "string": "[\"3c602924-4450-11ee-a33f-2667db42e4a6\", \"3c90fd74-4450-11ee-8287-eee2453f66ac\", \"3cd3a25a-4450-11ee-a8ca-b28ede539ab9\"]" + }, + "headers": { + "Accept": [ + "*/*" + ], + "Accept-Encoding": [ + "identity" + ], + "Authorization": [ + "bearer " + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "120" + ], + "Content-Type": [ + "application/json" + ], + "Cookie": [ + "edgebucket=WpJSHDtulMun2MXHSv; loid=000000000075u2lqkb.2.1593898363221.Z0FBQUFBQms2bUpzODE1QWVOZnIwc2p6cDJUUE81dVVnRHYwdkhkeDhUdlZPQXFGLVpSUEJMN3AwUW9qSkN3eEpkY1ZkYzRxWUNjRDRTbVcwcVBpMWVEUlBBTko4dGJUNDIxbDFiVjFPVkYzYVQxN2I0dG1VRnI0bklGRGJYb2h3SGliX3NFR1J3TXA; session_tracker=bnijfmibicgkrfmorm.0.1693082220757.Z0FBQUFBQms2bUpzcjB2WHVzTzJhMk1JWmhiRnJ3ZzNHeHdtdnMyM0Q2amxrNjFQZGJIRllwUDhKS0lRSFo0RWp5VTJzYTk5TWUzX05aQ1UyR2ZReUhxRjZiWnp3b252cHh4OV9HMVB6U04yMnU2cVNkeHR3d3h5dk05SDlPOTJEbzVCZGM3bF9XdTk; csv=2" + ], + "User-Agent": [ + " PRAW/7.7.2.dev0 prawcore/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": { + "encoding": "UTF-8", + "string": "" + }, + "headers": { + "Accept-Ranges": [ + "bytes" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "0" + ], + "Date": [ + "Sat, 26 Aug 2023 20:37:00 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" + ], + "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" + ], + "cache-control": [ + "private, s-maxage=0, max-age=0, must-revalidate, no-store" + ], + "content-type": [ + "application/json; charset=UTF-8" + ], + "expires": [ + "-1" + ], + "set-cookie": [ + "session_tracker=bnijfmibicgkrfmorm.0.1693082220914.Z0FBQUFBQms2bUpzWnd1VlBuT0g1ZjBBWWVUNmxBVmRxMTgxanFjV3NXUTZDVWtmdG5CVWp6aGliSlVjVjlqUGNMRXlldVYwUElMR0VkSlowbjB2ZHhNVTc4VnZIWHg3cUdCVTg0S3VfOE9qZ3A4TzJXbTRscWQ1SE5QbHMwc1FCZEZZbmI4VWppY3k; Domain=reddit.com; Max-Age=7199; Path=/; expires=Sat, 26-Aug-2023 22:37:00 GMT; secure" + ], + "x-moose": [ + "majestic" + ], + "x-ratelimit-remaining": [ + "969" + ], + "x-ratelimit-reset": [ + "180" + ], + "x-ratelimit-used": [ + "27" + ], + "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" + } + }, + { + "recorded_at": "2023-08-26T20:37:01", + "request": { + "body": { + "encoding": "utf-8", + "string": "" + }, + "headers": { + "Accept": [ + "*/*" + ], + "Accept-Encoding": [ + "identity" + ], + "Authorization": [ + "bearer " + ], + "Connection": [ + "keep-alive" + ], + "Cookie": [ + "edgebucket=WpJSHDtulMun2MXHSv; loid=000000000075u2lqkb.2.1593898363221.Z0FBQUFBQms2bUpzODE1QWVOZnIwc2p6cDJUUE81dVVnRHYwdkhkeDhUdlZPQXFGLVpSUEJMN3AwUW9qSkN3eEpkY1ZkYzRxWUNjRDRTbVcwcVBpMWVEUlBBTko4dGJUNDIxbDFiVjFPVkYzYVQxN2I0dG1VRnI0bklGRGJYb2h3SGliX3NFR1J3TXA; session_tracker=bnijfmibicgkrfmorm.0.1693082220914.Z0FBQUFBQms2bUpzWnd1VlBuT0g1ZjBBWWVUNmxBVmRxMTgxanFjV3NXUTZDVWtmdG5CVWp6aGliSlVjVjlqUGNMRXlldVYwUElMR0VkSlowbjB2ZHhNVTc4VnZIWHg3cUdCVTg0S3VfOE9qZ3A4TzJXbTRscWQ1SE5QbHMwc1FCZEZZbmI4VWppY3k; csv=2" + ], + "User-Agent": [ + " PRAW/7.7.2.dev0 prawcore/2.3.0" + ] + }, + "method": "GET", + "uri": "https://oauth.reddit.com/r//api/user_flair_v2?unique=2&raw_json=1" + }, + "response": { + "body": { + "encoding": "UTF-8", + "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" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "851" + ], + "Date": [ + "Sat, 26 Aug 2023 20:37: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": [ + "session_tracker=bnijfmibicgkrfmorm.0.1693082221143.Z0FBQUFBQms2bUp0MlFYUmlpSEVVcDZ2VlBjTWpab181dlRhT3FZSG9fU2FDRGFKOTBjUkQ2UG1IZkJzOW1ZV2tPUlB1MHhoNUloUGdVeTV5dkxySzhvSk1IZ1RncFVvNkpBVmJpclgtY0ZqeU9UX0RtWmgwSkxjRXpMV3FOUktzcWVCYk8ySkhvcHo; Domain=reddit.com; Max-Age=7199; Path=/; expires=Sat, 26-Aug-2023 22:37:01 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" + ], + "cache-control": [ + "private, s-maxage=0, max-age=0, must-revalidate, no-store" + ], + "content-type": [ + "application/json; charset=UTF-8" + ], + "expires": [ + "-1" + ], + "x-moose": [ + "majestic" + ], + "x-ratelimit-remaining": [ + "968" + ], + "x-ratelimit-reset": [ + "179" + ], + "x-ratelimit-used": [ + "28" + ], + "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_with": "betamax/0.8.1" +} diff --git a/tests/integration/cassettes/TestSubredditLinkFlairTemplates.test_reorder.json b/tests/integration/cassettes/TestSubredditLinkFlairTemplates.test_reorder.json new file mode 100644 index 000000000..c1dc051c7 --- /dev/null +++ b/tests/integration/cassettes/TestSubredditLinkFlairTemplates.test_reorder.json @@ -0,0 +1,539 @@ +{ + "http_interactions": [ + { + "recorded_at": "2023-08-26T20:34:45", + "request": { + "body": { + "encoding": "utf-8", + "string": "grant_type=refresh_token&refresh_token=" + }, + "headers": { + "Accept": [ + "*/*" + ], + "Accept-Encoding": [ + "identity" + ], + "Authorization": [ + "Basic " + ], + "Connection": [ + "close" + ], + "Content-Length": [ + "82" + ], + "Content-Type": [ + "application/x-www-form-urlencoded" + ], + "User-Agent": [ + " PRAW/7.7.2.dev0 prawcore/2.3.0" + ] + }, + "method": "POST", + "uri": "https://www.reddit.com/api/v1/access_token" + }, + "response": { + "body": { + "encoding": "UTF-8", + "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 read privatemessages report identity livemanage account modtraffic wikiread edit modwiki modself history flair\"}" + }, + "headers": { + "Accept-Ranges": [ + "bytes" + ], + "Cache-Control": [ + "private, max-age=3600" + ], + "Connection": [ + "close" + ], + "Content-Length": [ + "1527" + ], + "Date": [ + "Sat, 26 Aug 2023 20:34:45 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=QNBgZvwSIl7hxK70z8; 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" + ], + "content-type": [ + "application/json; charset=UTF-8" + ], + "x-moose": [ + "majestic" + ] + }, + "status": { + "code": 200, + "message": "OK" + }, + "url": "https://www.reddit.com/api/v1/access_token" + } + }, + { + "recorded_at": "2023-08-26T20:34:45", + "request": { + "body": { + "encoding": "utf-8", + "string": "" + }, + "headers": { + "Accept": [ + "*/*" + ], + "Accept-Encoding": [ + "identity" + ], + "Authorization": [ + "bearer " + ], + "Connection": [ + "keep-alive" + ], + "Cookie": [ + "edgebucket=QNBgZvwSIl7hxK70z8" + ], + "User-Agent": [ + " PRAW/7.7.2.dev0 prawcore/2.3.0" + ] + }, + "method": "GET", + "uri": "https://oauth.reddit.com/r//api/link_flair_v2?raw_json=1" + }, + "response": { + "body": { + "encoding": "UTF-8", + "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" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "504" + ], + "Date": [ + "Sat, 26 Aug 2023 20:34:46 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=000000000075u2lqkb.2.1593898363221.Z0FBQUFBQms2bUhsdkdxdTBzUGZZUXRNRHZlUmJESk5UTjZOWmF0TFBsZVZlcWMxSmxfWmlkZHZjeE82UDZ5cDhYV01mVkRQWno5WG9ZaXltRnRDcG1BTjV3UElwNXpOOXBxbkM1VzRyT19Qei1BZGthbTY3VEs2Z1NtLW5aVTVvRTZxb3U4cUs4T2Y; Domain=reddit.com; Max-Age=63071999; Path=/; expires=Mon, 25-Aug-2025 20:34:45 GMT; secure; SameSite=None; Secure", + "session_tracker=pdlcjabpqnarfjcdfr.0.1693082085952.Z0FBQUFBQms2bUhsT1VWVVJ4cWJydzdNbmp1ZXotSmR0WVd5c3JnTzhzWU1JV09qSHNyT2FIbGJJWW16R09SM2VOaW5BcE5oeVpib0l0WnktNW4yTkcxZEJTdjNqZDFJWWV5TXh2SGFKaVFVc0hFZUNiSnRTc3VGTEhVbVAzaFRaRm81MmF1ckJNTTY; Domain=reddit.com; Max-Age=7199; Path=/; expires=Sat, 26-Aug-2023 22:34:45 GMT; secure; SameSite=None; 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" + ], + "cache-control": [ + "private, s-maxage=0, max-age=0, must-revalidate, no-store" + ], + "content-type": [ + "application/json; charset=UTF-8" + ], + "expires": [ + "-1" + ], + "x-moose": [ + "majestic" + ], + "x-ratelimit-remaining": [ + "985" + ], + "x-ratelimit-reset": [ + "315" + ], + "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" + } + }, + { + "recorded_at": "2023-08-26T20:34:46", + "request": { + "body": { + "encoding": "utf-8", + "string": "" + }, + "headers": { + "Accept": [ + "*/*" + ], + "Accept-Encoding": [ + "identity" + ], + "Authorization": [ + "bearer " + ], + "Connection": [ + "keep-alive" + ], + "Cookie": [ + "edgebucket=QNBgZvwSIl7hxK70z8; loid=000000000075u2lqkb.2.1593898363221.Z0FBQUFBQms2bUhsdkdxdTBzUGZZUXRNRHZlUmJESk5UTjZOWmF0TFBsZVZlcWMxSmxfWmlkZHZjeE82UDZ5cDhYV01mVkRQWno5WG9ZaXltRnRDcG1BTjV3UElwNXpOOXBxbkM1VzRyT19Qei1BZGthbTY3VEs2Z1NtLW5aVTVvRTZxb3U4cUs4T2Y; session_tracker=pdlcjabpqnarfjcdfr.0.1693082085952.Z0FBQUFBQms2bUhsT1VWVVJ4cWJydzdNbmp1ZXotSmR0WVd5c3JnTzhzWU1JV09qSHNyT2FIbGJJWW16R09SM2VOaW5BcE5oeVpib0l0WnktNW4yTkcxZEJTdjNqZDFJWWV5TXh2SGFKaVFVc0hFZUNiSnRTc3VGTEhVbVAzaFRaRm81MmF1ckJNTTY; csv=2" + ], + "User-Agent": [ + " PRAW/7.7.2.dev0 prawcore/2.3.0" + ] + }, + "method": "GET", + "uri": "https://oauth.reddit.com/r//api/link_flair_v2?raw_json=1" + }, + "response": { + "body": { + "encoding": "UTF-8", + "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" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "504" + ], + "Date": [ + "Sat, 26 Aug 2023 20:34:46 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": [ + "session_tracker=pdlcjabpqnarfjcdfr.0.1693082086112.Z0FBQUFBQms2bUhtY1NkNnhOVXowWVl5UVRSbXdzVFNiWlNUdnJtRUVBS0RNeFY2QWVaUGdZMFZvbHVBWlBBZUxFQ1kyMnZjNHlxcVFMcTk2SEc1TFZMZWhZTGZZWHBxdF9wZjJ6ck92SlY5Q0FQTXpCcGdob3psRFg5cl9QZVlRSTZRSERlM1kxaHY; Domain=reddit.com; Max-Age=7199; Path=/; expires=Sat, 26-Aug-2023 22:34:46 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" + ], + "cache-control": [ + "private, s-maxage=0, max-age=0, must-revalidate, no-store" + ], + "content-type": [ + "application/json; charset=UTF-8" + ], + "expires": [ + "-1" + ], + "x-moose": [ + "majestic" + ], + "x-ratelimit-remaining": [ + "984" + ], + "x-ratelimit-reset": [ + "314" + ], + "x-ratelimit-used": [ + "12" + ], + "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-08-26T20:34:46", + "request": { + "body": { + "encoding": "utf-8", + "string": "[\"aa80b3be-f56b-11eb-8c89-1a66d9a33ef0\", \"6fc213da-cae7-11ea-9274-0e2407099e45\"]" + }, + "headers": { + "Accept": [ + "*/*" + ], + "Accept-Encoding": [ + "identity" + ], + "Authorization": [ + "bearer " + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "80" + ], + "Content-Type": [ + "application/json" + ], + "Cookie": [ + "edgebucket=QNBgZvwSIl7hxK70z8; loid=000000000075u2lqkb.2.1593898363221.Z0FBQUFBQms2bUhsdkdxdTBzUGZZUXRNRHZlUmJESk5UTjZOWmF0TFBsZVZlcWMxSmxfWmlkZHZjeE82UDZ5cDhYV01mVkRQWno5WG9ZaXltRnRDcG1BTjV3UElwNXpOOXBxbkM1VzRyT19Qei1BZGthbTY3VEs2Z1NtLW5aVTVvRTZxb3U4cUs4T2Y; session_tracker=pdlcjabpqnarfjcdfr.0.1693082086112.Z0FBQUFBQms2bUhtY1NkNnhOVXowWVl5UVRSbXdzVFNiWlNUdnJtRUVBS0RNeFY2QWVaUGdZMFZvbHVBWlBBZUxFQ1kyMnZjNHlxcVFMcTk2SEc1TFZMZWhZTGZZWHBxdF9wZjJ6ck92SlY5Q0FQTXpCcGdob3psRFg5cl9QZVlRSTZRSERlM1kxaHY; csv=2" + ], + "User-Agent": [ + " PRAW/7.7.2.dev0 prawcore/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": { + "encoding": "UTF-8", + "string": "" + }, + "headers": { + "Accept-Ranges": [ + "bytes" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "0" + ], + "Date": [ + "Sat, 26 Aug 2023 20:34:46 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" + ], + "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" + ], + "cache-control": [ + "private, s-maxage=0, max-age=0, must-revalidate, no-store" + ], + "content-type": [ + "application/json; charset=UTF-8" + ], + "expires": [ + "-1" + ], + "set-cookie": [ + "session_tracker=pdlcjabpqnarfjcdfr.0.1693082086270.Z0FBQUFBQms2bUhtVE5JZVJ3SzA2bnBrbEtsTlBnV3EtQW5UZzItS3ctNnNNSEhmUllKcVROTThER1RKeGtKQjNhOU8zdUstallZU3VSNWp0d1o1Y19VUDVYVjYwNWI5X3NfaGtrU2FnbDR6aHFxakxlUVJKaHByWW1sUmQtZl9Wd3VjWWhpcnhiWHI; Domain=reddit.com; Max-Age=7199; Path=/; expires=Sat, 26-Aug-2023 22:34:46 GMT; secure" + ], + "x-moose": [ + "majestic" + ], + "x-ratelimit-remaining": [ + "983" + ], + "x-ratelimit-reset": [ + "314" + ], + "x-ratelimit-used": [ + "13" + ], + "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" + } + }, + { + "recorded_at": "2023-08-26T20:34:46", + "request": { + "body": { + "encoding": "utf-8", + "string": "" + }, + "headers": { + "Accept": [ + "*/*" + ], + "Accept-Encoding": [ + "identity" + ], + "Authorization": [ + "bearer " + ], + "Connection": [ + "keep-alive" + ], + "Cookie": [ + "edgebucket=QNBgZvwSIl7hxK70z8; loid=000000000075u2lqkb.2.1593898363221.Z0FBQUFBQms2bUhsdkdxdTBzUGZZUXRNRHZlUmJESk5UTjZOWmF0TFBsZVZlcWMxSmxfWmlkZHZjeE82UDZ5cDhYV01mVkRQWno5WG9ZaXltRnRDcG1BTjV3UElwNXpOOXBxbkM1VzRyT19Qei1BZGthbTY3VEs2Z1NtLW5aVTVvRTZxb3U4cUs4T2Y; session_tracker=pdlcjabpqnarfjcdfr.0.1693082086270.Z0FBQUFBQms2bUhtVE5JZVJ3SzA2bnBrbEtsTlBnV3EtQW5UZzItS3ctNnNNSEhmUllKcVROTThER1RKeGtKQjNhOU8zdUstallZU3VSNWp0d1o1Y19VUDVYVjYwNWI5X3NfaGtrU2FnbDR6aHFxakxlUVJKaHByWW1sUmQtZl9Wd3VjWWhpcnhiWHI; csv=2" + ], + "User-Agent": [ + " PRAW/7.7.2.dev0 prawcore/2.3.0" + ] + }, + "method": "GET", + "uri": "https://oauth.reddit.com/r//api/link_flair_v2?raw_json=1" + }, + "response": { + "body": { + "encoding": "UTF-8", + "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" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "504" + ], + "Date": [ + "Sat, 26 Aug 2023 20:34:46 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": [ + "session_tracker=pdlcjabpqnarfjcdfr.0.1693082086530.Z0FBQUFBQms2bUhtc3h4SFdkVzYtVmNWUEE4M3JMMEthUXJWN2ZtRjhPQTZwdlJHV2JTbHlZVlVDdXNRRFdNVGN6TkRNcHItdjdMc2J0T3ZoWGMxa0g3ZF9rZWxLbzFEUFVYQ3dpUE0yVHpscWlLSmFTakxFcTc2VnFHWEVNbTNKazhlY1UwMUFRdGY; Domain=reddit.com; Max-Age=7199; Path=/; expires=Sat, 26-Aug-2023 22:34:46 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" + ], + "cache-control": [ + "private, s-maxage=0, max-age=0, must-revalidate, no-store" + ], + "content-type": [ + "application/json; charset=UTF-8" + ], + "expires": [ + "-1" + ], + "x-moose": [ + "majestic" + ], + "x-ratelimit-remaining": [ + "982" + ], + "x-ratelimit-reset": [ + "314" + ], + "x-ratelimit-used": [ + "14" + ], + "x-ua-compatible": [ + "IE=edge" + ] + }, + "status": { + "code": 200, + "message": "OK" + }, + "url": "https://oauth.reddit.com/r//api/link_flair_v2?raw_json=1" + } + } + ], + "recorded_with": "betamax/0.8.1" +} diff --git a/tests/integration/models/reddit/test_subreddit.py b/tests/integration/models/reddit/test_subreddit.py index 02bdea8a5..2ddee0527 100644 --- a/tests/integration/models/reddit/test_subreddit.py +++ b/tests/integration/models/reddit/test_subreddit.py @@ -232,6 +232,14 @@ def test_delete(self, reddit): subreddit = reddit.subreddit(pytest.placeholders.test_subreddit) subreddit.flair.templates.delete(template["id"]) + def test_reorder(self, reddit): + reddit.read_only = False + subreddit = reddit.subreddit(pytest.placeholders.test_subreddit) + original = list(subreddit.flair.templates) + flairs = [flair["id"] for flair in subreddit.flair.templates] + subreddit.flair.templates.reorder(list(reversed(flairs))) + assert list(subreddit.flair.templates) == list(reversed(original)) + def test_update(self, reddit): reddit.read_only = False subreddit = reddit.subreddit(pytest.placeholders.test_subreddit) @@ -364,6 +372,14 @@ def test_clear(self, reddit): subreddit = reddit.subreddit(pytest.placeholders.test_subreddit) subreddit.flair.link_templates.clear() + def test_reorder(self, reddit): + reddit.read_only = False + subreddit = reddit.subreddit(pytest.placeholders.test_subreddit) + original = list(subreddit.flair.link_templates) + flairs = [flair["id"] for flair in subreddit.flair.link_templates] + subreddit.flair.link_templates.reorder(list(reversed(flairs))) + assert list(subreddit.flair.link_templates) == list(reversed(original)) + def test_user_selectable(self, reddit): reddit.read_only = False subreddit = reddit.subreddit(pytest.placeholders.test_subreddit)