Merge lp:~cjwatson/lazr.restfulclient/access-token-compat into lp:lazr.restfulclient

Proposed by Colin Watson
Status: Merged
Merged at revision: 172
Proposed branch: lp:~cjwatson/lazr.restfulclient/access-token-compat
Merge into: lp:lazr.restfulclient
Diff against target: 91 lines (+52/-0)
3 files modified
NEWS.rst (+7/-0)
src/lazr/restfulclient/authorize/oauth.py (+19/-0)
src/lazr/restfulclient/tests/test_oauth.py (+26/-0)
To merge this branch: bzr merge lp:~cjwatson/lazr.restfulclient/access-token-compat
Reviewer Review Type Date Requested Status
Thiago F. Pappacena (community) Approve
LAZR Developers Pending
Review via email: mp+378084@code.launchpad.net

Commit message

Restore some AccessToken methods.

Description of the change

Restore from_string, to_string, and __str__ methods of lazr.restfulclient.authorize.oauth.AccessToken, unintentionally removed in 0.14.0. This caused a test failure when attempting to upgrade Launchpad from 0.13.2 to 0.14.2.

AccessToken.from_string doesn't have particularly clean error handling, but this was true of the previous oauth-based version as well.

The test regression was caused by https://code.launchpad.net/~cjwatson/lazr.restfulclient/oauthlib/+merge/344716.

To post a comment you must log in.
Revision history for this message
Thiago F. Pappacena (pappacena) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'NEWS.rst'
--- NEWS.rst 2019-11-02 21:55:16 +0000
+++ NEWS.rst 2020-01-26 11:00:16 +0000
@@ -2,6 +2,13 @@
2NEWS for lazr.restfulclient2NEWS for lazr.restfulclient
3===========================3===========================
44
50.14.3
6======
7
8 - Restore from_string, to_string, and __str__ methods of
9 lazr.restfulclient.authorize.oauth.AccessToken, unintentionally removed
10 in 0.14.0.
11
50.14.2 (2018-11-17)120.14.2 (2018-11-17)
6===================13===================
714
815
=== modified file 'src/lazr/restfulclient/authorize/oauth.py'
--- src/lazr/restfulclient/authorize/oauth.py 2018-11-17 14:43:04 +0000
+++ src/lazr/restfulclient/authorize/oauth.py 2020-01-26 11:00:16 +0000
@@ -31,6 +31,10 @@
3131
32from oauthlib import oauth132from oauthlib import oauth1
33import six33import six
34from six.moves.urllib.parse import (
35 parse_qs,
36 urlencode,
37 )
3438
35from lazr.restfulclient.authorize import HttpAuthorizer39from lazr.restfulclient.authorize import HttpAuthorizer
36from lazr.restfulclient.errors import CredentialsFileError40from lazr.restfulclient.errors import CredentialsFileError
@@ -75,6 +79,21 @@
75 self.secret = secret79 self.secret = secret
76 self.context = context80 self.context = context
7781
82 def to_string(self):
83 return urlencode([
84 ("oauth_token_secret", self.secret),
85 ("oauth_token", self.key),
86 ])
87
88 __str__ = to_string
89
90 @classmethod
91 def from_string(cls, s):
92 params = parse_qs(s, keep_blank_values=False)
93 key = params["oauth_token"][0]
94 secret = params["oauth_token_secret"][0]
95 return cls(key, secret)
96
7897
79class TruthyString(six.text_type):98class TruthyString(six.text_type):
80 """A Unicode string which is always true."""99 """A Unicode string which is always true."""
81100
=== modified file 'src/lazr/restfulclient/tests/test_oauth.py'
--- src/lazr/restfulclient/tests/test_oauth.py 2018-04-28 12:29:24 +0000
+++ src/lazr/restfulclient/tests/test_oauth.py 2020-01-26 11:00:16 +0000
@@ -53,6 +53,32 @@
53 self.assertEqual(consumer.application_name, None)53 self.assertEqual(consumer.application_name, None)
5454
5555
56class TestAccessToken(TestCase):
57
58 def test_data_fields(self):
59 access_token = AccessToken("key", "secret", "context")
60 self.assertEqual(access_token.key, "key")
61 self.assertEqual(access_token.secret, "secret")
62 self.assertEqual(access_token.context, "context")
63
64 def test_default_context(self):
65 # Context defaults to None.
66 access_token = AccessToken("key", "secret")
67 self.assertIsNone(access_token.context)
68
69 def test___str__(self):
70 access_token = AccessToken("lock&key", "secret=password")
71 self.assertEqual(
72 "oauth_token_secret=secret%3Dpassword&oauth_token=lock%26key",
73 str(access_token))
74
75 def test_from_string(self):
76 access_token = AccessToken.from_string(
77 "oauth_token_secret=secret%3Dpassword&oauth_token=lock%26key")
78 self.assertEqual(access_token.key, "lock&key")
79 self.assertEqual(access_token.secret, "secret=password")
80
81
56class TestSystemWideConsumer(TestCase):82class TestSystemWideConsumer(TestCase):
5783
58 def test_useful_distro_name(self):84 def test_useful_distro_name(self):

Subscribers

People subscribed via source and target branches