Merge lp:~leonardr/launchpadlib/use-shorthand-uris-in-all-tests into lp:launchpadlib

Proposed by Leonard Richardson
Status: Merged
Merged at revision: not available
Proposed branch: lp:~leonardr/launchpadlib/use-shorthand-uris-in-all-tests
Merge into: lp:launchpadlib
Diff against target: 217 lines (+26/-19)
5 files modified
src/launchpadlib/credentials.py (+4/-1)
src/launchpadlib/docs/introduction.txt (+7/-8)
src/launchpadlib/launchpad.py (+10/-5)
src/launchpadlib/testing/helpers.py (+1/-5)
src/launchpadlib/uris.py (+4/-0)
To merge this branch: bzr merge lp:~leonardr/launchpadlib/use-shorthand-uris-in-all-tests
Reviewer Review Type Date Requested Status
Gary Poster Approve
Review via email: mp+16298@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Leonard Richardson (leonardr) wrote :

We had some untested code paths to do with shorthand URIs like 'edge'. This is because the Launchpad instance used for tests didn't have a shorthand URI, so we used the long-form URI everywhere. This masked several places where shorthand URIs, when passed in, were not being dereferenced.

This branch changes all our tests that use 'http://api.launchpad.dev:8085/beta/' or 'http://launchpad.dev:8085/' to use the shorthand string 'dev_test' instead. This caused several tests to fail due to a lack of dereferencing code. The most important one is a bug I just introduced into Launchpad.login_with, which was breaking typical usage of popular launchpadlib scripts.

Revision history for this message
Gary Poster (gary) wrote :

merge-conditional

Hi Leonard, as we agreed on IRC, please include an explanation in introduction.txt of what the test_dev string is and where it is defined in the package (so that readers can find the other strings).

Other than that, looks good. Thank you!

Gary

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/launchpadlib/credentials.py'
2--- src/launchpadlib/credentials.py 2009-12-16 19:35:27 +0000
3+++ src/launchpadlib/credentials.py 2009-12-17 17:05:22 +0000
4@@ -86,6 +86,7 @@
5 """
6 assert self.consumer is not None, "Consumer not specified."
7 assert self.access_token is None, "Access token already obtained."
8+ web_root = uris.lookup_web_root(web_root)
9 params = dict(
10 oauth_consumer_key=self.consumer.key,
11 oauth_signature_method='PLAINTEXT',
12@@ -127,6 +128,7 @@
13 """
14 assert self._request_token is not None, (
15 "get_request_token() doesn't seem to have been called.")
16+ web_root = uris.lookup_web_root(web_root)
17 params = dict(
18 oauth_consumer_key=self.consumer.key,
19 oauth_signature_method='PLAINTEXT',
20@@ -187,7 +189,7 @@
21 """
22
23 def __init__(self, web_root=uris.STAGING_WEB_ROOT):
24- self.web_root = web_root
25+ self.web_root = uris.lookup_web_root(web_root)
26 self.http = httplib2.Http()
27
28 def _auth_header(self, username, password):
29@@ -509,6 +511,7 @@
30
31 def __init__(self, web_root, consumer_name, request_token,
32 allow_access_levels=[], max_failed_attempts=3):
33+ web_root = uris.lookup_web_root(web_root)
34 page = "+authorize-token?oauth_token=%s" % request_token
35 if len(allow_access_levels) > 0:
36 page += ("&allow_permission=" +
37
38=== modified file 'src/launchpadlib/docs/introduction.txt'
39--- src/launchpadlib/docs/introduction.txt 2009-12-16 19:35:27 +0000
40+++ src/launchpadlib/docs/introduction.txt 2009-12-17 17:05:22 +0000
41@@ -219,7 +219,7 @@
42 >>> credentials = Credentials('consumer')
43
44 >>> authorization_url = credentials.get_request_token(
45- ... context='firefox', web_root='http://launchpad.dev:8085/')
46+ ... context='firefox', web_root='test_dev')
47 >>> authorization_url
48 'http://launchpad.dev:8085/+authorize-token?oauth_token=...&lp.context=firefox'
49
50@@ -237,8 +237,7 @@
51 SimulatedLaunchpadBrowser to pretend the user is authorizing it.
52
53 >>> from launchpadlib.credentials import SimulatedLaunchpadBrowser
54- >>> browser = SimulatedLaunchpadBrowser(
55- ... web_root='http://launchpad.dev:8085/')
56+ >>> browser = SimulatedLaunchpadBrowser(web_root='test_dev')
57 >>> response, content = browser.grant_access(
58 ... "foo.bar@canonical.com", "test",
59 ... credentials._request_token.key, "WRITE_PRIVATE",
60@@ -249,7 +248,7 @@
61 After that we can exchange that request token for an access token.
62
63 >>> credentials.exchange_request_token_for_access_token(
64- ... web_root='http://launchpad.dev:8085/')
65+ ... web_root='test_dev')
66
67 Once that's done, our credentials will be complete and ready to use.
68
69@@ -295,7 +294,7 @@
70
71 >>> consumer_name = 'launchpadlib'
72 >>> launchpad = Launchpad.get_token_and_login(
73- ... consumer_name, service_root="http://api.launchpad.dev:8085/beta/",
74+ ... consumer_name, service_root="test_dev",
75 ... authorizer_class=AuthorizeAsSalgado)
76 [If this were a real application, the end-user's web browser would
77 be opened to http://launchpad.dev:8085/+authorize-token?oauth_token=...]
78@@ -312,7 +311,7 @@
79 >>> import tempfile
80 >>> cache_dir = tempfile.mkdtemp()
81 >>> launchpad = Launchpad.login_with(
82- ... consumer_name, service_root="http://api.launchpad.dev:8085/beta/",
83+ ... consumer_name, service_root="test_dev",
84 ... launchpadlib_dir=cache_dir,
85 ... authorizer_class=AuthorizeAsSalgado)
86 [If this were a real application...]
87@@ -329,7 +328,7 @@
88 authorize a request token.
89
90 >>> launchpad = Launchpad.login_with(
91- ... consumer_name, service_root="http://api.launchpad.dev:8085/beta/",
92+ ... consumer_name, service_root="test_dev",
93 ... launchpadlib_dir=cache_dir,
94 ... authorizer_class=None)
95 >>> print launchpad.me.name
96@@ -349,7 +348,7 @@
97
98 >>> credentials = Credentials('consumer')
99 >>> dictionary = credentials.get_request_token(
100- ... context='firefox', web_root='http://launchpad.dev:8085/',
101+ ... context='firefox', web_root='test_dev',
102 ... token_format=Credentials.DICT_TOKEN_FORMAT)
103
104 The dictionary has useful information about the token and about the
105
106=== modified file 'src/launchpadlib/launchpad.py'
107--- src/launchpadlib/launchpad.py 2009-12-16 19:35:27 +0000
108+++ src/launchpadlib/launchpad.py 2009-12-17 17:05:22 +0000
109@@ -94,6 +94,7 @@
110 :param service_root: The URL to the root of the web service.
111 :type service_root: string
112 """
113+ service_root = uris.lookup_service_root(service_root)
114 super(Launchpad, self).__init__(
115 credentials, service_root, cache, timeout, proxy_info)
116
117@@ -156,6 +157,7 @@
118 :rtype: `Launchpad`
119 """
120 credentials = Credentials(consumer_name)
121+ service_root = uris.lookup_service_root(service_root)
122 web_root_uri = URI(service_root)
123 web_root_uri.path = ""
124 web_root_uri.host = web_root_uri.host.replace("api.", "", 1)
125@@ -175,7 +177,7 @@
126 cls, consumer_name, service_root=uris.STAGING_SERVICE_ROOT,
127 launchpadlib_dir=None, timeout=None, proxy_info=None):
128 """Get access to Launchpad without providing any credentials."""
129- service_root_dir, cache_path = cls._get_paths(
130+ service_root, service_root_dir, cache_path = cls._get_paths(
131 service_root, launchpadlib_dir)
132 token = AnonymousAccessToken()
133 credentials = Credentials(consumer_name, access_token=token)
134@@ -222,7 +224,7 @@
135 :rtype: `Launchpad`
136
137 """
138- service_root_dir, cache_path = cls._get_paths(
139+ service_root, service_root_dir, cache_path = cls._get_paths(
140 service_root, launchpadlib_dir)
141 credentials_path = os.path.join(service_root_dir, 'credentials')
142 if not os.path.exists(credentials_path):
143@@ -256,10 +258,13 @@
144 This is a helper function used by login_with() and
145 login_anonymously().
146
147- :param service_root: The service root the user wants to connect to.
148+ :param service_root: The service root the user wants to
149+ connect to. This may be an alias (which will be
150+ dereferenced to a URL and returned) or a URL (which will
151+ be returned as is).
152 :param launchpadlib_dir: The user's base launchpadlib directory,
153 if known.
154- :return: A 2-tuple: (cache_dir, service_root_dir)
155+ :return: A 3-tuple: (service_root_uri, cache_dir, service_root_dir)
156 """
157 if launchpadlib_dir is None:
158 home_dir = os.environ['HOME']
159@@ -277,4 +282,4 @@
160 cache_path = os.path.join(service_root_dir, 'cache')
161 if not os.path.exists(cache_path):
162 os.makedirs(cache_path)
163- return (cache_path, service_root_dir)
164+ return (service_root, cache_path, service_root_dir)
165
166=== modified file 'src/launchpadlib/testing/helpers.py'
167--- src/launchpadlib/testing/helpers.py 2009-11-03 13:50:27 +0000
168+++ src/launchpadlib/testing/helpers.py 2009-12-17 17:05:22 +0000
169@@ -38,14 +38,10 @@
170 class TestableLaunchpad(Launchpad):
171 """A base class for talking to the testing root service."""
172
173- # Use our test service root.
174- TESTING_SERVICE_ROOT = 'http://api.launchpad.dev:8085/beta/'
175-
176 def __init__(self, credentials, service_root=None,
177 cache=None, timeout=None, proxy_info=None):
178 super(TestableLaunchpad, self).__init__(
179- credentials, TestableLaunchpad.TESTING_SERVICE_ROOT,
180- cache, timeout, proxy_info)
181+ credentials, 'test_dev', cache, timeout, proxy_info)
182
183
184 class KnownTokens:
185
186=== modified file 'src/launchpadlib/uris.py'
187--- src/launchpadlib/uris.py 2009-10-27 15:58:44 +0000
188+++ src/launchpadlib/uris.py 2009-12-17 17:05:22 +0000
189@@ -33,12 +33,14 @@
190 STAGING_SERVICE_ROOT = 'https://api.staging.launchpad.net/beta/'
191 DEV_SERVICE_ROOT = 'https://api.launchpad.dev/beta/'
192 DOGFOOD_SERVICE_ROOT = 'https://api.dogfood.launchpad.net/beta/'
193+TEST_DEV_SERVICE_ROOT = 'http://api.launchpad.dev:8085/beta/'
194
195 LPNET_WEB_ROOT = 'https://launchpad.net/'
196 EDGE_WEB_ROOT = 'https://edge.launchpad.net/'
197 STAGING_WEB_ROOT = 'https://staging.launchpad.net/'
198 DEV_WEB_ROOT = 'https://launchpad.dev/'
199 DOGFOOD_WEB_ROOT = 'https://dogfood.launchpad.net/'
200+TEST_DEV_WEB_ROOT = 'http://launchpad.dev:8085/'
201
202
203 service_roots = dict(
204@@ -47,6 +49,7 @@
205 staging=STAGING_SERVICE_ROOT,
206 dogfood=DOGFOOD_SERVICE_ROOT,
207 dev=DEV_SERVICE_ROOT,
208+ test_dev=TEST_DEV_SERVICE_ROOT
209 )
210
211
212@@ -56,6 +59,7 @@
213 staging=STAGING_WEB_ROOT,
214 dogfood=DOGFOOD_WEB_ROOT,
215 dev=DEV_WEB_ROOT,
216+ test_dev=TEST_DEV_WEB_ROOT
217 )
218
219

Subscribers

People subscribed via source and target branches