Merge lp:~leonardr/launchpadlib/find-length into lp:launchpadlib

Proposed by Leonard Richardson
Status: Merged
Approved by: Aaron Bentley
Approved revision: 96
Merged at revision: 96
Proposed branch: lp:~leonardr/launchpadlib/find-length
Merge into: lp:launchpadlib
Diff against target: 112 lines (+47/-3)
5 files modified
src/launchpadlib/NEWS.txt (+5/-0)
src/launchpadlib/__init__.py (+1/-1)
src/launchpadlib/docs/operations.txt (+27/-0)
src/launchpadlib/launchpad.py (+2/-2)
src/launchpadlib/tests/test_launchpad.py (+12/-0)
To merge this branch: bzr merge lp:~leonardr/launchpadlib/find-length
Reviewer Review Type Date Requested Status
Aaron Bentley (community) Approve
Review via email: mp+33440@code.launchpad.net

Description of the change

This branch fixes launchpadlib to start out with knowledge of all the special resource classes defined by lazr.restfulclient. The most recent launchpadlib release doesn't know about the ScalarValue resource class, because it wasn't specifically mentioned in Launchpad.RESOURCE_TYPE_CLASSES. Now Launchpad.R_T_C is always updated with whatever is in lazr.restful's ServiceRoot.R_T_C.

I added a unit test for this, and also an end-to-end pagetest (for ScalarValue in particular) that must be run in conjunction with Launchpad.

To post a comment you must log in.
Revision history for this message
Aaron Bentley (abentley) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/launchpadlib/NEWS.txt'
2--- src/launchpadlib/NEWS.txt 2010-08-17 20:21:12 +0000
3+++ src/launchpadlib/NEWS.txt 2010-08-23 19:59:40 +0000
4@@ -2,6 +2,11 @@
5 NEWS for launchpadlib
6 =====================
7
8+1.6.5 (2010-08-23)
9+==================
10+
11+- Make launchpadlib compatible with the latest lazr.restfulclient.
12+
13 1.6.4 (2010-08-18)
14 ==================
15
16
17=== modified file 'src/launchpadlib/__init__.py'
18--- src/launchpadlib/__init__.py 2010-08-17 20:23:54 +0000
19+++ src/launchpadlib/__init__.py 2010-08-23 19:59:40 +0000
20@@ -14,4 +14,4 @@
21 # You should have received a copy of the GNU Lesser General Public License
22 # along with launchpadlib. If not, see <http://www.gnu.org/licenses/>.
23
24-__version__ = '1.6.4'
25+__version__ = '1.6.5'
26
27=== added file 'src/launchpadlib/docs/operations.txt'
28--- src/launchpadlib/docs/operations.txt 1970-01-01 00:00:00 +0000
29+++ src/launchpadlib/docs/operations.txt 2010-08-23 19:59:40 +0000
30@@ -0,0 +1,27 @@
31+****************
32+Named operations
33+****************
34+
35+launchpadlib can transparently determine the size of the list even
36+when the size is not directly provided, but is only available through
37+a link.
38+
39+ >>> from launchpadlib.testing.helpers import salgado_with_full_permissions
40+ >>> launchpad = salgado_with_full_permissions.login(version="devel")
41+
42+ >>> results = launchpad.people.find(text='s')
43+ >>> 'total_size' in results._wadl_resource.representation.keys()
44+ False
45+ >>> 'total_size_link' in results._wadl_resource.representation.keys()
46+ True
47+ >>> len(results) > 1
48+ True
49+
50+Of course, launchpadlib can also determine the size when the size _is_
51+directly provided.
52+
53+ >>> results = launchpad.people.find(text='salgado')
54+ >>> 'total_size' in results._wadl_resource.representation.keys()
55+ True
56+ >>> len(results) == 1
57+ True
58
59=== modified file 'src/launchpadlib/launchpad.py'
60--- src/launchpadlib/launchpad.py 2010-07-14 12:23:11 +0000
61+++ src/launchpadlib/launchpad.py 2010-08-23 19:59:40 +0000
62@@ -27,7 +27,7 @@
63
64 from lazr.uri import URI
65 from lazr.restfulclient.resource import (
66- CollectionWithKeyBasedLookup, HostedFile, ServiceRoot)
67+ CollectionWithKeyBasedLookup, HostedFile, ScalarValue, ServiceRoot)
68 from launchpadlib.credentials import (
69 AccessToken, AnonymousAccessToken, Credentials,
70 AuthorizeRequestTokenWithBrowser)
71@@ -108,11 +108,11 @@
72 RESOURCE_TYPE_CLASSES = {
73 'bugs': BugSet,
74 'distributions': DistributionSet,
75- 'HostedFile': HostedFile,
76 'people': PersonSet,
77 'project_groups': ProjectGroupSet,
78 'projects': ProjectSet,
79 }
80+ RESOURCE_TYPE_CLASSES.update(ServiceRoot.RESOURCE_TYPE_CLASSES)
81
82 def __init__(self, credentials, service_root=uris.STAGING_SERVICE_ROOT,
83 cache=None, timeout=None, proxy_info=None,
84
85=== modified file 'src/launchpadlib/tests/test_launchpad.py'
86--- src/launchpadlib/tests/test_launchpad.py 2010-07-20 15:56:32 +0000
87+++ src/launchpadlib/tests/test_launchpad.py 2010-08-23 19:59:40 +0000
88@@ -24,6 +24,8 @@
89 import tempfile
90 import unittest
91
92+from lazr.restfulclient.resource import ServiceRoot
93+
94 from launchpadlib.credentials import (
95 AccessToken, AuthorizeRequestTokenWithBrowser, Credentials)
96 from launchpadlib.launchpad import Launchpad
97@@ -58,6 +60,16 @@
98 return launchpad
99
100
101+class TestResourceTypeClasses(unittest.TestCase):
102+ """launchpadlib must know about restfulclient's resource types."""
103+
104+ def test_resource_types(self):
105+ # Make sure that Launchpad knows about every special resource
106+ # class defined by lazr.restfulclient.
107+ for name, cls in ServiceRoot.RESOURCE_TYPE_CLASSES.items():
108+ self.assertEqual(Launchpad.RESOURCE_TYPE_CLASSES[name], cls)
109+
110+
111 class TestNameLookups(unittest.TestCase):
112 """Test the utility functions in the 'uris' module."""
113

Subscribers

People subscribed via source and target branches