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
=== modified file '.bzrignore'
--- .bzrignore 2012-08-24 19:34:45 +0000
+++ .bzrignore 2012-10-11 15:37:26 +0000
@@ -12,3 +12,4 @@
12./eggs12./eggs
13./parts13./parts
14./bin/*14./bin/*
15dist
1516
=== modified file 'djlibdep/api.py'
--- djlibdep/api.py 2012-09-11 14:48:05 +0000
+++ djlibdep/api.py 2012-10-11 15:37:26 +0000
@@ -17,13 +17,13 @@
17from devportalbinary.database import PackageDatabase17from devportalbinary.database import PackageDatabase
1818
1919
20def get_binaries_for_libraries(libs):20def get_binaries_for_libraries(libs, arch):
21 metrics = get_metrics()21 metrics = get_metrics()
22 db = PackageDatabase.create()22 db = PackageDatabase.create()
23 deps = {}23 deps = {}
24 for lib in libs:24 for lib in libs:
25 metrics.meter(lib)25 metrics.meter(lib)
26 deps_for_lib = db.get_dependencies(lib)26 deps_for_lib = db.get_dependencies(lib, arch)
27 if deps_for_lib:27 if deps_for_lib:
28 deps[lib] = sorted(deps_for_lib)28 deps[lib] = sorted(deps_for_lib)
29 else:29 else:
3030
=== modified file 'djlibdep/tests/test_interface.py'
--- djlibdep/tests/test_interface.py 2012-09-28 14:01:42 +0000
+++ djlibdep/tests/test_interface.py 2012-10-11 15:37:26 +0000
@@ -1,7 +1,10 @@
1"""Test the HTTP interface of libdep-service."""1"""Test the HTTP interface of libdep-service."""
22
3import json3import json
4from urllib2 import urlopen4from urllib2 import (
5 HTTPError,
6 urlopen,
7 )
58
6from devportalbinary.database import PackageDatabase9from devportalbinary.database import PackageDatabase
7from devportalbinary.testing import (10from devportalbinary.testing import (
@@ -43,7 +46,8 @@
4346
44real_server_fixture = FixtureResource(47real_server_fixture = FixtureResource(
45 RealServerFixture(48 RealServerFixture(
46 [('libc', {'i386': {'libc.so.6': 'libc-bin'}}),49 [('libc', {'i386': {'libc.so.6': 'libc-bin'},
50 'amd64': {'libc.so.6': 'libc-amd64'}}),
47 ]))51 ]))
4852
4953
@@ -67,9 +71,21 @@
6771
68 def test_found(self):72 def test_found(self):
69 url = '%s/v1/get_binaries_for_libraries' % (self.server.base_url,)73 url = '%s/v1/get_binaries_for_libraries' % (self.server.base_url,)
70 url += '?libs=libc.so.6'74 url += '?libs=libc.so.6&arch=i386'
71 data = urlopen(url).read()75 data = urlopen(url).read()
72 self.assertEqual(json.dumps({'libc.so.6': ['libc-bin']}), data)76 self.assertEqual({'libc.so.6': ['libc-bin']}, json.loads(data))
77
78 def test_discriminates_by_architecture(self):
79 url = '%s/v1/get_binaries_for_libraries' % (self.server.base_url,)
80 url += '?libs=libc.so.6&arch=amd64'
81 data = urlopen(url).read()
82 self.assertEqual({'libc.so.6': ['libc-amd64']}, json.loads(data))
83
84 def test_too_many_architectures(self):
85 url = '%s/v1/get_binaries_for_libraries' % (self.server.base_url,)
86 url += '?libs=libc.so.6&arch=amd64&arch=i386'
87 e = self.assertRaises(HTTPError, urlopen, url)
88 self.assertEqual(400, e.code)
7389
7490
75def load_tests(loader, tests, ignored):91def load_tests(loader, tests, ignored):
7692
=== modified file 'djlibdep/tests/test_test_double.py'
--- djlibdep/tests/test_test_double.py 2012-10-03 00:36:08 +0000
+++ djlibdep/tests/test_test_double.py 2012-10-11 15:37:26 +0000
@@ -18,7 +18,10 @@
18 'v1/service_check': [({}, 'Hello world!')],18 'v1/service_check': [({}, 'Hello world!')],
19 'v1/get_binaries_for_libraries': [19 'v1/get_binaries_for_libraries': [
20 ({'libs': ['doesnotexist']}, '{}'),20 ({'libs': ['doesnotexist']}, '{}'),
21 ({'libs': ['libc.so.6']}, '{"libc.so.6": ["libc-bin"]}'),21 ({'libs': ['libc.so.6'], 'arch': ['i386']},
22 '{"libc.so.6": ["libc-bin"]}'),
23 ({'libs': ['libc.so.6'], 'arch': ['amd64']},
24 '{"libc.so.6": ["libc-amd64"]}'),
22 ],25 ],
23 }26 }
24test_double_fixture = FixtureResource(LibdepServiceDouble(TEST_DATA))27test_double_fixture = FixtureResource(LibdepServiceDouble(TEST_DATA))
2528
=== modified file 'djlibdep/tests/test_views.py'
--- djlibdep/tests/test_views.py 2012-09-17 15:37:28 +0000
+++ djlibdep/tests/test_views.py 2012-10-11 15:37:26 +0000
@@ -30,8 +30,9 @@
3030
31class SimpleTest(TestCase, WithDatabase):31class SimpleTest(TestCase, WithDatabase):
3232
33 def do_query(self, libs):33 def do_query(self, libs, arch='i386'):
34 query_params = [('libs', lib) for lib in libs]34 query_params = [('libs', lib) for lib in libs]
35 query_params.append(('arch', arch))
35 url = '/v1/get_binaries_for_libraries/?' + urlencode(query_params)36 url = '/v1/get_binaries_for_libraries/?' + urlencode(query_params)
36 result = self.client.get(url)37 result = self.client.get(url)
37 self.assertEqual(200, result.status_code, result.content)38 self.assertEqual(200, result.status_code, result.content)
@@ -48,6 +49,19 @@
48 {'libfoo': ['libfoo-bin'], 'libbar': ['libbar-bin']},49 {'libfoo': ['libfoo-bin'], 'libbar': ['libbar-bin']},
49 result)50 result)
5051
52 def test_architecture(self):
53 db = self.get_package_db()
54 db.update_package(
55 'libfoo-bin', {'i386': {'libfoo': 'libfoo-bin'},
56 'amd64': {'libfoo': 'libfoo-amd64'}})
57 db.update_package(
58 'libbar-bin', {'i386': {'libbar': 'libbar-bin'},
59 'amd64': {'libbar': 'libbar-amd64'}})
60 result = self.do_query(['libfoo', 'libbar'], arch='amd64')
61 self.assertEqual(
62 {'libfoo': ['libfoo-amd64'], 'libbar': ['libbar-amd64']},
63 result)
64
51 def test_ordering(self):65 def test_ordering(self):
52 db = self.get_package_db()66 db = self.get_package_db()
53 db.update_package(67 db.update_package(
5468
=== modified file 'djlibdep/views.py'
--- djlibdep/views.py 2012-09-11 14:45:39 +0000
+++ djlibdep/views.py 2012-10-11 15:37:26 +0000
@@ -24,7 +24,10 @@
24 concurrent_request,24 concurrent_request,
25 timed,25 timed,
26 )26 )
27from .wrappers import json_get_api27from .wrappers import (
28 json_get_api,
29 UserError,
30 )
2831
2932
30ALL_CLEAR = u'Hello world!'33ALL_CLEAR = u'Hello world!'
@@ -37,8 +40,14 @@
37@json_get_api40@json_get_api
38@concurrent_request41@concurrent_request
39@timed42@timed
40def get_binaries_for_libraries(libs=(), **kwargs):43def get_binaries_for_libraries(libs=(), arch=None, **kwargs):
41 return api.get_binaries_for_libraries(libs)44 if arch is None:
45 arch = ['i386']
46 try:
47 [arch] = arch
48 except ValueError:
49 raise UserError("Specify only one architecture, got %r" % (arch,))
50 return api.get_binaries_for_libraries(libs, arch)
4251
4352
44@json_get_api53@json_get_api
4554
=== modified file 'djlibdep/wrappers.py'
--- djlibdep/wrappers.py 2012-09-07 11:30:08 +0000
+++ djlibdep/wrappers.py 2012-10-11 15:37:26 +0000
@@ -12,10 +12,22 @@
12# You should have received a copy of the GNU Affero General Public License12# You should have received a copy of the GNU Affero General Public License
13# along with this program. If not, see <http://www.gnu.org/licenses/>.13# along with this program. If not, see <http://www.gnu.org/licenses/>.
1414
15__all__ = [
16 'UserError',
17 'json_get_api',
18 ]
19
15from functools import wraps20from functools import wraps
16import json21import json
1722
18from django.http import HttpResponse23from django.http import (
24 HttpResponse,
25 HttpResponseBadRequest,
26 )
27
28
29class UserError(Exception):
30 """Raised when the user has submitted bad data."""
1931
2032
21def json_get_api(function):33def json_get_api(function):
@@ -23,5 +35,9 @@
23 @wraps(function)35 @wraps(function)
24 def wrapped(request):36 def wrapped(request):
25 kwargs = request.GET37 kwargs = request.GET
26 return HttpResponse(json.dumps(function(**kwargs)))38 try:
39 result = function(**kwargs)
40 except UserError, e:
41 return HttpResponseBadRequest(str(e))
42 return HttpResponse(json.dumps(result))
27 return wrapped43 return wrapped

Subscribers

People subscribed via source and target branches