Merge lp:~bac/launchpadlib/short_service_names into lp:~launchpad-pqm/launchpadlib/devel

Proposed by Brad Crittenden
Status: Merged
Merge reported by: Leonard Richardson
Merged at revision: not available
Proposed branch: lp:~bac/launchpadlib/short_service_names
Merge into: lp:~launchpad-pqm/launchpadlib/devel
Diff against target: 129 lines
3 files modified
HACKING.txt (+16/-0)
src/launchpadlib/launchpad.py (+16/-4)
src/launchpadlib/tests/test_launchpad.py (+18/-1)
To merge this branch: bzr merge lp:~bac/launchpadlib/short_service_names
Reviewer Review Type Date Requested Status
Leonard Richardson (community) code Approve
Review via email: mp+12543@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Brad Crittenden (bac) wrote :

Allows the use of short names in Launchpad.login_with. Supported names are 'edge', 'staging', 'dogfood', and 'dev'.

Revision history for this message
Leonard Richardson (leonardr) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'HACKING.txt'
2--- HACKING.txt 2009-03-20 20:46:06 +0000
3+++ HACKING.txt 2009-09-28 19:05:20 +0000
4@@ -39,3 +39,19 @@
5 or send a message to:
6
7 lazr-developers@lists.launchpad.net
8+
9+
10+========
11+Building
12+========
13+
14+As mentioned above, this project uses zc.buildout, which requires a
15+few steps to build some necessary files.
16+
17+The following two steps will create some necessary files, including a
18+bin directory.
19+% python bootstrap.py
20+% bin/buildout
21+
22+Once built you can run all of the tests with:
23+% bin/test
24
25=== modified file 'src/launchpadlib/launchpad.py'
26--- src/launchpadlib/launchpad.py 2009-03-23 21:50:35 +0000
27+++ src/launchpadlib/launchpad.py 2009-09-28 19:05:20 +0000
28@@ -22,11 +22,9 @@
29 ]
30
31 import os
32-import shutil
33 import simplejson
34 import stat
35 import sys
36-import tempfile
37 import urlparse
38 import webbrowser
39
40@@ -37,8 +35,12 @@
41 from launchpadlib.resource import Resource
42 from launchpadlib.credentials import AccessToken, Credentials
43
44+
45+EDGE_SERVICE_ROOT = 'https://api.edge.launchpad.net/beta/'
46 STAGING_SERVICE_ROOT = 'https://api.staging.launchpad.net/beta/'
47-EDGE_SERVICE_ROOT = 'https://api.edge.launchpad.net/beta/'
48+DOGFOOD_SERVICE_ROOT = 'https://api.dogfood.launchpad.net/beta/'
49+DEV_SERVICE_ROOT = 'https://api.launchpad.dev/beta/'
50+
51
52 class Launchpad(Resource):
53 """Root Launchpad API class.
54@@ -47,6 +49,12 @@
55 :type credentials: `Credentials`
56 """
57
58+ service_roots = dict(edge=EDGE_SERVICE_ROOT,
59+ staging=STAGING_SERVICE_ROOT,
60+ dogfood=DOGFOOD_SERVICE_ROOT,
61+ dev=DEV_SERVICE_ROOT,
62+ )
63+
64 def __init__(self, credentials, service_root=STAGING_SERVICE_ROOT,
65 cache=None, timeout=None, proxy_info=None):
66 """Root access to the Launchpad API.
67@@ -183,7 +191,8 @@
68 `Consumer` constructor
69 :type consumer_name: string
70 :param service_root: The URL to the root of the web service.
71- :type service_root: string
72+ :type service_root: string. Can either be the full URL to a service
73+ or one of the short service names.
74 :param launchpadlib_dir: The directory where the cache and
75 credentials are stored.
76 :type launchpadlib_dir: string
77@@ -195,6 +204,9 @@
78 home_dir = os.environ['HOME']
79 launchpadlib_dir = os.path.join(home_dir, '.launchpadlib')
80 launchpadlib_dir = os.path.expanduser(launchpadlib_dir)
81+ # Determine the real service root.
82+ if service_root in cls.service_roots:
83+ service_root = cls.service_roots[service_root]
84 # Each service root has its own cache and credential dirs.
85 scheme, host_name, path, query, fragment = urlparse.urlsplit(
86 service_root)
87
88=== modified file 'src/launchpadlib/tests/test_launchpad.py'
89--- src/launchpadlib/tests/test_launchpad.py 2009-03-23 22:48:16 +0000
90+++ src/launchpadlib/tests/test_launchpad.py 2009-09-28 19:05:20 +0000
91@@ -41,6 +41,7 @@
92 passed_in_kwargs = None
93 credentials = None
94 get_token_and_login_called = False
95+ service_roots = dict(example='http://api.example.com/beta')
96
97 def __init__(self, credentials, **kw):
98 self.credentials = credentials
99@@ -48,7 +49,7 @@
100
101 @classmethod
102 def get_token_and_login(cls, consumer_name, **kw):
103- """Create fake credentials and recored that we were called."""
104+ """Create fake credentials and record that we were called."""
105 credentials = Credentials(
106 consumer_name, consumer_secret='consumer_secret:42',
107 access_token=AccessToken('access_key:84', 'access_secret:168'))
108@@ -204,5 +205,21 @@
109 self.assertTrue(os.path.exists(
110 os.path.join(launchpadlib_dir, 'api.example.com', 'credentials')))
111
112+ def test_short_service_name(self):
113+ # A short service name is converted to the full service root URL.
114+ launchpad = NoNetworkLaunchpad.login_with('app name', 'example')
115+ self.assertEqual(
116+ launchpad.passed_in_kwargs['service_root'],
117+ 'http://api.example.com/beta')
118+
119+ def test_short_service_name_bad(self):
120+ # A short service name that does not match one of the pre-defined
121+ # service root names is passed through.
122+ launchpad = NoNetworkLaunchpad.login_with('app name', 'foo')
123+ self.assertEqual(
124+ launchpad.passed_in_kwargs['service_root'],
125+ 'foo')
126+
127+
128 def additional_tests():
129 return unittest.TestLoader().loadTestsFromName(__name__)

Subscribers

People subscribed via source and target branches