Skip to content

Commit

Permalink
Sort praw.models.reddit.subreddit.SubredditStylesheet.upload arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
LilSpazJoekp committed Jan 12, 2022
1 parent fe36ff4 commit 22cef1e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 4 additions & 3 deletions praw/models/reddit/subreddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3847,12 +3847,13 @@ def update(self, stylesheet: str, *, reason: Optional[str] = None):
url = API_PATH["subreddit_stylesheet"].format(subreddit=self.subreddit)
self.subreddit._reddit.post(url, data=data)

def upload(self, name: str, image_path: str) -> Dict[str, str]:
@_deprecate_args("name", "image_path")
def upload(self, *, image_path: str, name: str) -> Dict[str, str]:
"""Upload an image to the :class:`.Subreddit`.
:param image_path: A path to a jpeg or png image.
:param name: The name to use for the image. If an image already exists with the
same name, it will be replaced.
:param image_path: A path to a jpeg or png image.
:returns: A dictionary containing a link to the uploaded image under the key
``img_src``.
Expand All @@ -3868,7 +3869,7 @@ def upload(self, name: str, image_path: str) -> Dict[str, str]:
.. code-block:: python
reddit.subreddit("test").stylesheet.upload("smile", "img.png")
reddit.subreddit("test").stylesheet.upload(name="smile", image_path="img.png")
"""
return self._upload_image(image_path, {"name": name, "upload_type": "img"})
Expand Down
10 changes: 6 additions & 4 deletions tests/integration/models/reddit/test_subreddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2005,23 +2005,25 @@ def test_upload(self):
self.reddit.read_only = False
with self.use_cassette():
response = self.subreddit.stylesheet.upload(
"praw", self.image_path("white-square.png")
name="praw", image_path=self.image_path("white-square.png")
)
assert response["img_src"].endswith(".png")

def test_upload__invalid(self):
self.reddit.read_only = False
with self.use_cassette():
with pytest.raises(RedditAPIException) as excinfo:
self.subreddit.stylesheet.upload("praw", self.image_path("invalid.jpg"))
self.subreddit.stylesheet.upload(
name="praw", image_path=self.image_path("invalid.jpg")
)
assert excinfo.value.items[0].error_type == "IMAGE_ERROR"

def test_upload__invalid_ext(self):
self.reddit.read_only = False
with self.use_cassette():
with pytest.raises(RedditAPIException) as excinfo:
self.subreddit.stylesheet.upload(
"praw.png", self.image_path("white-square.png")
name="praw.png", image_path=self.image_path("white-square.png")
)
assert excinfo.value.items[0].error_type == "BAD_CSS_NAME"

Expand All @@ -2030,7 +2032,7 @@ def test_upload__too_large(self):
with self.use_cassette():
with pytest.raises(TooLarge):
self.subreddit.stylesheet.upload(
"praw", self.image_path("too_large.jpg")
name="praw", image_path=self.image_path("too_large.jpg")
)

@mock.patch("time.sleep", return_value=None)
Expand Down

0 comments on commit 22cef1e

Please sign in to comment.