Merge lp:~leonardr/launchpadlib/use-shorthand-uris-in-all-tests into lp:launchpadlib
- use-shorthand-uris-in-all-tests
- Merge into trunk
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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Gary Poster | Approve | ||
Review via email: mp+16298@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Leonard Richardson (leonardr) wrote : | # |
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 | 86 | """ | 86 | """ |
6 | 87 | assert self.consumer is not None, "Consumer not specified." | 87 | assert self.consumer is not None, "Consumer not specified." |
7 | 88 | assert self.access_token is None, "Access token already obtained." | 88 | assert self.access_token is None, "Access token already obtained." |
8 | 89 | web_root = uris.lookup_web_root(web_root) | ||
9 | 89 | params = dict( | 90 | params = dict( |
10 | 90 | oauth_consumer_key=self.consumer.key, | 91 | oauth_consumer_key=self.consumer.key, |
11 | 91 | oauth_signature_method='PLAINTEXT', | 92 | oauth_signature_method='PLAINTEXT', |
12 | @@ -127,6 +128,7 @@ | |||
13 | 127 | """ | 128 | """ |
14 | 128 | assert self._request_token is not None, ( | 129 | assert self._request_token is not None, ( |
15 | 129 | "get_request_token() doesn't seem to have been called.") | 130 | "get_request_token() doesn't seem to have been called.") |
16 | 131 | web_root = uris.lookup_web_root(web_root) | ||
17 | 130 | params = dict( | 132 | params = dict( |
18 | 131 | oauth_consumer_key=self.consumer.key, | 133 | oauth_consumer_key=self.consumer.key, |
19 | 132 | oauth_signature_method='PLAINTEXT', | 134 | oauth_signature_method='PLAINTEXT', |
20 | @@ -187,7 +189,7 @@ | |||
21 | 187 | """ | 189 | """ |
22 | 188 | 190 | ||
23 | 189 | def __init__(self, web_root=uris.STAGING_WEB_ROOT): | 191 | def __init__(self, web_root=uris.STAGING_WEB_ROOT): |
25 | 190 | self.web_root = web_root | 192 | self.web_root = uris.lookup_web_root(web_root) |
26 | 191 | self.http = httplib2.Http() | 193 | self.http = httplib2.Http() |
27 | 192 | 194 | ||
28 | 193 | def _auth_header(self, username, password): | 195 | def _auth_header(self, username, password): |
29 | @@ -509,6 +511,7 @@ | |||
30 | 509 | 511 | ||
31 | 510 | def __init__(self, web_root, consumer_name, request_token, | 512 | def __init__(self, web_root, consumer_name, request_token, |
32 | 511 | allow_access_levels=[], max_failed_attempts=3): | 513 | allow_access_levels=[], max_failed_attempts=3): |
33 | 514 | web_root = uris.lookup_web_root(web_root) | ||
34 | 512 | page = "+authorize-token?oauth_token=%s" % request_token | 515 | page = "+authorize-token?oauth_token=%s" % request_token |
35 | 513 | if len(allow_access_levels) > 0: | 516 | if len(allow_access_levels) > 0: |
36 | 514 | page += ("&allow_permission=" + | 517 | page += ("&allow_permission=" + |
37 | 515 | 518 | ||
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 | 219 | >>> credentials = Credentials('consumer') | 219 | >>> credentials = Credentials('consumer') |
43 | 220 | 220 | ||
44 | 221 | >>> authorization_url = credentials.get_request_token( | 221 | >>> authorization_url = credentials.get_request_token( |
46 | 222 | ... context='firefox', web_root='http://launchpad.dev:8085/') | 222 | ... context='firefox', web_root='test_dev') |
47 | 223 | >>> authorization_url | 223 | >>> authorization_url |
48 | 224 | 'http://launchpad.dev:8085/+authorize-token?oauth_token=...&lp.context=firefox' | 224 | 'http://launchpad.dev:8085/+authorize-token?oauth_token=...&lp.context=firefox' |
49 | 225 | 225 | ||
50 | @@ -237,8 +237,7 @@ | |||
51 | 237 | SimulatedLaunchpadBrowser to pretend the user is authorizing it. | 237 | SimulatedLaunchpadBrowser to pretend the user is authorizing it. |
52 | 238 | 238 | ||
53 | 239 | >>> from launchpadlib.credentials import SimulatedLaunchpadBrowser | 239 | >>> from launchpadlib.credentials import SimulatedLaunchpadBrowser |
56 | 240 | >>> browser = SimulatedLaunchpadBrowser( | 240 | >>> browser = SimulatedLaunchpadBrowser(web_root='test_dev') |
55 | 241 | ... web_root='http://launchpad.dev:8085/') | ||
57 | 242 | >>> response, content = browser.grant_access( | 241 | >>> response, content = browser.grant_access( |
58 | 243 | ... "foo.bar@canonical.com", "test", | 242 | ... "foo.bar@canonical.com", "test", |
59 | 244 | ... credentials._request_token.key, "WRITE_PRIVATE", | 243 | ... credentials._request_token.key, "WRITE_PRIVATE", |
60 | @@ -249,7 +248,7 @@ | |||
61 | 249 | After that we can exchange that request token for an access token. | 248 | After that we can exchange that request token for an access token. |
62 | 250 | 249 | ||
63 | 251 | >>> credentials.exchange_request_token_for_access_token( | 250 | >>> credentials.exchange_request_token_for_access_token( |
65 | 252 | ... web_root='http://launchpad.dev:8085/') | 251 | ... web_root='test_dev') |
66 | 253 | 252 | ||
67 | 254 | Once that's done, our credentials will be complete and ready to use. | 253 | Once that's done, our credentials will be complete and ready to use. |
68 | 255 | 254 | ||
69 | @@ -295,7 +294,7 @@ | |||
70 | 295 | 294 | ||
71 | 296 | >>> consumer_name = 'launchpadlib' | 295 | >>> consumer_name = 'launchpadlib' |
72 | 297 | >>> launchpad = Launchpad.get_token_and_login( | 296 | >>> launchpad = Launchpad.get_token_and_login( |
74 | 298 | ... consumer_name, service_root="http://api.launchpad.dev:8085/beta/", | 297 | ... consumer_name, service_root="test_dev", |
75 | 299 | ... authorizer_class=AuthorizeAsSalgado) | 298 | ... authorizer_class=AuthorizeAsSalgado) |
76 | 300 | [If this were a real application, the end-user's web browser would | 299 | [If this were a real application, the end-user's web browser would |
77 | 301 | be opened to http://launchpad.dev:8085/+authorize-token?oauth_token=...] | 300 | be opened to http://launchpad.dev:8085/+authorize-token?oauth_token=...] |
78 | @@ -312,7 +311,7 @@ | |||
79 | 312 | >>> import tempfile | 311 | >>> import tempfile |
80 | 313 | >>> cache_dir = tempfile.mkdtemp() | 312 | >>> cache_dir = tempfile.mkdtemp() |
81 | 314 | >>> launchpad = Launchpad.login_with( | 313 | >>> launchpad = Launchpad.login_with( |
83 | 315 | ... consumer_name, service_root="http://api.launchpad.dev:8085/beta/", | 314 | ... consumer_name, service_root="test_dev", |
84 | 316 | ... launchpadlib_dir=cache_dir, | 315 | ... launchpadlib_dir=cache_dir, |
85 | 317 | ... authorizer_class=AuthorizeAsSalgado) | 316 | ... authorizer_class=AuthorizeAsSalgado) |
86 | 318 | [If this were a real application...] | 317 | [If this were a real application...] |
87 | @@ -329,7 +328,7 @@ | |||
88 | 329 | authorize a request token. | 328 | authorize a request token. |
89 | 330 | 329 | ||
90 | 331 | >>> launchpad = Launchpad.login_with( | 330 | >>> launchpad = Launchpad.login_with( |
92 | 332 | ... consumer_name, service_root="http://api.launchpad.dev:8085/beta/", | 331 | ... consumer_name, service_root="test_dev", |
93 | 333 | ... launchpadlib_dir=cache_dir, | 332 | ... launchpadlib_dir=cache_dir, |
94 | 334 | ... authorizer_class=None) | 333 | ... authorizer_class=None) |
95 | 335 | >>> print launchpad.me.name | 334 | >>> print launchpad.me.name |
96 | @@ -349,7 +348,7 @@ | |||
97 | 349 | 348 | ||
98 | 350 | >>> credentials = Credentials('consumer') | 349 | >>> credentials = Credentials('consumer') |
99 | 351 | >>> dictionary = credentials.get_request_token( | 350 | >>> dictionary = credentials.get_request_token( |
101 | 352 | ... context='firefox', web_root='http://launchpad.dev:8085/', | 351 | ... context='firefox', web_root='test_dev', |
102 | 353 | ... token_format=Credentials.DICT_TOKEN_FORMAT) | 352 | ... token_format=Credentials.DICT_TOKEN_FORMAT) |
103 | 354 | 353 | ||
104 | 355 | The dictionary has useful information about the token and about the | 354 | The dictionary has useful information about the token and about the |
105 | 356 | 355 | ||
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 | 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. |
111 | 95 | :type service_root: string | 95 | :type service_root: string |
112 | 96 | """ | 96 | """ |
113 | 97 | service_root = uris.lookup_service_root(service_root) | ||
114 | 97 | super(Launchpad, self).__init__( | 98 | super(Launchpad, self).__init__( |
115 | 98 | credentials, service_root, cache, timeout, proxy_info) | 99 | credentials, service_root, cache, timeout, proxy_info) |
116 | 99 | 100 | ||
117 | @@ -156,6 +157,7 @@ | |||
118 | 156 | :rtype: `Launchpad` | 157 | :rtype: `Launchpad` |
119 | 157 | """ | 158 | """ |
120 | 158 | credentials = Credentials(consumer_name) | 159 | credentials = Credentials(consumer_name) |
121 | 160 | service_root = uris.lookup_service_root(service_root) | ||
122 | 159 | web_root_uri = URI(service_root) | 161 | web_root_uri = URI(service_root) |
123 | 160 | web_root_uri.path = "" | 162 | web_root_uri.path = "" |
124 | 161 | web_root_uri.host = web_root_uri.host.replace("api.", "", 1) | 163 | web_root_uri.host = web_root_uri.host.replace("api.", "", 1) |
125 | @@ -175,7 +177,7 @@ | |||
126 | 175 | cls, consumer_name, service_root=uris.STAGING_SERVICE_ROOT, | 177 | cls, consumer_name, service_root=uris.STAGING_SERVICE_ROOT, |
127 | 176 | launchpadlib_dir=None, timeout=None, proxy_info=None): | 178 | launchpadlib_dir=None, timeout=None, proxy_info=None): |
128 | 177 | """Get access to Launchpad without providing any credentials.""" | 179 | """Get access to Launchpad without providing any credentials.""" |
130 | 178 | service_root_dir, cache_path = cls._get_paths( | 180 | service_root, service_root_dir, cache_path = cls._get_paths( |
131 | 179 | service_root, launchpadlib_dir) | 181 | service_root, launchpadlib_dir) |
132 | 180 | token = AnonymousAccessToken() | 182 | token = AnonymousAccessToken() |
133 | 181 | credentials = Credentials(consumer_name, access_token=token) | 183 | credentials = Credentials(consumer_name, access_token=token) |
134 | @@ -222,7 +224,7 @@ | |||
135 | 222 | :rtype: `Launchpad` | 224 | :rtype: `Launchpad` |
136 | 223 | 225 | ||
137 | 224 | """ | 226 | """ |
139 | 225 | service_root_dir, cache_path = cls._get_paths( | 227 | service_root, service_root_dir, cache_path = cls._get_paths( |
140 | 226 | service_root, launchpadlib_dir) | 228 | service_root, launchpadlib_dir) |
141 | 227 | credentials_path = os.path.join(service_root_dir, 'credentials') | 229 | credentials_path = os.path.join(service_root_dir, 'credentials') |
142 | 228 | if not os.path.exists(credentials_path): | 230 | if not os.path.exists(credentials_path): |
143 | @@ -256,10 +258,13 @@ | |||
144 | 256 | This is a helper function used by login_with() and | 258 | This is a helper function used by login_with() and |
145 | 257 | login_anonymously(). | 259 | login_anonymously(). |
146 | 258 | 260 | ||
148 | 259 | :param service_root: The service root the user wants to connect to. | 261 | :param service_root: The service root the user wants to |
149 | 262 | connect to. This may be an alias (which will be | ||
150 | 263 | dereferenced to a URL and returned) or a URL (which will | ||
151 | 264 | be returned as is). | ||
152 | 260 | :param launchpadlib_dir: The user's base launchpadlib directory, | 265 | :param launchpadlib_dir: The user's base launchpadlib directory, |
153 | 261 | if known. | 266 | if known. |
155 | 262 | :return: A 2-tuple: (cache_dir, service_root_dir) | 267 | :return: A 3-tuple: (service_root_uri, cache_dir, service_root_dir) |
156 | 263 | """ | 268 | """ |
157 | 264 | if launchpadlib_dir is None: | 269 | if launchpadlib_dir is None: |
158 | 265 | home_dir = os.environ['HOME'] | 270 | home_dir = os.environ['HOME'] |
159 | @@ -277,4 +282,4 @@ | |||
160 | 277 | cache_path = os.path.join(service_root_dir, 'cache') | 282 | cache_path = os.path.join(service_root_dir, 'cache') |
161 | 278 | if not os.path.exists(cache_path): | 283 | if not os.path.exists(cache_path): |
162 | 279 | os.makedirs(cache_path) | 284 | os.makedirs(cache_path) |
164 | 280 | return (cache_path, service_root_dir) | 285 | return (service_root, cache_path, service_root_dir) |
165 | 281 | 286 | ||
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 | 38 | class TestableLaunchpad(Launchpad): | 38 | class TestableLaunchpad(Launchpad): |
171 | 39 | """A base class for talking to the testing root service.""" | 39 | """A base class for talking to the testing root service.""" |
172 | 40 | 40 | ||
173 | 41 | # Use our test service root. | ||
174 | 42 | TESTING_SERVICE_ROOT = 'http://api.launchpad.dev:8085/beta/' | ||
175 | 43 | |||
176 | 44 | def __init__(self, credentials, service_root=None, | 41 | def __init__(self, credentials, service_root=None, |
177 | 45 | cache=None, timeout=None, proxy_info=None): | 42 | cache=None, timeout=None, proxy_info=None): |
178 | 46 | super(TestableLaunchpad, self).__init__( | 43 | super(TestableLaunchpad, self).__init__( |
181 | 47 | credentials, TestableLaunchpad.TESTING_SERVICE_ROOT, | 44 | credentials, 'test_dev', cache, timeout, proxy_info) |
180 | 48 | cache, timeout, proxy_info) | ||
182 | 49 | 45 | ||
183 | 50 | 46 | ||
184 | 51 | class KnownTokens: | 47 | class KnownTokens: |
185 | 52 | 48 | ||
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 | 33 | STAGING_SERVICE_ROOT = 'https://api.staging.launchpad.net/beta/' | 33 | STAGING_SERVICE_ROOT = 'https://api.staging.launchpad.net/beta/' |
191 | 34 | DEV_SERVICE_ROOT = 'https://api.launchpad.dev/beta/' | 34 | DEV_SERVICE_ROOT = 'https://api.launchpad.dev/beta/' |
192 | 35 | DOGFOOD_SERVICE_ROOT = 'https://api.dogfood.launchpad.net/beta/' | 35 | DOGFOOD_SERVICE_ROOT = 'https://api.dogfood.launchpad.net/beta/' |
193 | 36 | TEST_DEV_SERVICE_ROOT = 'http://api.launchpad.dev:8085/beta/' | ||
194 | 36 | 37 | ||
195 | 37 | LPNET_WEB_ROOT = 'https://launchpad.net/' | 38 | LPNET_WEB_ROOT = 'https://launchpad.net/' |
196 | 38 | EDGE_WEB_ROOT = 'https://edge.launchpad.net/' | 39 | EDGE_WEB_ROOT = 'https://edge.launchpad.net/' |
197 | 39 | STAGING_WEB_ROOT = 'https://staging.launchpad.net/' | 40 | STAGING_WEB_ROOT = 'https://staging.launchpad.net/' |
198 | 40 | DEV_WEB_ROOT = 'https://launchpad.dev/' | 41 | DEV_WEB_ROOT = 'https://launchpad.dev/' |
199 | 41 | DOGFOOD_WEB_ROOT = 'https://dogfood.launchpad.net/' | 42 | DOGFOOD_WEB_ROOT = 'https://dogfood.launchpad.net/' |
200 | 43 | TEST_DEV_WEB_ROOT = 'http://launchpad.dev:8085/' | ||
201 | 42 | 44 | ||
202 | 43 | 45 | ||
203 | 44 | service_roots = dict( | 46 | service_roots = dict( |
204 | @@ -47,6 +49,7 @@ | |||
205 | 47 | staging=STAGING_SERVICE_ROOT, | 49 | staging=STAGING_SERVICE_ROOT, |
206 | 48 | dogfood=DOGFOOD_SERVICE_ROOT, | 50 | dogfood=DOGFOOD_SERVICE_ROOT, |
207 | 49 | dev=DEV_SERVICE_ROOT, | 51 | dev=DEV_SERVICE_ROOT, |
208 | 52 | test_dev=TEST_DEV_SERVICE_ROOT | ||
209 | 50 | ) | 53 | ) |
210 | 51 | 54 | ||
211 | 52 | 55 | ||
212 | @@ -56,6 +59,7 @@ | |||
213 | 56 | staging=STAGING_WEB_ROOT, | 59 | staging=STAGING_WEB_ROOT, |
214 | 57 | dogfood=DOGFOOD_WEB_ROOT, | 60 | dogfood=DOGFOOD_WEB_ROOT, |
215 | 58 | dev=DEV_WEB_ROOT, | 61 | dev=DEV_WEB_ROOT, |
216 | 62 | test_dev=TEST_DEV_WEB_ROOT | ||
217 | 59 | ) | 63 | ) |
218 | 60 | 64 | ||
219 | 61 | 65 |
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.