Skip to content

Commit

Permalink
Add Submission lock and unlock.
Browse files Browse the repository at this point in the history
  • Loading branch information
bboe committed Aug 30, 2016
1 parent b51d12c commit a1338d4
Show file tree
Hide file tree
Showing 5 changed files with 229 additions and 1 deletion.
4 changes: 3 additions & 1 deletion praw/const.py
Expand Up @@ -52,6 +52,7 @@
'leavemoderator': 'api/leavemoderator',
'liveabout': 'api/live/{id}/about/',
'livecreate': 'api/live/create',
'lock': 'api/lock/',
'me': 'api/v1/me',
'mentions': 'message/mentions',
'message': 'message/messages/{messageid}/',
Expand Down Expand Up @@ -117,10 +118,11 @@
'uncollapse_message': 'api/uncollapse_message/',
'unfriend': 'api/unfriend/',
'unhide': 'api/unhide/',
'unignore_reports': 'api/unignore_reports/',
'unlock': 'api/unlock/',
'unmarknsfw': 'api/unmarknsfw/',
'unmoderated': 'r/{subreddit}/about/unmoderated/',
'unmute_sender': 'api/unmute_message_author/',
'unignore_reports': 'api/unignore_reports/',
'unread': 'message/unread/',
'unread_message': 'api/unread_message/',
'unsave': 'api/unsave/',
Expand Down
10 changes: 10 additions & 0 deletions praw/models/reddit/submission.py
Expand Up @@ -191,6 +191,11 @@ def contest_mode(self, state=True):
self.submission._reddit.post(API_PATH['contest_mode'], data={
'id': self.submission.fullname, 'state': state})

def lock(self):
"""Lock the submission."""
self.submission._reddit.post(API_PATH['lock'],
data={'id': self.submission.fullname})

def nsfw(self):
"""Mark as not safe for work."""
self.submission._reddit.post(API_PATH['marknsfw'],
Expand Down Expand Up @@ -230,4 +235,9 @@ def suggested_sort(self, sort='blank'):
self.submission._reddit.post(API_PATH['suggested_sort'], data={
'id': self.submission.fullname, 'sort': sort})

def unlock(self):
"""Lock the submission."""
self.submission._reddit.post(API_PATH['unlock'],
data={'id': self.submission.fullname})

Subreddit._submission_class = Submission
102 changes: 102 additions & 0 deletions tests/integration/cassettes/TestSubmissionModeration.test_lock.json
@@ -0,0 +1,102 @@
{
"http_interactions": [
{
"recorded_at": "2016-08-30T05:45:59",
"request": {
"body": {
"encoding": "utf-8",
"string": "grant_type=password&password=<PASSWORD>&username=<USERNAME>"
},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "identity",
"Authorization": "Basic <BASIC_AUTH>",
"Connection": "keep-alive",
"Content-Length": "57",
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": "<USER_AGENT> PRAW/4.0.0b16 prawcore/0.2.1"
},
"method": "POST",
"uri": "https://www.reddit.com/api/v1/access_token"
},
"response": {
"body": {
"encoding": "UTF-8",
"string": "{\"access_token\": \"OV-LN_O3Rmcno6jyEnWu1wGYuD0\", \"token_type\": \"bearer\", \"expires_in\": 3600, \"scope\": \"*\"}"
},
"headers": {
"CF-RAY": "2da5f08dd3e01ead-SJC",
"Connection": "keep-alive",
"Content-Length": "105",
"Content-Type": "application/json; charset=UTF-8",
"Date": "Tue, 30 Aug 2016 05:45:59 GMT",
"Server": "cloudflare-nginx",
"Set-Cookie": "__cfduid=dd9e008880a8356e61df7bc2666cbee3b1472535958; expires=Wed, 30-Aug-17 05:45:58 GMT; path=/; domain=.reddit.com; HttpOnly",
"Strict-Transport-Security": "max-age=15552000; includeSubDomains; preload",
"X-Moose": "majestic",
"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-08-30T05:45:59",
"request": {
"body": {
"encoding": "utf-8",
"string": "api_type=json&id=t3_4s2idz"
},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "identity",
"Authorization": "bearer OV-LN_O3Rmcno6jyEnWu1wGYuD0",
"Connection": "keep-alive",
"Content-Length": "26",
"Content-Type": "application/x-www-form-urlencoded",
"Cookie": "loid=qv0hSXXojfOvf1v7r7; loidcreated=2016-08-30T05%3A45%3A58.763Z; __cfduid=dd9e008880a8356e61df7bc2666cbee3b1472535958",
"User-Agent": "<USER_AGENT> PRAW/4.0.0b16 prawcore/0.2.1"
},
"method": "POST",
"uri": "https://oauth.reddit.com/api/lock/?raw_json=1"
},
"response": {
"body": {
"encoding": "UTF-8",
"string": "{}"
},
"headers": {
"CF-RAY": "2da5f091941a1ead-SJC",
"Connection": "keep-alive",
"Content-Length": "2",
"Content-Type": "application/json; charset=UTF-8",
"Date": "Tue, 30 Aug 2016 05:45:59 GMT",
"Server": "cloudflare-nginx",
"Strict-Transport-Security": "max-age=15552000; includeSubDomains; preload",
"X-Moose": "majestic",
"cache-control": "private, s-maxage=0, max-age=0, must-revalidate",
"expires": "-1",
"x-content-type-options": "nosniff",
"x-frame-options": "SAMEORIGIN",
"x-ratelimit-remaining": "599.0",
"x-ratelimit-reset": "241",
"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/api/lock/?raw_json=1"
}
}
],
"recorded_with": "betamax/0.7.2"
}
102 changes: 102 additions & 0 deletions tests/integration/cassettes/TestSubmissionModeration.test_unlock.json
@@ -0,0 +1,102 @@
{
"http_interactions": [
{
"recorded_at": "2016-08-30T05:46:17",
"request": {
"body": {
"encoding": "utf-8",
"string": "grant_type=password&password=<PASSWORD>&username=<USERNAME>"
},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "identity",
"Authorization": "Basic <BASIC_AUTH>",
"Connection": "keep-alive",
"Content-Length": "57",
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": "<USER_AGENT> PRAW/4.0.0b16 prawcore/0.2.1"
},
"method": "POST",
"uri": "https://www.reddit.com/api/v1/access_token"
},
"response": {
"body": {
"encoding": "UTF-8",
"string": "{\"access_token\": \"57eYQ3vZa4bQxFiYoQVypr1nKcE\", \"token_type\": \"bearer\", \"expires_in\": 3600, \"scope\": \"*\"}"
},
"headers": {
"CF-RAY": "2da5f0fd0c1d0da9-SJC",
"Connection": "keep-alive",
"Content-Length": "105",
"Content-Type": "application/json; charset=UTF-8",
"Date": "Tue, 30 Aug 2016 05:46:16 GMT",
"Server": "cloudflare-nginx",
"Set-Cookie": "__cfduid=df876a91fb8b4fad306457e0fe89e815e1472535976; expires=Wed, 30-Aug-17 05:46:16 GMT; path=/; domain=.reddit.com; HttpOnly",
"Strict-Transport-Security": "max-age=15552000; includeSubDomains; preload",
"X-Moose": "majestic",
"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-08-30T05:46:17",
"request": {
"body": {
"encoding": "utf-8",
"string": "api_type=json&id=t3_4s2idz"
},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "identity",
"Authorization": "bearer 57eYQ3vZa4bQxFiYoQVypr1nKcE",
"Connection": "keep-alive",
"Content-Length": "26",
"Content-Type": "application/x-www-form-urlencoded",
"Cookie": "__cfduid=df876a91fb8b4fad306457e0fe89e815e1472535976; loid=b2eG6z4Uk69eoPvwai; loidcreated=2016-08-30T05%3A46%3A16.527Z",
"User-Agent": "<USER_AGENT> PRAW/4.0.0b16 prawcore/0.2.1"
},
"method": "POST",
"uri": "https://oauth.reddit.com/api/unlock/?raw_json=1"
},
"response": {
"body": {
"encoding": "UTF-8",
"string": "{}"
},
"headers": {
"CF-RAY": "2da5f101b4ae2894-SJC",
"Connection": "keep-alive",
"Content-Length": "2",
"Content-Type": "application/json; charset=UTF-8",
"Date": "Tue, 30 Aug 2016 05:46:17 GMT",
"Server": "cloudflare-nginx",
"Strict-Transport-Security": "max-age=15552000; includeSubDomains; preload",
"X-Moose": "majestic",
"cache-control": "private, s-maxage=0, max-age=0, must-revalidate",
"expires": "-1",
"x-content-type-options": "nosniff",
"x-frame-options": "SAMEORIGIN",
"x-ratelimit-remaining": "598.0",
"x-ratelimit-reset": "223",
"x-ratelimit-used": "2",
"x-ua-compatible": "IE=edge",
"x-xss-protection": "1; mode=block"
},
"status": {
"code": 200,
"message": "OK"
},
"url": "https://oauth.reddit.com/api/unlock/?raw_json=1"
}
}
],
"recorded_with": "betamax/0.7.2"
}
12 changes: 12 additions & 0 deletions tests/integration/models/reddit/test_submission.py
Expand Up @@ -163,6 +163,12 @@ def test_nsfw(self):
'TestSubmissionModeration.test_nsfw'):
Submission(self.reddit, '4s2idz').mod.nsfw()

def test_lock(self):
self.reddit.read_only = False
with self.recorder.use_cassette(
'TestSubmissionModeration.test_lock'):
Submission(self.reddit, '4s2idz').mod.lock()

def test_sfw(self):
self.reddit.read_only = False
with self.recorder.use_cassette(
Expand Down Expand Up @@ -198,3 +204,9 @@ def test_suggested_sort__clear(self):
with self.recorder.use_cassette(
'TestSubmissionModeration.test_suggested_sort__clear'):
Submission(self.reddit, '4s2idz').mod.suggested_sort(sort='blank')

def test_unock(self):
self.reddit.read_only = False
with self.recorder.use_cassette(
'TestSubmissionModeration.test_unlock'):
Submission(self.reddit, '4s2idz').mod.unlock()

0 comments on commit a1338d4

Please sign in to comment.