Merge lp:~zyga/launchpadlib/fix-1471894 into lp:launchpadlib

Proposed by Zygmunt Krynicki
Status: Merged
Merged at revision: 141
Proposed branch: lp:~zyga/launchpadlib/fix-1471894
Merge into: lp:launchpadlib
Diff against target: 115 lines (+15/-15)
2 files modified
src/launchpadlib/launchpad.py (+3/-3)
src/launchpadlib/tests/test_http.py (+12/-12)
To merge this branch: bzr merge lp:~zyga/launchpadlib/fix-1471894
Reviewer Review Type Date Requested Status
Dimitri John Ledkov Approve
Colin Watson Approve
Review via email: mp+263950@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve
Revision history for this message
Dimitri John Ledkov (xnox) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/launchpadlib/launchpad.py'
--- src/launchpadlib/launchpad.py 2014-12-05 23:21:40 +0000
+++ src/launchpadlib/launchpad.py 2015-07-06 18:03:00 +0000
@@ -122,9 +122,9 @@
122 def _bad_oauth_token(self, response, content):122 def _bad_oauth_token(self, response, content):
123 """Helper method to detect an error caused by a bad OAuth token."""123 """Helper method to detect an error caused by a bad OAuth token."""
124 return (response.status == 401 and124 return (response.status == 401 and
125 (content.startswith("Expired token")125 (content.startswith(b"Expired token")
126 or content.startswith("Invalid token")126 or content.startswith(b"Invalid token")
127 or content.startswith("Unknown access token")))127 or content.startswith(b"Unknown access token")))
128128
129 def _request(self, *args):129 def _request(self, *args):
130 response, content = super(130 response, content = super(
131131
=== modified file 'src/launchpadlib/tests/test_http.py'
--- src/launchpadlib/tests/test_http.py 2014-07-04 16:26:26 +0000
+++ src/launchpadlib/tests/test_http.py 2015-07-06 18:03:00 +0000
@@ -39,7 +39,7 @@
3939
4040
41# The simplest WADL that looks like a representation of the service root.41# The simplest WADL that looks like a representation of the service root.
42SIMPLE_WADL = '''<?xml version="1.0"?>42SIMPLE_WADL = b'''<?xml version="1.0"?>
43<application xmlns="http://research.sun.com/wadl/2006/10">43<application xmlns="http://research.sun.com/wadl/2006/10">
44 <resources base="http://www.example.com/">44 <resources base="http://www.example.com/">
45 <resource path="" type="#service-root"/>45 <resource path="" type="#service-root"/>
@@ -58,7 +58,7 @@
58'''58'''
5959
60# The simplest JSON that looks like a representation of the service root.60# The simplest JSON that looks like a representation of the service root.
61SIMPLE_JSON = dumps({})61SIMPLE_JSON = b'{}'
6262
6363
64class Response:64class Response:
@@ -148,7 +148,7 @@
148 """Show that bad WADL causes an exception."""148 """Show that bad WADL causes an exception."""
149 self.assertRaises(149 self.assertRaises(
150 SyntaxError, self.launchpad_with_responses,150 SyntaxError, self.launchpad_with_responses,
151 Response(200, "This is not WADL."),151 Response(200, b"This is not WADL."),
152 Response(200, SIMPLE_JSON))152 Response(200, SIMPLE_JSON))
153153
154 def test_bad_json(self):154 def test_bad_json(self):
@@ -156,7 +156,7 @@
156 self.assertRaises(156 self.assertRaises(
157 JSONDecodeError, self.launchpad_with_responses,157 JSONDecodeError, self.launchpad_with_responses,
158 Response(200, SIMPLE_WADL),158 Response(200, SIMPLE_WADL),
159 Response(200, "This is not JSON."))159 Response(200, b"This is not JSON."))
160160
161161
162class TestTokenFailureDuringRequest(SimulatedResponsesTestCase):162class TestTokenFailureDuringRequest(SimulatedResponsesTestCase):
@@ -182,7 +182,7 @@
182 def test_bad_token(self):182 def test_bad_token(self):
183 """If our token is bad, we get another one."""183 """If our token is bad, we get another one."""
184 SimulatedResponsesLaunchpad.responses = [184 SimulatedResponsesLaunchpad.responses = [
185 Response(401, "Invalid token."),185 Response(401, b"Invalid token."),
186 Response(200, SIMPLE_WADL),186 Response(200, SIMPLE_WADL),
187 Response(200, SIMPLE_JSON)]187 Response(200, SIMPLE_JSON)]
188188
@@ -195,7 +195,7 @@
195 """If our token is expired, we get another one."""195 """If our token is expired, we get another one."""
196196
197 SimulatedResponsesLaunchpad.responses = [197 SimulatedResponsesLaunchpad.responses = [
198 Response(401, "Expired token."),198 Response(401, b"Expired token."),
199 Response(200, SIMPLE_WADL),199 Response(200, SIMPLE_WADL),
200 Response(200, SIMPLE_JSON)]200 Response(200, SIMPLE_JSON)]
201201
@@ -208,7 +208,7 @@
208 """If our token is unknown, we get another one."""208 """If our token is unknown, we get another one."""
209209
210 SimulatedResponsesLaunchpad.responses = [210 SimulatedResponsesLaunchpad.responses = [
211 Response(401, "Unknown access token."),211 Response(401, b"Unknown access token."),
212 Response(200, SIMPLE_WADL),212 Response(200, SIMPLE_WADL),
213 Response(200, SIMPLE_JSON)]213 Response(200, SIMPLE_JSON)]
214214
@@ -221,7 +221,7 @@
221 """We get another token no matter when the error happens."""221 """We get another token no matter when the error happens."""
222 SimulatedResponsesLaunchpad.responses = [222 SimulatedResponsesLaunchpad.responses = [
223 Response(200, SIMPLE_WADL),223 Response(200, SIMPLE_WADL),
224 Response(401, "Expired token."),224 Response(401, b"Expired token."),
225 Response(200, SIMPLE_JSON)]225 Response(200, SIMPLE_JSON)]
226226
227 self.assertEqual(self.engine.access_tokens_obtained, 0)227 self.assertEqual(self.engine.access_tokens_obtained, 0)
@@ -232,10 +232,10 @@
232 def test_many_errors(self):232 def test_many_errors(self):
233 """We'll keep getting new tokens as long as tokens are the problem."""233 """We'll keep getting new tokens as long as tokens are the problem."""
234 SimulatedResponsesLaunchpad.responses = [234 SimulatedResponsesLaunchpad.responses = [
235 Response(401, "Invalid token."),235 Response(401, b"Invalid token."),
236 Response(200, SIMPLE_WADL),236 Response(200, SIMPLE_WADL),
237 Response(401, "Expired token."),237 Response(401, b"Expired token."),
238 Response(401, "Invalid token."),238 Response(401, b"Invalid token."),
239 Response(200, SIMPLE_JSON)]239 Response(200, SIMPLE_JSON)]
240 self.assertEqual(self.engine.access_tokens_obtained, 0)240 self.assertEqual(self.engine.access_tokens_obtained, 0)
241 launchpad = SimulatedResponsesLaunchpad.login_with(241 launchpad = SimulatedResponsesLaunchpad.login_with(
@@ -246,7 +246,7 @@
246 """If the token is not at fault, a 401 error raises an exception."""246 """If the token is not at fault, a 401 error raises an exception."""
247247
248 SimulatedResponsesLaunchpad.responses = [248 SimulatedResponsesLaunchpad.responses = [
249 Response(401, "Some other error.")]249 Response(401, b"Some other error.")]
250250
251 self.assertRaises(251 self.assertRaises(
252 Unauthorized, SimulatedResponsesLaunchpad.login_with,252 Unauthorized, SimulatedResponsesLaunchpad.login_with,

Subscribers

People subscribed via source and target branches