Merge lp:~leonardr/launchpadlib/test-failures into lp:launchpadlib

Proposed by Leonard Richardson
Status: Merged
Merged at revision: not available
Proposed branch: lp:~leonardr/launchpadlib/test-failures
Merge into: lp:launchpadlib
Diff against target: 107 lines (+34/-12)
2 files modified
src/launchpadlib/launchpad.py (+14/-10)
src/launchpadlib/tests/test_launchpad.py (+20/-2)
To merge this branch: bzr merge lp:~leonardr/launchpadlib/test-failures
Reviewer Review Type Date Requested Status
Gary Poster Approve
Review via email: mp+16303@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Leonard Richardson (leonardr) wrote :

This branch fixes some miscellaneous test failures I caused by running the launchpadlib doctests but not the unit tests. I also added a unit test that tests the anonymous login code, and changed login_anonymously so it would work with NoNetworkLaunchpad.

79. By Leonard Richardson

Fixed typo.

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

merge-conditional

Looks good.

There's a formatting problem in line 39 of diff (should be two lines). Fix that and land it and I'll make the release!

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/launchpad.py'
2--- src/launchpadlib/launchpad.py 2009-12-17 16:52:54 +0000
3+++ src/launchpadlib/launchpad.py 2009-12-17 19:04:11 +0000
4@@ -177,11 +177,12 @@
5 cls, consumer_name, service_root=uris.STAGING_SERVICE_ROOT,
6 launchpadlib_dir=None, timeout=None, proxy_info=None):
7 """Get access to Launchpad without providing any credentials."""
8- service_root, service_root_dir, cache_path = cls._get_paths(
9- service_root, launchpadlib_dir)
10+ (service_root, launchpadlib_dir, cache_path,
11+ service_root_dir) = cls._get_paths(service_root, launchpadlib_dir)
12 token = AnonymousAccessToken()
13 credentials = Credentials(consumer_name, access_token=token)
14- return cls(credentials, service_root, cache_path, timeout, proxy_info)
15+ return cls(credentials, service_root=service_root, cache=cache_path,
16+ timeout=timeout, proxy_info=proxy_info)
17
18 @classmethod
19 def login_with(cls, consumer_name,
20@@ -224,8 +225,8 @@
21 :rtype: `Launchpad`
22
23 """
24- service_root, service_root_dir, cache_path = cls._get_paths(
25- service_root, launchpadlib_dir)
26+ (service_root, launchpadlib_dir, cache_path,
27+ service_root_dir) = cls._get_paths(service_root, launchpadlib_dir)
28 credentials_path = os.path.join(service_root_dir, 'credentials')
29 if not os.path.exists(credentials_path):
30 os.makedirs(credentials_path)
31@@ -261,10 +262,13 @@
32 :param service_root: The service root the user wants to
33 connect to. This may be an alias (which will be
34 dereferenced to a URL and returned) or a URL (which will
35- be returned as is).
36- :param launchpadlib_dir: The user's base launchpadlib directory,
37- if known.
38- :return: A 3-tuple: (service_root_uri, cache_dir, service_root_dir)
39+ be returned as is). :param launchpadlib_dir: The user's
40+ base launchpadlib directory, if known. This may be
41+ modified, expanded, or determined from the environment if
42+ missing. A definitive value will be returned.
43+
44+ :return: A 4-tuple:
45+ (service_root_uri, launchpadlib_dir, cache_dir, service_root_dir)
46 """
47 if launchpadlib_dir is None:
48 home_dir = os.environ['HOME']
49@@ -282,4 +286,4 @@
50 cache_path = os.path.join(service_root_dir, 'cache')
51 if not os.path.exists(cache_path):
52 os.makedirs(cache_path)
53- return (service_root, cache_path, service_root_dir)
54+ return (service_root, launchpadlib_dir, cache_path, service_root_dir)
55
56=== modified file 'src/launchpadlib/tests/test_launchpad.py'
57--- src/launchpadlib/tests/test_launchpad.py 2009-12-03 15:46:27 +0000
58+++ src/launchpadlib/tests/test_launchpad.py 2009-12-17 19:04:11 +0000
59@@ -24,7 +24,8 @@
60 import tempfile
61 import unittest
62
63-from launchpadlib.credentials import AccessToken, Credentials
64+from launchpadlib.credentials import (
65+ AccessToken, AuthorizeRequestTokenWithBrowser, Credentials)
66 from launchpadlib.launchpad import Launchpad
67 from launchpadlib import uris
68
69@@ -62,7 +63,7 @@
70
71 def setUp(self):
72 self.aliases = sorted(
73- ['production', 'edge', 'staging', 'dogfood', 'dev'])
74+ ['production', 'edge', 'staging', 'dogfood', 'dev', 'test_dev'])
75
76 def test_short_names(self):
77 # Ensure the short service names are all supported.
78@@ -157,12 +158,29 @@
79 service_root=service_root, timeout=timeout, proxy_info=proxy_info)
80 self.assertEqual(launchpad.consumer_name, 'app name')
81 expected_arguments = dict(
82+ allow_access_levels=[],
83+ authorizer_class=AuthorizeRequestTokenWithBrowser,
84+ max_failed_attempts=3,
85 service_root=service_root,
86 timeout=timeout,
87 proxy_info=proxy_info,
88 cache=os.path.join(self.temp_dir, 'api.example.com', 'cache'))
89 self.assertEqual(launchpad.passed_in_kwargs, expected_arguments)
90
91+ def test_anonymous_login(self):
92+ """Test the anonymous login helper function."""
93+ launchpad = NoNetworkLaunchpad.login_anonymously(
94+ 'anonymous access', launchpadlib_dir=self.temp_dir,
95+ service_root='http://api.example.com/beta')
96+ self.assertEqual(launchpad.credentials.access_token.key, '')
97+ self.assertEqual(launchpad.credentials.access_token.secret, '')
98+
99+ # Test that anonymous credentials are not saved.
100+ credentials_path = os.path.join(
101+ self.temp_dir, 'api.example.com', 'credentials',
102+ 'anonymous access')
103+ self.assertFalse(os.path.exists(credentials_path))
104+
105 def test_new_credentials_are_saved(self):
106 # After get_token_and_login() have been called, the created
107 # credentials are saved.

Subscribers

People subscribed via source and target branches