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
=== modified file 'src/launchpadlib/credentials.py'
--- src/launchpadlib/credentials.py 2009-12-16 19:35:27 +0000
+++ src/launchpadlib/credentials.py 2009-12-17 17:05:22 +0000
@@ -86,6 +86,7 @@
86 """86 """
87 assert self.consumer is not None, "Consumer not specified."87 assert self.consumer is not None, "Consumer not specified."
88 assert self.access_token is None, "Access token already obtained."88 assert self.access_token is None, "Access token already obtained."
89 web_root = uris.lookup_web_root(web_root)
89 params = dict(90 params = dict(
90 oauth_consumer_key=self.consumer.key,91 oauth_consumer_key=self.consumer.key,
91 oauth_signature_method='PLAINTEXT',92 oauth_signature_method='PLAINTEXT',
@@ -127,6 +128,7 @@
127 """128 """
128 assert self._request_token is not None, (129 assert self._request_token is not None, (
129 "get_request_token() doesn't seem to have been called.")130 "get_request_token() doesn't seem to have been called.")
131 web_root = uris.lookup_web_root(web_root)
130 params = dict(132 params = dict(
131 oauth_consumer_key=self.consumer.key,133 oauth_consumer_key=self.consumer.key,
132 oauth_signature_method='PLAINTEXT',134 oauth_signature_method='PLAINTEXT',
@@ -187,7 +189,7 @@
187 """189 """
188190
189 def __init__(self, web_root=uris.STAGING_WEB_ROOT):191 def __init__(self, web_root=uris.STAGING_WEB_ROOT):
190 self.web_root = web_root192 self.web_root = uris.lookup_web_root(web_root)
191 self.http = httplib2.Http()193 self.http = httplib2.Http()
192194
193 def _auth_header(self, username, password):195 def _auth_header(self, username, password):
@@ -509,6 +511,7 @@
509511
510 def __init__(self, web_root, consumer_name, request_token,512 def __init__(self, web_root, consumer_name, request_token,
511 allow_access_levels=[], max_failed_attempts=3):513 allow_access_levels=[], max_failed_attempts=3):
514 web_root = uris.lookup_web_root(web_root)
512 page = "+authorize-token?oauth_token=%s" % request_token515 page = "+authorize-token?oauth_token=%s" % request_token
513 if len(allow_access_levels) > 0:516 if len(allow_access_levels) > 0:
514 page += ("&allow_permission=" +517 page += ("&allow_permission=" +
515518
=== modified file 'src/launchpadlib/docs/introduction.txt'
--- src/launchpadlib/docs/introduction.txt 2009-12-16 19:35:27 +0000
+++ src/launchpadlib/docs/introduction.txt 2009-12-17 17:05:22 +0000
@@ -219,7 +219,7 @@
219 >>> credentials = Credentials('consumer')219 >>> credentials = Credentials('consumer')
220220
221 >>> authorization_url = credentials.get_request_token(221 >>> authorization_url = credentials.get_request_token(
222 ... context='firefox', web_root='http://launchpad.dev:8085/')222 ... context='firefox', web_root='test_dev')
223 >>> authorization_url223 >>> authorization_url
224 'http://launchpad.dev:8085/+authorize-token?oauth_token=...&lp.context=firefox'224 'http://launchpad.dev:8085/+authorize-token?oauth_token=...&lp.context=firefox'
225225
@@ -237,8 +237,7 @@
237SimulatedLaunchpadBrowser to pretend the user is authorizing it.237SimulatedLaunchpadBrowser to pretend the user is authorizing it.
238238
239 >>> from launchpadlib.credentials import SimulatedLaunchpadBrowser239 >>> from launchpadlib.credentials import SimulatedLaunchpadBrowser
240 >>> browser = SimulatedLaunchpadBrowser(240 >>> browser = SimulatedLaunchpadBrowser(web_root='test_dev')
241 ... web_root='http://launchpad.dev:8085/')
242 >>> response, content = browser.grant_access(241 >>> response, content = browser.grant_access(
243 ... "foo.bar@canonical.com", "test",242 ... "foo.bar@canonical.com", "test",
244 ... credentials._request_token.key, "WRITE_PRIVATE",243 ... credentials._request_token.key, "WRITE_PRIVATE",
@@ -249,7 +248,7 @@
249After that we can exchange that request token for an access token.248After that we can exchange that request token for an access token.
250249
251 >>> credentials.exchange_request_token_for_access_token(250 >>> credentials.exchange_request_token_for_access_token(
252 ... web_root='http://launchpad.dev:8085/')251 ... web_root='test_dev')
253252
254Once that's done, our credentials will be complete and ready to use.253Once that's done, our credentials will be complete and ready to use.
255254
@@ -295,7 +294,7 @@
295294
296 >>> consumer_name = 'launchpadlib'295 >>> consumer_name = 'launchpadlib'
297 >>> launchpad = Launchpad.get_token_and_login(296 >>> launchpad = Launchpad.get_token_and_login(
298 ... consumer_name, service_root="http://api.launchpad.dev:8085/beta/",297 ... consumer_name, service_root="test_dev",
299 ... authorizer_class=AuthorizeAsSalgado)298 ... authorizer_class=AuthorizeAsSalgado)
300 [If this were a real application, the end-user's web browser would299 [If this were a real application, the end-user's web browser would
301 be opened to http://launchpad.dev:8085/+authorize-token?oauth_token=...]300 be opened to http://launchpad.dev:8085/+authorize-token?oauth_token=...]
@@ -312,7 +311,7 @@
312 >>> import tempfile311 >>> import tempfile
313 >>> cache_dir = tempfile.mkdtemp()312 >>> cache_dir = tempfile.mkdtemp()
314 >>> launchpad = Launchpad.login_with(313 >>> launchpad = Launchpad.login_with(
315 ... consumer_name, service_root="http://api.launchpad.dev:8085/beta/",314 ... consumer_name, service_root="test_dev",
316 ... launchpadlib_dir=cache_dir,315 ... launchpadlib_dir=cache_dir,
317 ... authorizer_class=AuthorizeAsSalgado)316 ... authorizer_class=AuthorizeAsSalgado)
318 [If this were a real application...]317 [If this were a real application...]
@@ -329,7 +328,7 @@
329authorize a request token.328authorize a request token.
330329
331 >>> launchpad = Launchpad.login_with(330 >>> launchpad = Launchpad.login_with(
332 ... consumer_name, service_root="http://api.launchpad.dev:8085/beta/",331 ... consumer_name, service_root="test_dev",
333 ... launchpadlib_dir=cache_dir,332 ... launchpadlib_dir=cache_dir,
334 ... authorizer_class=None)333 ... authorizer_class=None)
335 >>> print launchpad.me.name334 >>> print launchpad.me.name
@@ -349,7 +348,7 @@
349348
350 >>> credentials = Credentials('consumer')349 >>> credentials = Credentials('consumer')
351 >>> dictionary = credentials.get_request_token(350 >>> dictionary = credentials.get_request_token(
352 ... context='firefox', web_root='http://launchpad.dev:8085/',351 ... context='firefox', web_root='test_dev',
353 ... token_format=Credentials.DICT_TOKEN_FORMAT)352 ... token_format=Credentials.DICT_TOKEN_FORMAT)
354353
355The dictionary has useful information about the token and about the354The dictionary has useful information about the token and about the
356355
=== modified file 'src/launchpadlib/launchpad.py'
--- src/launchpadlib/launchpad.py 2009-12-16 19:35:27 +0000
+++ src/launchpadlib/launchpad.py 2009-12-17 17:05:22 +0000
@@ -94,6 +94,7 @@
94 :param service_root: The URL to the root of the web service.94 :param service_root: The URL to the root of the web service.
95 :type service_root: string95 :type service_root: string
96 """96 """
97 service_root = uris.lookup_service_root(service_root)
97 super(Launchpad, self).__init__(98 super(Launchpad, self).__init__(
98 credentials, service_root, cache, timeout, proxy_info)99 credentials, service_root, cache, timeout, proxy_info)
99100
@@ -156,6 +157,7 @@
156 :rtype: `Launchpad`157 :rtype: `Launchpad`
157 """158 """
158 credentials = Credentials(consumer_name)159 credentials = Credentials(consumer_name)
160 service_root = uris.lookup_service_root(service_root)
159 web_root_uri = URI(service_root)161 web_root_uri = URI(service_root)
160 web_root_uri.path = ""162 web_root_uri.path = ""
161 web_root_uri.host = web_root_uri.host.replace("api.", "", 1)163 web_root_uri.host = web_root_uri.host.replace("api.", "", 1)
@@ -175,7 +177,7 @@
175 cls, consumer_name, service_root=uris.STAGING_SERVICE_ROOT,177 cls, consumer_name, service_root=uris.STAGING_SERVICE_ROOT,
176 launchpadlib_dir=None, timeout=None, proxy_info=None):178 launchpadlib_dir=None, timeout=None, proxy_info=None):
177 """Get access to Launchpad without providing any credentials."""179 """Get access to Launchpad without providing any credentials."""
178 service_root_dir, cache_path = cls._get_paths(180 service_root, service_root_dir, cache_path = cls._get_paths(
179 service_root, launchpadlib_dir)181 service_root, launchpadlib_dir)
180 token = AnonymousAccessToken()182 token = AnonymousAccessToken()
181 credentials = Credentials(consumer_name, access_token=token)183 credentials = Credentials(consumer_name, access_token=token)
@@ -222,7 +224,7 @@
222 :rtype: `Launchpad`224 :rtype: `Launchpad`
223225
224 """226 """
225 service_root_dir, cache_path = cls._get_paths(227 service_root, service_root_dir, cache_path = cls._get_paths(
226 service_root, launchpadlib_dir)228 service_root, launchpadlib_dir)
227 credentials_path = os.path.join(service_root_dir, 'credentials')229 credentials_path = os.path.join(service_root_dir, 'credentials')
228 if not os.path.exists(credentials_path):230 if not os.path.exists(credentials_path):
@@ -256,10 +258,13 @@
256 This is a helper function used by login_with() and258 This is a helper function used by login_with() and
257 login_anonymously().259 login_anonymously().
258260
259 :param service_root: The service root the user wants to connect to.261 :param service_root: The service root the user wants to
262 connect to. This may be an alias (which will be
263 dereferenced to a URL and returned) or a URL (which will
264 be returned as is).
260 :param launchpadlib_dir: The user's base launchpadlib directory,265 :param launchpadlib_dir: The user's base launchpadlib directory,
261 if known.266 if known.
262 :return: A 2-tuple: (cache_dir, service_root_dir)267 :return: A 3-tuple: (service_root_uri, cache_dir, service_root_dir)
263 """268 """
264 if launchpadlib_dir is None:269 if launchpadlib_dir is None:
265 home_dir = os.environ['HOME']270 home_dir = os.environ['HOME']
@@ -277,4 +282,4 @@
277 cache_path = os.path.join(service_root_dir, 'cache')282 cache_path = os.path.join(service_root_dir, 'cache')
278 if not os.path.exists(cache_path):283 if not os.path.exists(cache_path):
279 os.makedirs(cache_path)284 os.makedirs(cache_path)
280 return (cache_path, service_root_dir)285 return (service_root, cache_path, service_root_dir)
281286
=== modified file 'src/launchpadlib/testing/helpers.py'
--- src/launchpadlib/testing/helpers.py 2009-11-03 13:50:27 +0000
+++ src/launchpadlib/testing/helpers.py 2009-12-17 17:05:22 +0000
@@ -38,14 +38,10 @@
38class TestableLaunchpad(Launchpad):38class TestableLaunchpad(Launchpad):
39 """A base class for talking to the testing root service."""39 """A base class for talking to the testing root service."""
4040
41 # Use our test service root.
42 TESTING_SERVICE_ROOT = 'http://api.launchpad.dev:8085/beta/'
43
44 def __init__(self, credentials, service_root=None,41 def __init__(self, credentials, service_root=None,
45 cache=None, timeout=None, proxy_info=None):42 cache=None, timeout=None, proxy_info=None):
46 super(TestableLaunchpad, self).__init__(43 super(TestableLaunchpad, self).__init__(
47 credentials, TestableLaunchpad.TESTING_SERVICE_ROOT,44 credentials, 'test_dev', cache, timeout, proxy_info)
48 cache, timeout, proxy_info)
4945
5046
51class KnownTokens:47class KnownTokens:
5248
=== modified file 'src/launchpadlib/uris.py'
--- src/launchpadlib/uris.py 2009-10-27 15:58:44 +0000
+++ src/launchpadlib/uris.py 2009-12-17 17:05:22 +0000
@@ -33,12 +33,14 @@
33STAGING_SERVICE_ROOT = 'https://api.staging.launchpad.net/beta/'33STAGING_SERVICE_ROOT = 'https://api.staging.launchpad.net/beta/'
34DEV_SERVICE_ROOT = 'https://api.launchpad.dev/beta/'34DEV_SERVICE_ROOT = 'https://api.launchpad.dev/beta/'
35DOGFOOD_SERVICE_ROOT = 'https://api.dogfood.launchpad.net/beta/'35DOGFOOD_SERVICE_ROOT = 'https://api.dogfood.launchpad.net/beta/'
36TEST_DEV_SERVICE_ROOT = 'http://api.launchpad.dev:8085/beta/'
3637
37LPNET_WEB_ROOT = 'https://launchpad.net/'38LPNET_WEB_ROOT = 'https://launchpad.net/'
38EDGE_WEB_ROOT = 'https://edge.launchpad.net/'39EDGE_WEB_ROOT = 'https://edge.launchpad.net/'
39STAGING_WEB_ROOT = 'https://staging.launchpad.net/'40STAGING_WEB_ROOT = 'https://staging.launchpad.net/'
40DEV_WEB_ROOT = 'https://launchpad.dev/'41DEV_WEB_ROOT = 'https://launchpad.dev/'
41DOGFOOD_WEB_ROOT = 'https://dogfood.launchpad.net/'42DOGFOOD_WEB_ROOT = 'https://dogfood.launchpad.net/'
43TEST_DEV_WEB_ROOT = 'http://launchpad.dev:8085/'
4244
4345
44service_roots = dict(46service_roots = dict(
@@ -47,6 +49,7 @@
47 staging=STAGING_SERVICE_ROOT,49 staging=STAGING_SERVICE_ROOT,
48 dogfood=DOGFOOD_SERVICE_ROOT,50 dogfood=DOGFOOD_SERVICE_ROOT,
49 dev=DEV_SERVICE_ROOT,51 dev=DEV_SERVICE_ROOT,
52 test_dev=TEST_DEV_SERVICE_ROOT
50 )53 )
5154
5255
@@ -56,6 +59,7 @@
56 staging=STAGING_WEB_ROOT,59 staging=STAGING_WEB_ROOT,
57 dogfood=DOGFOOD_WEB_ROOT,60 dogfood=DOGFOOD_WEB_ROOT,
58 dev=DEV_WEB_ROOT,61 dev=DEV_WEB_ROOT,
62 test_dev=TEST_DEV_WEB_ROOT
59 )63 )
6064
6165

Subscribers

People subscribed via source and target branches