Skip to content

Commit

Permalink
Merge e110661 into d1280b1
Browse files Browse the repository at this point in the history
  • Loading branch information
jsk56143 committed Jan 21, 2022
2 parents d1280b1 + e110661 commit 03f17e9
Show file tree
Hide file tree
Showing 16 changed files with 1,977 additions and 526 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -11,6 +11,8 @@ Unreleased
- :meth:`.pin` to manage pinned submissions on the authenticated user's profile.
- :meth:`.update_display_layout` to update the display layout of posts in a
:class:`.Collection`.
- :meth:`.SubredditCollectionsModeration.create` keyword argument ``display_layout`` for
specifying a display layout when creating a :class:`.Collection`.

**Changed**

Expand Down
29 changes: 23 additions & 6 deletions praw/models/reddit/collections.py
Expand Up @@ -441,14 +441,19 @@ def __init__(
super().__init__(reddit, _data)
self.subreddit_fullname = sub_fullname

def create(self, title: str, description: str):
def create(
self, title: str, description: str, display_layout: Optional[str] = None
):
"""Create a new :class:`.Collection`.
The authenticated account must have appropriate moderator permissions in the
subreddit this collection belongs to.
:param title: The title of the collection, up to 300 characters.
:param description: The description, up to 500 characters.
:param display_layout: Either ``"TIMELINE"`` for events or discussions or
``"GALLERY"`` for images or memes. ``None`` will make the collection appear
on Reddit as if this is set to ``"TIMELINE"`` (default:``None``).
:returns: The newly created :class:`.Collection`.
Expand All @@ -460,18 +465,30 @@ def create(self, title: str, description: str):
new_collection = my_sub.collections.mod.create("Title", "desc")
new_collection.mod.add_post("bgibu9")
Example usage (specifying display_layout):
.. code-block:: python
my_sub = reddit.subreddit("test")
new_collection = my_sub.collections.mod.create("Title", "desc", "GALLERY")
new_collection.mod.add_post("cmdfe8")
.. seealso::
:meth:`~.CollectionModeration.delete`
"""
API_PATH["collection_create"],
data = {
"sr_fullname": self.subreddit_fullname,
"title": title,
"description": description,
}
if display_layout:
data["display_layout"] = display_layout
return self._reddit.post(
API_PATH["collection_create"],
data={
"sr_fullname": self.subreddit_fullname,
"title": title,
"description": description,
},
data=data,
)


Expand Down
155 changes: 64 additions & 91 deletions tests/integration/cassettes/TestCollectionModeration.test_delete.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

@@ -0,0 +1,325 @@
{
"http_interactions": [
{
"recorded_at": "2021-12-28T20:56:38",
"request": {
"body": {
"encoding": "utf-8",
"string": "grant_type=password&password=<PASSWORD>&username=<TEST_SUBREDDIT>_bot"
},
"headers": {
"Accept": [
"*/*"
],
"Accept-Encoding": [
"identity"
],
"Authorization": [
"Basic <BASIC_AUTH>"
],
"Connection": [
"close"
],
"Content-Length": [
"65"
],
"Content-Type": [
"application/x-www-form-urlencoded"
],
"User-Agent": [
"<USER_AGENT> PRAW/7.5.1.dev0 prawcore/2.3.0"
]
},
"method": "POST",
"uri": "https://www.reddit.com/api/v1/access_token"
},
"response": {
"body": {
"encoding": "UTF-8",
"string": "{\"access_token\": \"<ACCESS_TOKEN>\", \"token_type\": \"bearer\", \"expires_in\": 3600, \"scope\": \"*\"}"
},
"headers": {
"Accept-Ranges": [
"bytes"
],
"Connection": [
"close"
],
"Content-Length": [
"121"
],
"Content-Type": [
"application/json; charset=UTF-8"
],
"Date": [
"Tue, 28 Dec 2021 20:56:38 GMT"
],
"Server": [
"snooserv"
],
"Set-Cookie": [
"edgebucket=T1Z0b5AN9LTMtk7woS; Domain=reddit.com; Max-Age=63071999; Path=/; secure"
],
"Strict-Transport-Security": [
"max-age=15552000; includeSubDomains; preload"
],
"Via": [
"1.1 varnish"
],
"X-Clacks-Overhead": [
"GNU Terry Pratchett"
],
"X-Moose": [
"majestic"
],
"cache-control": [
"max-age=0, must-revalidate"
],
"x-content-type-options": [
"nosniff"
],
"x-frame-options": [
"SAMEORIGIN"
],
"x-ratelimit-remaining": [
"296"
],
"x-ratelimit-reset": [
"202"
],
"x-ratelimit-used": [
"4"
],
"x-xss-protection": [
"1; mode=block"
]
},
"status": {
"code": 200,
"message": "OK"
},
"url": "https://www.reddit.com/api/v1/access_token"
}
},
{
"recorded_at": "2021-12-28T20:56:38",
"request": {
"body": {
"encoding": "utf-8",
"string": ""
},
"headers": {
"Accept": [
"*/*"
],
"Accept-Encoding": [
"identity"
],
"Authorization": [
"bearer <ACCESS_TOKEN>"
],
"Connection": [
"keep-alive"
],
"Cookie": [
"edgebucket=T1Z0b5AN9LTMtk7woS"
],
"User-Agent": [
"<USER_AGENT> PRAW/7.5.1.dev0 prawcore/2.3.0"
]
},
"method": "GET",
"uri": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/about/?raw_json=1"
},
"response": {
"body": {
"encoding": "UTF-8",
"string": "{\"kind\": \"t5\", \"data\": {\"user_flair_background_color\": null, \"submit_text_html\": null, \"restrict_posting\": true, \"user_is_banned\": false, \"free_form_reports\": true, \"wiki_enabled\": true, \"user_is_muted\": false, \"user_can_flair_in_sr\": true, \"display_name\": \"<TEST_SUBREDDIT>\", \"header_img\": null, \"title\": \"<TEST_SUBREDDIT>\", \"allow_galleries\": true, \"icon_size\": null, \"primary_color\": \"\", \"active_user_count\": 1, \"icon_img\": \"\", \"display_name_prefixed\": \"r/<TEST_SUBREDDIT>\", \"accounts_active\": 1, \"public_traffic\": false, \"subscribers\": 2, \"user_flair_richtext\": [], \"name\": \"t5_4bj4y6\", \"quarantine\": false, \"hide_ads\": false, \"prediction_leaderboard_entry_type\": \"IN_FEED\", \"emojis_enabled\": false, \"advertiser_category\": \"\", \"public_description\": \"test server\", \"comment_score_hide_mins\": 0, \"allow_predictions\": false, \"user_has_favorited\": false, \"user_flair_template_id\": null, \"community_icon\": \"\", \"banner_background_image\": \"\", \"original_content_tag_enabled\": false, \"community_reviewed\": false, \"submit_text\": \"\", \"description_html\": \"\\u003C!-- SC_OFF --\\u003E\\u003Cdiv class=\\\"md\\\"\\u003E\\u003Cp\\u003Enothing happening here\\u003C/p\\u003E\\n\\u003C/div\\u003E\\u003C!-- SC_ON --\\u003E\", \"spoilers_enabled\": true, \"header_title\": \"\", \"header_size\": null, \"user_flair_position\": \"right\", \"all_original_content\": false, \"collections_enabled\": true, \"is_enrolled_in_new_modmail\": true, \"key_color\": \"\", \"event_posts_enabled\": true, \"can_assign_user_flair\": true, \"created\": 1619538895.0, \"wls\": null, \"show_media_preview\": true, \"submission_type\": \"any\", \"user_is_subscriber\": true, \"disable_contributor_requests\": false, \"allow_videogifs\": true, \"should_archive_posts\": false, \"user_flair_type\": \"text\", \"allow_polls\": true, \"collapse_deleted_comments\": false, \"coins\": 0, \"emojis_custom_size\": null, \"public_description_html\": \"\\u003C!-- SC_OFF --\\u003E\\u003Cdiv class=\\\"md\\\"\\u003E\\u003Cp\\u003Etest server\\u003C/p\\u003E\\n\\u003C/div\\u003E\\u003C!-- SC_ON --\\u003E\", \"allow_videos\": false, \"is_crosspostable_subreddit\": true, \"notification_level\": \"low\", \"can_assign_link_flair\": true, \"has_menu_widget\": false, \"accounts_active_is_fuzzed\": false, \"allow_prediction_contributors\": false, \"submit_text_label\": \"\", \"link_flair_position\": \"left\", \"user_sr_flair_enabled\": true, \"user_flair_enabled_in_sr\": true, \"allow_chat_post_creation\": true, \"allow_discovery\": true, \"accept_followers\": true, \"user_sr_theme_enabled\": true, \"link_flair_enabled\": true, \"subreddit_type\": \"private\", \"suggested_comment_sort\": null, \"banner_img\": \"\", \"user_flair_text\": null, \"banner_background_color\": \"\", \"show_media\": true, \"id\": \"4bj4y6\", \"user_is_moderator\": true, \"over18\": false, \"description\": \"nothing happening here\", \"is_chat_post_feature_enabled\": true, \"submit_link_label\": \"\", \"user_flair_text_color\": null, \"restrict_commenting\": true, \"user_flair_css_class\": null, \"allow_images\": true, \"lang\": \"en\", \"whitelist_status\": null, \"url\": \"/r/<TEST_SUBREDDIT>/\", \"created_utc\": 1619538895.0, \"banner_size\": null, \"mobile_banner_image\": \"\", \"user_is_contributor\": true, \"allow_predictions_tournament\": false}}"
},
"headers": {
"Accept-Ranges": [
"bytes"
],
"Connection": [
"keep-alive"
],
"Content-Length": [
"3067"
],
"Content-Type": [
"application/json; charset=UTF-8"
],
"Date": [
"Tue, 28 Dec 2021 20:56:38 GMT"
],
"Server": [
"snooserv"
],
"Set-Cookie": [
"loid=0000000000c065m068.2.1620446985356.Z0FBQUFBQmh5M29HWVBhNTl4OVcyX2JuNlJyLTU2V0NqVklkMXVVYjIyRHktMzRRVzMtVU5JZ0hOWl9xZkRVbmVRMTI5bVUzMUl5UmI4dWdXdXNLUjY3THNpZkRYMTAybGFEZkVxMzZLdXR1emhDR1J1UHhuN3BKZnFBLXZwOElZWnBNbXJ5MFlaVUE; Domain=reddit.com; Max-Age=63071999; Path=/; expires=Thu, 28-Dec-2023 20:56:38 GMT; secure; SameSite=None; Secure",
"session_tracker=kmbljlajahfaohbhgr.0.1640724998902.Z0FBQUFBQmh5M29HLVlTOVVTLXJMZUZlYnZEUTNiNmZCdGVGSGllRUdIcF9tTV9taGhRVU9OdEVicVZ0YzRUX044SjBUdTM2WjBDMEFxU2VZWmJCcjlYYURTRXF2UkcxYWFHRUw5bVBJaWFnUzJtYWRNMThxT2MxYnNfenMyMDk5emJQckFzY1lHcEs; Domain=reddit.com; Max-Age=7199; Path=/; expires=Tue, 28-Dec-2021 22:56:38 GMT; secure; SameSite=None; Secure",
"csv=2; Max-Age=63072000; Domain=.reddit.com; Path=/; Secure; SameSite=None"
],
"Strict-Transport-Security": [
"max-age=15552000; includeSubDomains; preload"
],
"Vary": [
"accept-encoding"
],
"Via": [
"1.1 varnish"
],
"X-Clacks-Overhead": [
"GNU Terry Pratchett"
],
"X-Moose": [
"majestic"
],
"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": [
"595.0"
],
"x-ratelimit-reset": [
"202"
],
"x-ratelimit-used": [
"5"
],
"x-ua-compatible": [
"IE=edge"
],
"x-xss-protection": [
"1; mode=block"
]
},
"status": {
"code": 200,
"message": "OK"
},
"url": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/about/?raw_json=1"
}
},
{
"recorded_at": "2021-12-28T20:56:39",
"request": {
"body": {
"encoding": "utf-8",
"string": "api_type=json&description=The+description.&display_layout=&sr_fullname=t5_4bj4y6&title=The+title%21"
},
"headers": {
"Accept": [
"*/*"
],
"Accept-Encoding": [
"identity"
],
"Authorization": [
"bearer <ACCESS_TOKEN>"
],
"Connection": [
"keep-alive"
],
"Content-Length": [
"99"
],
"Content-Type": [
"application/x-www-form-urlencoded"
],
"Cookie": [
"csv=2; edgebucket=T1Z0b5AN9LTMtk7woS; loid=0000000000c065m068.2.1620446985356.Z0FBQUFBQmh5M29HWVBhNTl4OVcyX2JuNlJyLTU2V0NqVklkMXVVYjIyRHktMzRRVzMtVU5JZ0hOWl9xZkRVbmVRMTI5bVUzMUl5UmI4dWdXdXNLUjY3THNpZkRYMTAybGFEZkVxMzZLdXR1emhDR1J1UHhuN3BKZnFBLXZwOElZWnBNbXJ5MFlaVUE; session_tracker=kmbljlajahfaohbhgr.0.1640724998902.Z0FBQUFBQmh5M29HLVlTOVVTLXJMZUZlYnZEUTNiNmZCdGVGSGllRUdIcF9tTV9taGhRVU9OdEVicVZ0YzRUX044SjBUdTM2WjBDMEFxU2VZWmJCcjlYYURTRXF2UkcxYWFHRUw5bVBJaWFnUzJtYWRNMThxT2MxYnNfenMyMDk5emJQckFzY1lHcEs"
],
"User-Agent": [
"<USER_AGENT> PRAW/7.5.1.dev0 prawcore/2.3.0"
]
},
"method": "POST",
"uri": "https://oauth.reddit.com/api/v1/collections/create_collection?raw_json=1"
},
"response": {
"body": {
"encoding": "UTF-8",
"string": "{\"subreddit_id\": \"t5_4bj4y6\", \"description\": \"The description.\", \"author_name\": \"<TEST_SUBREDDIT>_bot\", \"collection_id\": \"93848bd5-1504-4603-a0b9-385dd1e7c890\", \"display_layout\": null, \"permalink\": \"https://www.reddit.com/r/<TEST_SUBREDDIT>/collection/93848bd5-1504-4603-a0b9-385dd1e7c890\", \"link_ids\": [], \"title\": \"The title!\", \"created_at_utc\": 1640724999.03, \"author_id\": \"t2_c065m068\", \"last_update_utc\": 1640724999.03}"
},
"headers": {
"Accept-Ranges": [
"bytes"
],
"Connection": [
"keep-alive"
],
"Content-Length": [
"406"
],
"Content-Type": [
"application/json; charset=UTF-8"
],
"Date": [
"Tue, 28 Dec 2021 20:56:39 GMT"
],
"Server": [
"snooserv"
],
"Strict-Transport-Security": [
"max-age=15552000; includeSubDomains; preload"
],
"Via": [
"1.1 varnish"
],
"X-Clacks-Overhead": [
"GNU Terry Pratchett"
],
"X-Moose": [
"majestic"
],
"cache-control": [
"private, s-maxage=0, max-age=0, must-revalidate, no-store, max-age=0, must-revalidate"
],
"expires": [
"-1"
],
"set-cookie": [
"session_tracker=kmbljlajahfaohbhgr.0.1640724999013.Z0FBQUFBQmh5M29INFBDUElSNG8wUnZMUHBvZFJpWS1ZMnhJdktjblF2X2piN0gtcmRfMGxrLWFtN1lYVHFrUVY3cDA2cFJvTjlqZW9CV0VMX2wtdi11aGFhYkdmdWF6NGNhZmVkTDhReG5mV3hrSFZ5eXBraldnNWxvTlpuWkRBTFM5RDIxTGV6N2Y; Domain=reddit.com; Max-Age=7199; Path=/; expires=Tue, 28-Dec-2021 22:56:39 GMT; secure"
],
"x-content-type-options": [
"nosniff"
],
"x-frame-options": [
"SAMEORIGIN"
],
"x-ratelimit-remaining": [
"594.0"
],
"x-ratelimit-reset": [
"201"
],
"x-ratelimit-used": [
"6"
],
"x-ua-compatible": [
"IE=edge"
],
"x-xss-protection": [
"1; mode=block"
]
},
"status": {
"code": 200,
"message": "OK"
},
"url": "https://oauth.reddit.com/api/v1/collections/create_collection?raw_json=1"
}
}
],
"recorded_with": "betamax/0.8.1"
}

0 comments on commit 03f17e9

Please sign in to comment.