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
1=== modified file 'src/launchpadlib/launchpad.py'
2--- src/launchpadlib/launchpad.py 2014-12-05 23:21:40 +0000
3+++ src/launchpadlib/launchpad.py 2015-07-06 18:03:00 +0000
4@@ -122,9 +122,9 @@
5 def _bad_oauth_token(self, response, content):
6 """Helper method to detect an error caused by a bad OAuth token."""
7 return (response.status == 401 and
8- (content.startswith("Expired token")
9- or content.startswith("Invalid token")
10- or content.startswith("Unknown access token")))
11+ (content.startswith(b"Expired token")
12+ or content.startswith(b"Invalid token")
13+ or content.startswith(b"Unknown access token")))
14
15 def _request(self, *args):
16 response, content = super(
17
18=== modified file 'src/launchpadlib/tests/test_http.py'
19--- src/launchpadlib/tests/test_http.py 2014-07-04 16:26:26 +0000
20+++ src/launchpadlib/tests/test_http.py 2015-07-06 18:03:00 +0000
21@@ -39,7 +39,7 @@
22
23
24 # The simplest WADL that looks like a representation of the service root.
25-SIMPLE_WADL = '''<?xml version="1.0"?>
26+SIMPLE_WADL = b'''<?xml version="1.0"?>
27 <application xmlns="http://research.sun.com/wadl/2006/10">
28 <resources base="http://www.example.com/">
29 <resource path="" type="#service-root"/>
30@@ -58,7 +58,7 @@
31 '''
32
33 # The simplest JSON that looks like a representation of the service root.
34-SIMPLE_JSON = dumps({})
35+SIMPLE_JSON = b'{}'
36
37
38 class Response:
39@@ -148,7 +148,7 @@
40 """Show that bad WADL causes an exception."""
41 self.assertRaises(
42 SyntaxError, self.launchpad_with_responses,
43- Response(200, "This is not WADL."),
44+ Response(200, b"This is not WADL."),
45 Response(200, SIMPLE_JSON))
46
47 def test_bad_json(self):
48@@ -156,7 +156,7 @@
49 self.assertRaises(
50 JSONDecodeError, self.launchpad_with_responses,
51 Response(200, SIMPLE_WADL),
52- Response(200, "This is not JSON."))
53+ Response(200, b"This is not JSON."))
54
55
56 class TestTokenFailureDuringRequest(SimulatedResponsesTestCase):
57@@ -182,7 +182,7 @@
58 def test_bad_token(self):
59 """If our token is bad, we get another one."""
60 SimulatedResponsesLaunchpad.responses = [
61- Response(401, "Invalid token."),
62+ Response(401, b"Invalid token."),
63 Response(200, SIMPLE_WADL),
64 Response(200, SIMPLE_JSON)]
65
66@@ -195,7 +195,7 @@
67 """If our token is expired, we get another one."""
68
69 SimulatedResponsesLaunchpad.responses = [
70- Response(401, "Expired token."),
71+ Response(401, b"Expired token."),
72 Response(200, SIMPLE_WADL),
73 Response(200, SIMPLE_JSON)]
74
75@@ -208,7 +208,7 @@
76 """If our token is unknown, we get another one."""
77
78 SimulatedResponsesLaunchpad.responses = [
79- Response(401, "Unknown access token."),
80+ Response(401, b"Unknown access token."),
81 Response(200, SIMPLE_WADL),
82 Response(200, SIMPLE_JSON)]
83
84@@ -221,7 +221,7 @@
85 """We get another token no matter when the error happens."""
86 SimulatedResponsesLaunchpad.responses = [
87 Response(200, SIMPLE_WADL),
88- Response(401, "Expired token."),
89+ Response(401, b"Expired token."),
90 Response(200, SIMPLE_JSON)]
91
92 self.assertEqual(self.engine.access_tokens_obtained, 0)
93@@ -232,10 +232,10 @@
94 def test_many_errors(self):
95 """We'll keep getting new tokens as long as tokens are the problem."""
96 SimulatedResponsesLaunchpad.responses = [
97- Response(401, "Invalid token."),
98+ Response(401, b"Invalid token."),
99 Response(200, SIMPLE_WADL),
100- Response(401, "Expired token."),
101- Response(401, "Invalid token."),
102+ Response(401, b"Expired token."),
103+ Response(401, b"Invalid token."),
104 Response(200, SIMPLE_JSON)]
105 self.assertEqual(self.engine.access_tokens_obtained, 0)
106 launchpad = SimulatedResponsesLaunchpad.login_with(
107@@ -246,7 +246,7 @@
108 """If the token is not at fault, a 401 error raises an exception."""
109
110 SimulatedResponsesLaunchpad.responses = [
111- Response(401, "Some other error.")]
112+ Response(401, b"Some other error.")]
113
114 self.assertRaises(
115 Unauthorized, SimulatedResponsesLaunchpad.login_with,

Subscribers

People subscribed via source and target branches