Merge lp:~jml/libdep-service/architecture into lp:libdep-service

Proposed by Jonathan Lange
Status: Merged
Merged at revision: 59
Proposed branch: lp:~jml/libdep-service/architecture
Merge into: lp:libdep-service
Diff against target: 202 lines (+73/-14)
7 files modified
.bzrignore (+1/-0)
djlibdep/api.py (+2/-2)
djlibdep/tests/test_interface.py (+21/-5)
djlibdep/tests/test_test_double.py (+4/-1)
djlibdep/tests/test_views.py (+15/-1)
djlibdep/views.py (+12/-3)
djlibdep/wrappers.py (+18/-2)
To merge this branch: bzr merge lp:~jml/libdep-service/architecture
Reviewer Review Type Date Requested Status
Canonical Consumer Applications Hackers Pending
Review via email: mp+129222@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2012-08-24 19:34:45 +0000
3+++ .bzrignore 2012-10-11 15:37:26 +0000
4@@ -12,3 +12,4 @@
5 ./eggs
6 ./parts
7 ./bin/*
8+dist
9
10=== modified file 'djlibdep/api.py'
11--- djlibdep/api.py 2012-09-11 14:48:05 +0000
12+++ djlibdep/api.py 2012-10-11 15:37:26 +0000
13@@ -17,13 +17,13 @@
14 from devportalbinary.database import PackageDatabase
15
16
17-def get_binaries_for_libraries(libs):
18+def get_binaries_for_libraries(libs, arch):
19 metrics = get_metrics()
20 db = PackageDatabase.create()
21 deps = {}
22 for lib in libs:
23 metrics.meter(lib)
24- deps_for_lib = db.get_dependencies(lib)
25+ deps_for_lib = db.get_dependencies(lib, arch)
26 if deps_for_lib:
27 deps[lib] = sorted(deps_for_lib)
28 else:
29
30=== modified file 'djlibdep/tests/test_interface.py'
31--- djlibdep/tests/test_interface.py 2012-09-28 14:01:42 +0000
32+++ djlibdep/tests/test_interface.py 2012-10-11 15:37:26 +0000
33@@ -1,7 +1,10 @@
34 """Test the HTTP interface of libdep-service."""
35
36 import json
37-from urllib2 import urlopen
38+from urllib2 import (
39+ HTTPError,
40+ urlopen,
41+ )
42
43 from devportalbinary.database import PackageDatabase
44 from devportalbinary.testing import (
45@@ -43,7 +46,8 @@
46
47 real_server_fixture = FixtureResource(
48 RealServerFixture(
49- [('libc', {'i386': {'libc.so.6': 'libc-bin'}}),
50+ [('libc', {'i386': {'libc.so.6': 'libc-bin'},
51+ 'amd64': {'libc.so.6': 'libc-amd64'}}),
52 ]))
53
54
55@@ -67,9 +71,21 @@
56
57 def test_found(self):
58 url = '%s/v1/get_binaries_for_libraries' % (self.server.base_url,)
59- url += '?libs=libc.so.6'
60- data = urlopen(url).read()
61- self.assertEqual(json.dumps({'libc.so.6': ['libc-bin']}), data)
62+ url += '?libs=libc.so.6&arch=i386'
63+ data = urlopen(url).read()
64+ self.assertEqual({'libc.so.6': ['libc-bin']}, json.loads(data))
65+
66+ def test_discriminates_by_architecture(self):
67+ url = '%s/v1/get_binaries_for_libraries' % (self.server.base_url,)
68+ url += '?libs=libc.so.6&arch=amd64'
69+ data = urlopen(url).read()
70+ self.assertEqual({'libc.so.6': ['libc-amd64']}, json.loads(data))
71+
72+ def test_too_many_architectures(self):
73+ url = '%s/v1/get_binaries_for_libraries' % (self.server.base_url,)
74+ url += '?libs=libc.so.6&arch=amd64&arch=i386'
75+ e = self.assertRaises(HTTPError, urlopen, url)
76+ self.assertEqual(400, e.code)
77
78
79 def load_tests(loader, tests, ignored):
80
81=== modified file 'djlibdep/tests/test_test_double.py'
82--- djlibdep/tests/test_test_double.py 2012-10-03 00:36:08 +0000
83+++ djlibdep/tests/test_test_double.py 2012-10-11 15:37:26 +0000
84@@ -18,7 +18,10 @@
85 'v1/service_check': [({}, 'Hello world!')],
86 'v1/get_binaries_for_libraries': [
87 ({'libs': ['doesnotexist']}, '{}'),
88- ({'libs': ['libc.so.6']}, '{"libc.so.6": ["libc-bin"]}'),
89+ ({'libs': ['libc.so.6'], 'arch': ['i386']},
90+ '{"libc.so.6": ["libc-bin"]}'),
91+ ({'libs': ['libc.so.6'], 'arch': ['amd64']},
92+ '{"libc.so.6": ["libc-amd64"]}'),
93 ],
94 }
95 test_double_fixture = FixtureResource(LibdepServiceDouble(TEST_DATA))
96
97=== modified file 'djlibdep/tests/test_views.py'
98--- djlibdep/tests/test_views.py 2012-09-17 15:37:28 +0000
99+++ djlibdep/tests/test_views.py 2012-10-11 15:37:26 +0000
100@@ -30,8 +30,9 @@
101
102 class SimpleTest(TestCase, WithDatabase):
103
104- def do_query(self, libs):
105+ def do_query(self, libs, arch='i386'):
106 query_params = [('libs', lib) for lib in libs]
107+ query_params.append(('arch', arch))
108 url = '/v1/get_binaries_for_libraries/?' + urlencode(query_params)
109 result = self.client.get(url)
110 self.assertEqual(200, result.status_code, result.content)
111@@ -48,6 +49,19 @@
112 {'libfoo': ['libfoo-bin'], 'libbar': ['libbar-bin']},
113 result)
114
115+ def test_architecture(self):
116+ db = self.get_package_db()
117+ db.update_package(
118+ 'libfoo-bin', {'i386': {'libfoo': 'libfoo-bin'},
119+ 'amd64': {'libfoo': 'libfoo-amd64'}})
120+ db.update_package(
121+ 'libbar-bin', {'i386': {'libbar': 'libbar-bin'},
122+ 'amd64': {'libbar': 'libbar-amd64'}})
123+ result = self.do_query(['libfoo', 'libbar'], arch='amd64')
124+ self.assertEqual(
125+ {'libfoo': ['libfoo-amd64'], 'libbar': ['libbar-amd64']},
126+ result)
127+
128 def test_ordering(self):
129 db = self.get_package_db()
130 db.update_package(
131
132=== modified file 'djlibdep/views.py'
133--- djlibdep/views.py 2012-09-11 14:45:39 +0000
134+++ djlibdep/views.py 2012-10-11 15:37:26 +0000
135@@ -24,7 +24,10 @@
136 concurrent_request,
137 timed,
138 )
139-from .wrappers import json_get_api
140+from .wrappers import (
141+ json_get_api,
142+ UserError,
143+ )
144
145
146 ALL_CLEAR = u'Hello world!'
147@@ -37,8 +40,14 @@
148 @json_get_api
149 @concurrent_request
150 @timed
151-def get_binaries_for_libraries(libs=(), **kwargs):
152- return api.get_binaries_for_libraries(libs)
153+def get_binaries_for_libraries(libs=(), arch=None, **kwargs):
154+ if arch is None:
155+ arch = ['i386']
156+ try:
157+ [arch] = arch
158+ except ValueError:
159+ raise UserError("Specify only one architecture, got %r" % (arch,))
160+ return api.get_binaries_for_libraries(libs, arch)
161
162
163 @json_get_api
164
165=== modified file 'djlibdep/wrappers.py'
166--- djlibdep/wrappers.py 2012-09-07 11:30:08 +0000
167+++ djlibdep/wrappers.py 2012-10-11 15:37:26 +0000
168@@ -12,10 +12,22 @@
169 # You should have received a copy of the GNU Affero General Public License
170 # along with this program. If not, see <http://www.gnu.org/licenses/>.
171
172+__all__ = [
173+ 'UserError',
174+ 'json_get_api',
175+ ]
176+
177 from functools import wraps
178 import json
179
180-from django.http import HttpResponse
181+from django.http import (
182+ HttpResponse,
183+ HttpResponseBadRequest,
184+ )
185+
186+
187+class UserError(Exception):
188+ """Raised when the user has submitted bad data."""
189
190
191 def json_get_api(function):
192@@ -23,5 +35,9 @@
193 @wraps(function)
194 def wrapped(request):
195 kwargs = request.GET
196- return HttpResponse(json.dumps(function(**kwargs)))
197+ try:
198+ result = function(**kwargs)
199+ except UserError, e:
200+ return HttpResponseBadRequest(str(e))
201+ return HttpResponse(json.dumps(result))
202 return wrapped

Subscribers

People subscribed via source and target branches