bodhi/controllers.py | 20 ++++++++++++++++++++
bodhi/tests/test_controllers.py | 29 +++++++++++++++++++++++++++++
2 files changed, 49 insertions(+)
New commits:
commit b91a7f7c5d02addff785226eb60842778f531f0a
Author: Luke Macken <lmacken(a)redhat.com>
Date: Mon May 4 18:57:02 2009 -0400
Add a get_updates_from_builds JSON method, along with a test case.
diff --git a/bodhi/controllers.py b/bodhi/controllers.py
index 5da54b2..24d5fa0 100644
--- a/bodhi/controllers.py
+++ b/bodhi/controllers.py
@@ -179,6 +179,26 @@ class Root(controllers.RootController):
identity.current.logout()
raise redirect('/')
+ @expose('json')
+ @validate(validators={'builds': validators.UnicodeString()})
+ def get_updates_from_builds(self, builds=''):
+ """Given a list of build nvrs, return the corresponding updates.
+
+ :builds: A space-delimited list of builds in the format of
+ name-version-release
+
+ :returns: A dictionary in the format of {build: update_data}
+ """
+ updates = {}
+ for build in builds.split():
+ try:
+ b = PackageBuild.byNvr(build)
+ for update in b.updates:
+ updates[build] = update.__json__()
+ except SQLObjectNotFound:
+ pass
+ return updates
+
@expose(template="bodhi.templates.list", allow_json=True)
@paginate('updates', limit=20, max_limit=50, allow_limit_override=True)
@validate(validators={
diff --git a/bodhi/tests/test_controllers.py b/bodhi/tests/test_controllers.py
index 2faad59..7991460 100644
--- a/bodhi/tests/test_controllers.py
+++ b/bodhi/tests/test_controllers.py
@@ -1160,3 +1160,32 @@ class TestControllers(testutil.DBTest):
self.save_update(params, session)
update = PackageUpdate.byTitle(params['builds'])
assert update
+
+ def test_get_updates_from_builds(self):
+ session = login()
+ create_release()
+ params = {
+ 'builds' : 'TurboGears-1.0.2.2-2.fc7',
+ 'release' : 'Fedora 7',
+ 'type_' : 'enhancement',
+ 'bugs' : '1234',
+ 'cves' : 'CVE-2020-0001',
+ 'notes' : 'foobar'
+ }
+ self.save_update(params, session)
+ params = {
+ 'builds' : 'kernel-2.6.29.1-111.fc7.x86_64',
+ 'release' : 'Fedora 7',
+ 'type_' : 'enhancement',
+ 'bugs' : '1234',
+ 'notes' : 'New kernel.'
+ }
+ self.save_update(params, session)
+ testutil.create_request('/updates/get_updates_from_builds?builds=' +
+ 'kernel-2.6.29.1-111.fc7.x86_64%20TurboGears-1.0.2.2-2.fc7',
+ method='POST')
+ import simplejson
+ json = simplejson.loads(cherrypy.response.body[0])
+ assert 'kernel-2.6.29.1-111.fc7.x86_64' in json
+ assert 'TurboGears-1.0.2.2-2.fc7' in json
+ assert json['TurboGears-1.0.2.2-2.fc7']['notes'] ==
'foobar'