Skip to content

Commit

Permalink
Sort praw.models.reddit.subreddit.SubredditFlairTemplates.update argu…
Browse files Browse the repository at this point in the history
…ments
  • Loading branch information
LilSpazJoekp committed Jan 12, 2022
1 parent f24502a commit 3707521
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 36 deletions.
57 changes: 36 additions & 21 deletions praw/models/reddit/subreddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1966,53 +1966,68 @@ 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})

@_deprecate_args(
"template_id",
"text",
"css_class",
"text_editable",
"background_color",
"text_color",
"mod_only",
"allowable_content",
"max_emojis",
"fetch",
)
def update(
self,
template_id: str,
text: Optional[str] = None,
css_class: Optional[str] = None,
text_editable: Optional[bool] = None,
background_color: Optional[str] = None,
text_color: Optional[str] = None,
mod_only: Optional[bool] = None,
*,
allowable_content: Optional[str] = None,
max_emojis: Optional[int] = None,
background_color: Optional[str] = None,
css_class: Optional[str] = None,
fetch: bool = True,
max_emojis: Optional[int] = None,
mod_only: Optional[bool] = None,
text: Optional[str] = None,
text_color: Optional[str] = None,
text_editable: Optional[bool] = None,
):
"""Update the flair template provided by ``template_id``.
:param template_id: The flair template to update. If not valid then an exception
will be thrown.
:param text: The flair template's new text.
:param css_class: The flair template's new css_class (default: ``""``).
:param text_editable: Indicate if the flair text can be modified for each
:class:`.Redditor` that sets it (default: ``False``).
:param background_color: The flair template's new background color, as a hex
color.
:param text_color: The flair template's new text color, either ``"light"`` or
``"dark"``.
:param mod_only: Indicate if the flair can only be used by moderators.
:param allowable_content: If specified, most be one of ``"all"``, ``"emoji"``,
or ``"text"`` to restrict content to that type. If set to ``"emoji"`` then
the ``"text"`` param must be a valid emoji string, for example,
``":snoo:"``.
:param background_color: The flair template's new background color, as a hex
color.
:param css_class: The flair template's new css_class (default: ``""``).
:param fetch: Whether PRAW will fetch existing information on the existing flair
before updating (default: ``True``).
:param max_emojis: Maximum emojis in the flair (Reddit defaults this value to
``10``).
:param fetch: Whether or not PRAW will fetch existing information on the
existing flair before updating (default: ``True``).
:param mod_only: Indicate if the flair can only be used by moderators.
:param text: The flair template's new text.
:param text_color: The flair template's new text color, either ``"light"`` or
``"dark"``.
:param text_editable: Indicate if the flair text can be modified for each
redditor that sets it (default: ``False``).
.. warning::
If parameter ``fetch`` is set to ``False``, all parameters not provided will
be reset to default (``None`` or ``False``) values.
be reset to their default (``None`` or ``False``) values.
For example, to make a user flair template text_editable, try:
For example, to make a user flair template text editable, try:
.. code-block:: python
template_info = list(subreddit.flair.templates)[0]
subreddit.flair.templates.update(
template_info["id"], template_info["flair_text"], text_editable=True
template_info["id"],
text=template_info["flair_text"],
text_editable=True,
)
"""
Expand Down
30 changes: 15 additions & 15 deletions tests/integration/models/reddit/test_subreddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1156,10 +1156,10 @@ def test_update(self, _):
template = list(self.subreddit.flair.templates)[0]
self.subreddit.flair.templates.update(
template["id"],
"PRAW updated",
background_color="#00FFFF",
css_class="myCSS",
text="PRAW updated",
text_color="dark",
background_color="#00FFFF",
)

@mock.patch("time.sleep", return_value=None)
Expand All @@ -1169,11 +1169,11 @@ def test_update_invalid(self, _):
with pytest.raises(InvalidFlairTemplateID):
self.subreddit.flair.templates.update(
"fake id",
"PRAW updated",
css_class="myCSS",
text_color="dark",
background_color="#00FFFF",
css_class="myCSS",
fetch=True,
text="PRAW updated",
text_color="dark",
)

@mock.patch("time.sleep", return_value=None)
Expand All @@ -1183,11 +1183,11 @@ def test_update_fetch(self, _):
template = list(self.subreddit.flair.templates)[0]
self.subreddit.flair.templates.update(
template["id"],
"PRAW updated",
css_class="myCSS",
text_color="dark",
background_color="#00FFFF",
css_class="myCSS",
fetch=True,
text="PRAW updated",
text_color="dark",
)

@mock.patch("time.sleep", return_value=None)
Expand All @@ -1197,10 +1197,10 @@ def test_update_fetch_no_css_class(self, _):
template = list(self.subreddit.flair.templates)[0]
self.subreddit.flair.templates.update(
template["id"],
"PRAW updated",
text_color="dark",
background_color="#00FFFF",
fetch=True,
text="PRAW updated",
text_color="dark",
)

@mock.patch("time.sleep", return_value=None)
Expand All @@ -1210,10 +1210,10 @@ def test_update_fetch_no_text(self, _):
template = list(self.subreddit.flair.templates)[0]
self.subreddit.flair.templates.update(
template["id"],
css_class="myCSS",
text_color="dark",
background_color="#00FFFF",
css_class="myCSS",
fetch=True,
text_color="dark",
)

@mock.patch("time.sleep", return_value=None)
Expand All @@ -1223,9 +1223,9 @@ def test_update_fetch_no_text_or_css_class(self, _):
template = list(self.subreddit.flair.templates)[0]
self.subreddit.flair.templates.update(
template["id"],
text_color="dark",
background_color="#00FFFF",
fetch=True,
text_color="dark",
)

@mock.patch("time.sleep", return_value=None)
Expand All @@ -1248,10 +1248,10 @@ def test_update_false(self, _):
with self.use_cassette():
template = list(self.subreddit.flair.templates)[0]
self.subreddit.flair.templates.update(
template["id"], text_editable=True, fetch=True
template["id"], fetch=True, text_editable=True
)
self.subreddit.flair.templates.update(
template["id"], text_editable=False, fetch=True
template["id"], fetch=True, text_editable=False
)
newtemplate = list(
filter(
Expand Down

0 comments on commit 3707521

Please sign in to comment.