Skip to content

Commit 0654440

Browse files
authored
Merge pull request #116 from MaybeNetwork/accept-202
Support 202 HTTP responses
2 parents 4e582b2 + c185be7 commit 0654440

4 files changed

Lines changed: 231 additions & 1 deletion

File tree

CHANGES.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ Change Log
33

44
prawcore follows `semantic versioning <http://semver.org/>`_.
55

6+
Unreleased
7+
----------
8+
9+
**Added**
10+
11+
- Support 202 "Accepted" HTTP responses.
12+
613
2.1.0 (2021-06-07)
714
------------------
815

prawcore/sessions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class Session(object):
111111
520: ServerError,
112112
522: ServerError,
113113
}
114-
SUCCESS_STATUSES = {codes["created"], codes["ok"]}
114+
SUCCESS_STATUSES = {codes["accepted"], codes["created"], codes["ok"]}
115115

116116
@staticmethod
117117
def _log_request(data, method, params, url):
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
{
2+
"http_interactions": [
3+
{
4+
"recorded_at": "2021-06-09T23:00:18",
5+
"request": {
6+
"body": {
7+
"encoding": "utf-8",
8+
"string": "grant_type=password&password=<PASSWORD>&username=<USERNAME>"
9+
},
10+
"headers": {
11+
"Accept": [
12+
"*/*"
13+
],
14+
"Accept-Encoding": [
15+
"gzip, deflate"
16+
],
17+
"Authorization": [
18+
"Basic <BASIC_AUTH>"
19+
],
20+
"Connection": [
21+
"close"
22+
],
23+
"Content-Length": [
24+
"152"
25+
],
26+
"Content-Type": [
27+
"application/x-www-form-urlencoded"
28+
],
29+
"User-Agent": [
30+
"prawcore:test (by /u/bboe) prawcore/2.1.0"
31+
]
32+
},
33+
"method": "POST",
34+
"uri": "https://www.reddit.com/api/v1/access_token"
35+
},
36+
"response": {
37+
"body": {
38+
"encoding": "UTF-8",
39+
"string": "{\"access_token\": \"00000000-000000000000000000000000000000\", \"token_type\": \"bearer\", \"expires_in\": 3600, \"scope\": \"*\"}"
40+
},
41+
"headers": {
42+
"Accept-Ranges": [
43+
"bytes"
44+
],
45+
"Connection": [
46+
"close"
47+
],
48+
"Content-Length": [
49+
"117"
50+
],
51+
"Content-Type": [
52+
"application/json; charset=UTF-8"
53+
],
54+
"Date": [
55+
"Wed, 09 Jun 2021 23:00:17 GMT"
56+
],
57+
"Server": [
58+
"snooserv"
59+
],
60+
"Set-Cookie": [
61+
"edgebucket=KLG8DuWl7lo6rq6Dzq; Domain=reddit.com; Max-Age=63071999; Path=/; secure"
62+
],
63+
"Strict-Transport-Security": [
64+
"max-age=15552000; includeSubDomains; preload"
65+
],
66+
"Via": [
67+
"1.1 varnish"
68+
],
69+
"X-Clacks-Overhead": [
70+
"GNU Terry Pratchett"
71+
],
72+
"X-Moose": [
73+
"majestic"
74+
],
75+
"cache-control": [
76+
"max-age=0, must-revalidate"
77+
],
78+
"x-content-type-options": [
79+
"nosniff"
80+
],
81+
"x-frame-options": [
82+
"SAMEORIGIN"
83+
],
84+
"x-ratelimit-remaining": [
85+
"299"
86+
],
87+
"x-ratelimit-reset": [
88+
"583"
89+
],
90+
"x-ratelimit-used": [
91+
"1"
92+
],
93+
"x-xss-protection": [
94+
"1; mode=block"
95+
]
96+
},
97+
"status": {
98+
"code": 200,
99+
"message": "OK"
100+
},
101+
"url": "https://www.reddit.com/api/v1/access_token"
102+
}
103+
},
104+
{
105+
"recorded_at": "2021-06-09T23:00:18",
106+
"request": {
107+
"body": {
108+
"encoding": "utf-8",
109+
"string": ""
110+
},
111+
"headers": {
112+
"Accept": [
113+
"*/*"
114+
],
115+
"Accept-Encoding": [
116+
"gzip, deflate"
117+
],
118+
"Authorization": [
119+
"bearer 00000000-000000000000000000000000000000"
120+
],
121+
"Connection": [
122+
"keep-alive"
123+
],
124+
"Content-Length": [
125+
"0"
126+
],
127+
"Cookie": [
128+
"edgebucket=KLG8DuWl7lo6rq6Dzq"
129+
],
130+
"User-Agent": [
131+
"prawcore:test (by /u/bboe) prawcore/2.1.0"
132+
]
133+
},
134+
"method": "POST",
135+
"uri": "https://oauth.reddit.com/api/read_all_messages?raw_json=1"
136+
},
137+
"response": {
138+
"body": {
139+
"encoding": "UTF-8",
140+
"string": "{}"
141+
},
142+
"headers": {
143+
"Accept-Ranges": [
144+
"bytes"
145+
],
146+
"Connection": [
147+
"keep-alive"
148+
],
149+
"Content-Length": [
150+
"2"
151+
],
152+
"Content-Type": [
153+
"application/json; charset=UTF-8"
154+
],
155+
"Date": [
156+
"Wed, 09 Jun 2021 23:00:18 GMT"
157+
],
158+
"Server": [
159+
"snooserv"
160+
],
161+
"Strict-Transport-Security": [
162+
"max-age=15552000; includeSubDomains; preload"
163+
],
164+
"Via": [
165+
"1.1 varnish"
166+
],
167+
"X-Clacks-Overhead": [
168+
"GNU Terry Pratchett"
169+
],
170+
"X-Moose": [
171+
"majestic"
172+
],
173+
"cache-control": [
174+
"private, s-maxage=0, max-age=0, must-revalidate, no-store, max-age=0, must-revalidate"
175+
],
176+
"expires": [
177+
"-1"
178+
],
179+
"set-cookie": [
180+
"redesign_optout=true; Domain=reddit.com; Max-Age=94607999; Path=/; expires=Sat, 08-Jun-2024 23:00:18 GMT; secure",
181+
"session_tracker=6GEhiIYy1IKboYp6F8.0.1623279618070.Z0FBQUFBQmd3VWdDcW5WVsk0UE5Dc2JJME1QaG5ncDdfTDgtOTRtWWxxLXJmWWFsS0NaaWdrvzRkQmJnbEhIUkYzcm9FNGlHN1p6N3ZoODM3cTliWDRseFNwTDBYSHNdWE15Wkhvc1VCVW1zUU81cVFmYy1wbW5tRG9aUkU4Q1FlQTBTemdRSTA2Y0s; Domain=reddit.com; Max-Age=7199; Path=/; expires=Thu, 10-Jun-2021 01:00:18 GMT; secure"
182+
],
183+
"x-content-type-options": [
184+
"nosniff"
185+
],
186+
"x-frame-options": [
187+
"SAMEORIGIN"
188+
],
189+
"x-ratelimit-remaining": [
190+
"599.0"
191+
],
192+
"x-ratelimit-reset": [
193+
"582"
194+
],
195+
"x-ratelimit-used": [
196+
"1"
197+
],
198+
"x-ua-compatible": [
199+
"IE=edge"
200+
],
201+
"x-xss-protection": [
202+
"1; mode=block"
203+
]
204+
},
205+
"status": {
206+
"code": 202,
207+
"message": "Accepted"
208+
},
209+
"url": "https://oauth.reddit.com/api/read_all_messages?raw_json=1"
210+
}
211+
}
212+
],
213+
"recorded_with": "betamax/0.8.1"
214+
}

tests/test_sessions.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ def test_init__with_implicit_authorizer(self):
8989
authorizer = prawcore.ImplicitAuthorizer(authenticator, None, 0, "")
9090
prawcore.Session(authorizer)
9191

92+
def test_request__accepted(self):
93+
with Betamax(REQUESTOR).use_cassette("Session_request__accepted"):
94+
session = prawcore.Session(script_authorizer())
95+
with LogCapture(level=logging.DEBUG) as log_capture:
96+
session.request("POST", "api/read_all_messages")
97+
log_capture.check_present(
98+
("prawcore", "DEBUG", "Response: 202 (2 bytes)")
99+
)
100+
92101
@patch("requests.Session")
93102
def test_request__chunked_encoding_retry(self, mock_session):
94103
session_instance = mock_session.return_value

0 commit comments

Comments
 (0)