From 11e92afc4bf64c4bac3eabb879db0109a01103f8 Mon Sep 17 00:00:00 2001 From: PythonCoderAS <13932583+PythonCoderAS@users.noreply.github.com> Date: Sat, 21 Mar 2020 20:05:01 -0400 Subject: [PATCH 1/3] Merge Stylesheet and SubredditStylesheet --- CHANGES.rst | 8 + praw/models/__init__.py | 1 - praw/models/reddit/subreddit.py | 51 +++- praw/models/stylesheet.py | 23 -- praw/reddit.py | 1 - .../TestSubredditStylesheet.test_attrs.json | 221 ++++++++++++++++++ .../models/reddit/test_subreddit.py | 13 +- tests/unit/models/reddit/test_subreddit.py | 6 + tests/unit/test_deprecations.py | 4 + 9 files changed, 291 insertions(+), 37 deletions(-) delete mode 100644 praw/models/stylesheet.py create mode 100644 tests/integration/cassettes/TestSubredditStylesheet.test_attrs.json diff --git a/CHANGES.rst b/CHANGES.rst index 3b9b19e16f..3584a43440 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -62,6 +62,12 @@ Unreleased * :attr:`.WebSocketException.original_exception` is deprecated and slated for removal in PRAW 8.0. +**Deprecated** + +* :class:`.SubredditStylesheet`\ 's ``__call__`` method + (``subreddit.stylesheet()``) is deprecated and slotted for removal in PRAW + 8.0. + **Fixed** * An issue where certain subreddit settings could not be set through @@ -170,6 +176,8 @@ Unreleased using an invalid template id, but instead throw a :class:`.InvalidFlairTemplateID`. * Method ``reddit.user.moderator_subreddits`` has been removed. Please use :meth:`.Redditor.moderated` instead. +* Class ``Stylesheet`` no longer exists. It has been merged with + :class:`.SubredditStylesheet`. 6.5.1 (2020/01/07) ------------------ diff --git a/praw/models/__init__.py b/praw/models/__init__.py index 91f1d0c796..6faf2ddaf8 100644 --- a/praw/models/__init__.py +++ b/praw/models/__init__.py @@ -52,7 +52,6 @@ ) from .reddit.wikipage import WikiPage from .redditors import Redditors -from .stylesheet import Stylesheet from .subreddits import Subreddits from .trophy import Trophy from .user import User diff --git a/praw/models/reddit/subreddit.py b/praw/models/reddit/subreddit.py index b557a777e2..350953faa6 100644 --- a/praw/models/reddit/subreddit.py +++ b/praw/models/reddit/subreddit.py @@ -9,6 +9,7 @@ from os.path import basename, dirname, isfile, join from typing import List from urllib.parse import urljoin +from warnings import warn from xml.etree.ElementTree import XML import websocket @@ -3197,22 +3198,47 @@ def submissions(self, **stream_options): return stream_generator(self.subreddit.new, **stream_options) -class SubredditStylesheet: +class SubredditStylesheet(RedditBase): """Provides a set of stylesheet functions to a Subreddit. + **Typical Attributes** + + This table describes attributes that typically belong to objects of this + class. Since attributes are dynamically provided (see + :ref:`determine-available-attributes-of-an-object`), there is not a + guarantee that these attributes will always be present, nor is this list + necessarily comprehensive. + + ======================= =================================================== + Attribute Description + ======================= =================================================== + ``images`` A :class:`list` of images used by the stylesheet. + ``stylesheet`` The contents of the stylesheet, as CSS. + ======================= =================================================== + For example, to add the css data ``.test{color:blue}`` to the existing stylesheet: .. code-block:: python subreddit = reddit.subreddit("SUBREDDIT") - stylesheet = subreddit.stylesheet() + stylesheet = subreddit.stylesheet.stylesheet stylesheet += ".test{color:blue}" subreddit.stylesheet.update(stylesheet) """ + STR_FIELD = "subreddit_display_name" + def __call__(self): - """Return the subreddit's stylesheet. + """Return the subreddit's stylesheet (Deprecated). + + .. note:: As of PRAW 7.0, the model containing the stylesheet data and + the class holding the methods have been combined into one. The + new class is a lazy class, meaning that attributes have to be + called for if wanted. The __call__ method will return itself. + + .. warning:: This method is slated for removal in the next major PRAW + release (8.0). To be used as: @@ -3221,8 +3247,14 @@ def __call__(self): stylesheet = reddit.subreddit("SUBREDDIT").stylesheet() """ - url = API_PATH["about_stylesheet"].format(subreddit=self.subreddit) - return self.subreddit._reddit.get(url) + warn( + "This method is deprecated and will be removed in PRAW 8.0. " + "Removing the call will still result in the same functionality. " + "To do so, remove the ``()`` before the stylesheet attribute.", + category=DeprecationWarning, + stacklevel=2, + ) + return self def __init__(self, subreddit): """Create a SubredditStylesheet instance. @@ -3237,6 +3269,15 @@ def __init__(self, subreddit): """ self.subreddit = subreddit + super().__init__(subreddit._reddit, None) + self.subreddit_display_name = self.subreddit.display_name + + def _fetch(self): + url = API_PATH["about_stylesheet"].format(subreddit=self.subreddit) + data = self.subreddit._reddit.get(url) + data = data["data"] + del data["subreddit_id"] + self.__dict__.update(data) def _update_structured_styles(self, style_data): url = API_PATH["structured_styles"].format(subreddit=self.subreddit) diff --git a/praw/models/stylesheet.py b/praw/models/stylesheet.py deleted file mode 100644 index 184cc5a1e8..0000000000 --- a/praw/models/stylesheet.py +++ /dev/null @@ -1,23 +0,0 @@ -"""Provide the Stylesheet class.""" - -from .base import PRAWBase - - -class Stylesheet(PRAWBase): - """Represent a stylesheet. - - **Typical Attributes** - - This table describes attributes that typically belong to objects of this class. - Since attributes are dynamically provided (see - :ref:`determine-available-attributes-of-an-object`), there is not a guarantee that - these attributes will always be present, nor is this list necessarily complete. - - ======================= ============================================================ - Attribute Description - ======================= ============================================================ - ``images`` A ``list`` of images used by the stylesheet. - ``stylesheet`` The contents of the stylesheet, as CSS. - ======================= ============================================================ - - """ diff --git a/praw/reddit.py b/praw/reddit.py index e2fb3d8374..4c7950bb6f 100644 --- a/praw/reddit.py +++ b/praw/reddit.py @@ -390,7 +390,6 @@ def _prepare_objector(self): "more": models.MoreComments, "post-flair": models.PostFlairWidget, "rule": models.Rule, - "stylesheet": models.Stylesheet, "subreddit-rules": models.RulesWidget, "textarea": models.TextArea, "widget": models.Widget, diff --git a/tests/integration/cassettes/TestSubredditStylesheet.test_attrs.json b/tests/integration/cassettes/TestSubredditStylesheet.test_attrs.json new file mode 100644 index 0000000000..76e97499bc --- /dev/null +++ b/tests/integration/cassettes/TestSubredditStylesheet.test_attrs.json @@ -0,0 +1,221 @@ +{ + "http_interactions": [ + { + "recorded_at": "2020-03-21T23:53:51", + "request": { + "body": { + "encoding": "utf-8", + "string": "grant_type=password&password=&username=" + }, + "headers": { + "Accept": [ + "*/*" + ], + "Accept-Encoding": [ + "identity" + ], + "Authorization": [ + "Basic " + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "61" + ], + "Content-Type": [ + "application/x-www-form-urlencoded" + ], + "User-Agent": [ + " PRAW/7.0.0.dev0 prawcore/1.0.1" + ] + }, + "method": "POST", + "uri": "https://www.reddit.com/api/v1/access_token" + }, + "response": { + "body": { + "encoding": "UTF-8", + "string": "{\"access_token\": \"\", \"token_type\": \"bearer\", \"expires_in\": 3600, \"scope\": \"*\"}" + }, + "headers": { + "Accept-Ranges": [ + "bytes" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "118" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Date": [ + "Sat, 21 Mar 2020 23:53:51 GMT" + ], + "Server": [ + "snooserv" + ], + "Set-Cookie": [ + "edgebucket=b9GRcPdORfNO8naijI; Domain=reddit.com; Max-Age=63071999; Path=/; secure" + ], + "Strict-Transport-Security": [ + "max-age=15552000; includeSubDomains; preload" + ], + "Via": [ + "1.1 varnish" + ], + "X-Cache": [ + "MISS" + ], + "X-Cache-Hits": [ + "0" + ], + "X-Moose": [ + "majestic" + ], + "X-Served-By": [ + "cache-lga21941-LGA" + ], + "X-Timer": [ + "S1584834832.507552,VS0,VE314" + ], + "cache-control": [ + "max-age=0, must-revalidate" + ], + "x-content-type-options": [ + "nosniff" + ], + "x-frame-options": [ + "SAMEORIGIN" + ], + "x-xss-protection": [ + "1; mode=block" + ] + }, + "status": { + "code": 200, + "message": "OK" + }, + "url": "https://www.reddit.com/api/v1/access_token" + } + }, + { + "recorded_at": "2020-03-21T23:53:52", + "request": { + "body": { + "encoding": "utf-8", + "string": "" + }, + "headers": { + "Accept": [ + "*/*" + ], + "Accept-Encoding": [ + "identity" + ], + "Authorization": [ + "bearer " + ], + "Connection": [ + "keep-alive" + ], + "Cookie": [ + "edgebucket=b9GRcPdORfNO8naijI" + ], + "User-Agent": [ + " PRAW/7.0.0.dev0 prawcore/1.0.1" + ] + }, + "method": "GET", + "uri": "https://oauth.reddit.com/r//about/stylesheet/?raw_json=1" + }, + "response": { + "body": { + "encoding": "UTF-8", + "string": "{\"kind\": \"stylesheet\", \"data\": {\"images\": [{\"url\": \"https://b.thumbs.redditmedia.com/pFZFx9GVBHDtoJp_7We5AG3aWT1ldcLl6n55wYL2kro.png\", \"link\": \"url(%%Watermark%%)\", \"name\": \"Watermark\"}], \"subreddit_id\": \"t5_2bhxu0\", \"stylesheet\": \"/* test */\"}}" + }, + "headers": { + "Accept-Ranges": [ + "bytes" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "245" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "Date": [ + "Sat, 21 Mar 2020 23:53:52 GMT" + ], + "Server": [ + "snooserv" + ], + "Set-Cookie": [ + "loid=00000000005bn5wlvy.2.1577584524387.Z0FBQUFBQmVkcWtRRnFVcTJ1VC11Qnd3dUpDcVpRLXNPb0U2d1VvV2pxZFNCRmJMZW00ODRzcURTZXFtYlpkWlpfWXdkZllzZ0MyM0FQVFo0SXJURFdfVEhnVlBPNVpHTkFhaEdyMmhLRFVsT2dIMUhKYlZRaFQ0Ynh1blpvV2hoTWx0R0NQTFF1U3Y; Domain=reddit.com; Max-Age=63071999; Path=/; expires=Mon, 21-Mar-2022 23:53:52 GMT; secure; SameSite=None; Secure", + "session_tracker=fIz54mlWmWeZTqgtox.0.1584834832000.Z0FBQUFBQmVkcWtRMnBxRS1WU1lvNERSTkV2SnNuSWI4eVpwWkphTEVyalRjSjNNSDM1d3ptOEFIbWlxZHMzbmR4M0NPWEtUTmRGNVV6cTVJQkJ4MXpLUGhEX082R01VNHk2QmYxQ0NSZ1Y5UjUwNVJrZFFNNWZFT3ZBQTM4XzVYY1NJdC14VzBJVWI; Domain=reddit.com; Max-Age=7199; Path=/; expires=Sun, 22-Mar-2020 01:53:52 GMT; secure; SameSite=None; Secure", + "csv=1; Max-Age=63072000; Domain=.reddit.com; Path=/; Secure; SameSite=None" + ], + "Strict-Transport-Security": [ + "max-age=15552000; includeSubDomains; preload" + ], + "Via": [ + "1.1 varnish" + ], + "X-Cache": [ + "MISS" + ], + "X-Cache-Hits": [ + "0" + ], + "X-Moose": [ + "majestic" + ], + "X-Served-By": [ + "cache-lga21925-LGA" + ], + "X-Timer": [ + "S1584834832.963531,VS0,VE121" + ], + "cache-control": [ + "private, s-maxage=0, max-age=0, must-revalidate, no-store, max-age=0, must-revalidate" + ], + "expires": [ + "-1" + ], + "x-content-type-options": [ + "nosniff" + ], + "x-frame-options": [ + "SAMEORIGIN" + ], + "x-ratelimit-remaining": [ + "599.0" + ], + "x-ratelimit-reset": [ + "368" + ], + "x-ratelimit-used": [ + "1" + ], + "x-ua-compatible": [ + "IE=edge" + ], + "x-xss-protection": [ + "1; mode=block" + ] + }, + "status": { + "code": 200, + "message": "OK" + }, + "url": "https://oauth.reddit.com/r//about/stylesheet/?raw_json=1" + } + } + ], + "recorded_with": "betamax/0.8.1" +} \ No newline at end of file diff --git a/tests/integration/models/reddit/test_subreddit.py b/tests/integration/models/reddit/test_subreddit.py index 119ebab01d..127f35db76 100644 --- a/tests/integration/models/reddit/test_subreddit.py +++ b/tests/integration/models/reddit/test_subreddit.py @@ -34,7 +34,6 @@ ModmailConversation, ModmailMessage, Redditor, - Stylesheet, Submission, Subreddit, SubredditMessage, @@ -2018,12 +2017,12 @@ def image_path(name): def subreddit(self): return self.reddit.subreddit(pytest.placeholders.test_subreddit) - def test_call(self): - with self.recorder.use_cassette("TestSubredditStylesheet.test_call"): - stylesheet = self.subreddit.stylesheet() - assert isinstance(stylesheet, Stylesheet) - assert len(stylesheet.images) > 0 - assert stylesheet.stylesheet != "" + def test_attrs(self): + self.reddit.read_only = False + stylesheet = self.subreddit.stylesheet + with self.recorder.use_cassette("TestSubredditStylesheet.test_attrs"): + assert len(stylesheet.images) > 0 + assert stylesheet.stylesheet != "" def test_delete_banner(self): self.reddit.read_only = False diff --git a/tests/unit/models/reddit/test_subreddit.py b/tests/unit/models/reddit/test_subreddit.py index 4f90ae787b..bb971c4416 100644 --- a/tests/unit/models/reddit/test_subreddit.py +++ b/tests/unit/models/reddit/test_subreddit.py @@ -76,6 +76,12 @@ def test_repr(self): subreddit = Subreddit(self.reddit, display_name="name") assert repr(subreddit) == "Subreddit(display_name='name')" + @pytest.mark.filterwarnings("ignore", category=DeprecationWarning) + def test_stylesheet_call(self): + subreddit = self.reddit.subreddit(pytest.placeholders.test_subreddit) + style = subreddit.stylesheet + assert type(style()) == type(style) + def test_search__params_not_modified(self): params = {"dummy": "value"} subreddit = Subreddit(self.reddit, display_name="name") diff --git a/tests/unit/test_deprecations.py b/tests/unit/test_deprecations.py index a243bd0d29..b7254b685e 100644 --- a/tests/unit/test_deprecations.py +++ b/tests/unit/test_deprecations.py @@ -63,3 +63,7 @@ def test_gild_method(self): with pytest.raises(DeprecationWarning) as excinfo: self.reddit.submission("1234").gild() assert excinfo.value.args[0] == "`.gild` has been renamed to `.award`." + + def test_subreddit_stylesheet_call(self): + with pytest.raises(DeprecationWarning): + self.reddit.subreddit("test").stylesheet() From 481e4d7bffabb40b9caaeead496b04bd8952e11a Mon Sep 17 00:00:00 2001 From: PythonCoderAS <13932583+PythonCoderAS@users.noreply.github.com> Date: Sun, 22 Mar 2020 22:34:16 -0400 Subject: [PATCH 2/3] Code review suggestions --- praw/models/reddit/subreddit.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/praw/models/reddit/subreddit.py b/praw/models/reddit/subreddit.py index 350953faa6..33aeef3d30 100644 --- a/praw/models/reddit/subreddit.py +++ b/praw/models/reddit/subreddit.py @@ -482,7 +482,7 @@ def stylesheet(self): .. code-block:: python subreddit = reddit.subreddit("SUBREDDIT") - stylesheet = subreddit.stylesheet() + stylesheet = subreddit.stylesheet.stylesheet stylesheet += ".test{color:blue}" subreddit.stylesheet.update(stylesheet) @@ -3227,7 +3227,7 @@ class SubredditStylesheet(RedditBase): """ - STR_FIELD = "subreddit_display_name" + STR_FIELD = "subreddit_id" def __call__(self): """Return the subreddit's stylesheet (Deprecated). @@ -3270,13 +3270,11 @@ def __init__(self, subreddit): """ self.subreddit = subreddit super().__init__(subreddit._reddit, None) - self.subreddit_display_name = self.subreddit.display_name def _fetch(self): url = API_PATH["about_stylesheet"].format(subreddit=self.subreddit) data = self.subreddit._reddit.get(url) data = data["data"] - del data["subreddit_id"] self.__dict__.update(data) def _update_structured_styles(self, style_data): From 3a326ba1bb36780aee5a3280fffa0e0593d61344 Mon Sep 17 00:00:00 2001 From: PythonCoderAS <13932583+PythonCoderAS@users.noreply.github.com> Date: Tue, 19 May 2020 19:55:51 -0400 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Joey RH --- CHANGES.rst | 7 +- praw/models/reddit/subreddit.py | 21 ++-- .../TestSubredditStylesheet.test_call.json | 109 ------------------ .../models/reddit/test_subreddit.py | 14 +++ 4 files changed, 31 insertions(+), 120 deletions(-) delete mode 100644 tests/integration/cassettes/TestSubredditStylesheet.test_call.json diff --git a/CHANGES.rst b/CHANGES.rst index 3584a43440..c8ff0c812c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -80,6 +80,11 @@ Unreleased when Reddit fails to post an image or video post. +**Removed** + +* Class ``Stylesheet`` no longer exists. It has been merged with + :class:`.SubredditStylesheet`. + 7.0.0 (2020/04/24) ------------------ @@ -176,8 +181,6 @@ Unreleased using an invalid template id, but instead throw a :class:`.InvalidFlairTemplateID`. * Method ``reddit.user.moderator_subreddits`` has been removed. Please use :meth:`.Redditor.moderated` instead. -* Class ``Stylesheet`` no longer exists. It has been merged with - :class:`.SubredditStylesheet`. 6.5.1 (2020/01/07) ------------------ diff --git a/praw/models/reddit/subreddit.py b/praw/models/reddit/subreddit.py index 33aeef3d30..c8862667b7 100644 --- a/praw/models/reddit/subreddit.py +++ b/praw/models/reddit/subreddit.py @@ -3221,7 +3221,7 @@ class SubredditStylesheet(RedditBase): .. code-block:: python subreddit = reddit.subreddit("SUBREDDIT") - stylesheet = subreddit.stylesheet.stylesheet + stylesheet = subreddit.stylesheet.contents stylesheet += ".test{color:blue}" subreddit.stylesheet.update(stylesheet) @@ -3229,16 +3229,19 @@ class SubredditStylesheet(RedditBase): STR_FIELD = "subreddit_id" + @property + def contents(self) -> str: + """Obtain the contents of the subreddit's stylesheet.""" + return self.stylesheet + def __call__(self): """Return the subreddit's stylesheet (Deprecated). - .. note:: As of PRAW 7.0, the model containing the stylesheet data and - the class holding the methods have been combined into one. The - new class is a lazy class, meaning that attributes have to be - called for if wanted. The __call__ method will return itself. + .. note:: As of PRAW 7.1, the model containing the stylesheet data and + the class holding the methods have been combined into one. - .. warning:: This method is slated for removal in the next major PRAW - release (8.0). + .. deprecated:: 7.1 + This method will be removed in the next major release of PRAW (8.0) To be used as: @@ -3250,7 +3253,7 @@ def __call__(self): warn( "This method is deprecated and will be removed in PRAW 8.0. " "Removing the call will still result in the same functionality. " - "To do so, remove the ``()`` before the stylesheet attribute.", + "To do so, change `subreddit.stylesheet()` to `subreddit.stylesheet`.", category=DeprecationWarning, stacklevel=2, ) @@ -3273,7 +3276,7 @@ def __init__(self, subreddit): def _fetch(self): url = API_PATH["about_stylesheet"].format(subreddit=self.subreddit) - data = self.subreddit._reddit.get(url) + data = self._reddit.get(url) data = data["data"] self.__dict__.update(data) diff --git a/tests/integration/cassettes/TestSubredditStylesheet.test_call.json b/tests/integration/cassettes/TestSubredditStylesheet.test_call.json deleted file mode 100644 index cb0ea068c0..0000000000 --- a/tests/integration/cassettes/TestSubredditStylesheet.test_call.json +++ /dev/null @@ -1,109 +0,0 @@ -{ - "http_interactions": [ - { - "recorded_at": "2016-11-15T07:25:07", - "request": { - "body": { - "encoding": "utf-8", - "string": "grant_type=client_credentials" - }, - "headers": { - "Accept": "*/*", - "Accept-Encoding": "identity", - "Authorization": "Basic ", - "Connection": "keep-alive", - "Content-Length": "29", - "Content-Type": "application/x-www-form-urlencoded", - "User-Agent": " PRAW/4.0.0b22 prawcore/0.2.1" - }, - "method": "POST", - "uri": "https://www.reddit.com/api/v1/access_token" - }, - "response": { - "body": { - "encoding": "UTF-8", - "string": "{\"access_token\": \"rNkwGJCs1hso3mHRlRJhLEEqw0w\", \"token_type\": \"bearer\", \"expires_in\": 3600, \"scope\": \"*\"}" - }, - "headers": { - "Accept-Ranges": "bytes", - "Connection": "keep-alive", - "Content-Length": "105", - "Content-Type": "application/json; charset=UTF-8", - "Date": "Tue, 15 Nov 2016 07:25:07 GMT", - "Server": "snooserv", - "Set-Cookie": "loid=dJJX0lDGEhzX32ByAa; Domain=reddit.com; Max-Age=63071999; Path=/; secure", - "Strict-Transport-Security": "max-age=15552000; includeSubDomains; preload", - "Via": "1.1 varnish", - "X-Cache": "MISS", - "X-Cache-Hits": "0", - "X-Moose": "majestic", - "X-Served-By": "cache-sea1925-SEA", - "X-Timer": "S1479194707.112342,VS0,VE105", - "cache-control": "max-age=0, must-revalidate", - "x-content-type-options": "nosniff", - "x-frame-options": "SAMEORIGIN", - "x-xss-protection": "1; mode=block" - }, - "status": { - "code": 200, - "message": "OK" - }, - "url": "https://www.reddit.com/api/v1/access_token" - } - }, - { - "recorded_at": "2016-11-15T07:25:07", - "request": { - "body": { - "encoding": "utf-8", - "string": "" - }, - "headers": { - "Accept": "*/*", - "Accept-Encoding": "identity", - "Authorization": "bearer rNkwGJCs1hso3mHRlRJhLEEqw0w", - "Connection": "keep-alive", - "Cookie": "loidcreated=1479194707000; loid=dJJX0lDGEhzX32ByAa", - "User-Agent": " PRAW/4.0.0b22 prawcore/0.2.1" - }, - "method": "GET", - "uri": "https://oauth.reddit.com/r//about/stylesheet/?raw_json=1" - }, - "response": { - "body": { - "encoding": "UTF-8", - "string": "{\"kind\": \"stylesheet\", \"data\": {\"images\": [{\"url\": \"http://a.thumbs.redditmedia.com/-H12U-lP73t_KDrA2jre5hT35QiwMOE3OlxX33GW204.png\", \"link\": \"url(%%ad%%)\", \"name\": \"ad\"}], \"subreddit_id\": \"t5_2t5o6\", \"stylesheet\": \"div { color: blue; }\"}}" - }, - "headers": { - "Accept-Ranges": "bytes", - "Connection": "keep-alive", - "Content-Length": "239", - "Content-Type": "application/json; charset=UTF-8", - "Date": "Tue, 15 Nov 2016 07:25:07 GMT", - "Server": "snooserv", - "Strict-Transport-Security": "max-age=15552000; includeSubDomains; preload", - "Via": "1.1 varnish", - "X-Cache": "MISS", - "X-Cache-Hits": "0", - "X-Moose": "majestic", - "X-Served-By": "cache-sea1921-SEA", - "X-Timer": "S1479194707.446185,VS0,VE101", - "access-control-allow-origin": "*", - "access-control-expose-headers": "X-Reddit-Tracking, X-Moose", - "cache-control": "max-age=0, must-revalidate", - "x-content-type-options": "nosniff", - "x-frame-options": "SAMEORIGIN", - "x-reddit-tracking": "https://pixel.redditmedia.com/pixel/of_destiny.png?v=aCAX1HLybsaViQ7cWut2s4Zv7Jzdol0xP5OqOv0O1tIS0P8ivgUDxS1vLGBrlkyMwAzDSDY7XM1gOxSoF7KFXx34qhgs4CEC", - "x-ua-compatible": "IE=edge", - "x-xss-protection": "1; mode=block" - }, - "status": { - "code": 200, - "message": "OK" - }, - "url": "https://oauth.reddit.com/r//about/stylesheet/?raw_json=1" - } - } - ], - "recorded_with": "betamax/0.8.0" -} diff --git a/tests/integration/models/reddit/test_subreddit.py b/tests/integration/models/reddit/test_subreddit.py index 127f35db76..f35a7074ed 100644 --- a/tests/integration/models/reddit/test_subreddit.py +++ b/tests/integration/models/reddit/test_subreddit.py @@ -2024,6 +2024,20 @@ def test_attrs(self): assert len(stylesheet.images) > 0 assert stylesheet.stylesheet != "" + def test_call(self): + self.reddit.read_only = False + with self.recorder.use_cassette("TestSubredditStylesheet.test_attrs"): + stylesheet = self.subreddit.stylesheet() + assert len(stylesheet.images) > 0 + assert stylesheet.stylesheet != "" + + def test_contents(self): + self.reddit.read_only = False + stylesheet = self.subreddit.stylesheet + with self.recorder.use_cassette("TestSubredditStylesheet.test_attrs"): + contents = stylesheet.contents + assert contents == stylesheet.stylesheet + def test_delete_banner(self): self.reddit.read_only = False with self.recorder.use_cassette("TestSubredditStylesheet.test_delete_banner"):