pyramid/bodhi/bodhi/models/models.py | 23 ++++++++++++++++------
pyramid/bodhi/bodhi/resources.py | 15 +++++++++++++-
pyramid/bodhi/bodhi/tests/functional/test_wsgi.py | 7 ++++++
pyramid/bodhi/bodhi/tests/models/test_models.py | 5 +---
4 files changed, 40 insertions(+), 10 deletions(-)
New commits:
commit d2f7f4c71512205025671b8e122b6d51057f6cc9
Author: Luke Macken <lmacken(a)redhat.com>
Date: Tue May 17 16:41:20 2011 -0400
Add the ability to specify resource column filters
diff --git a/pyramid/bodhi/bodhi/resources.py b/pyramid/bodhi/bodhi/resources.py
index a14173a..6d15cad 100644
--- a/pyramid/bodhi/bodhi/resources.py
+++ b/pyramid/bodhi/bodhi/resources.py
@@ -25,9 +25,15 @@ class BodhiResource(object):
__parent__ = None
__model__ = None
__column__ = None
+ __filter__ = None
def __getitem__(self, key):
session = DBSession()
+ if self.__filter__:
+ try:
+ key = self.__filter__(key)
+ except:
+ raise KeyError(key)
try:
return session.query(self.__model__).filter_by(
**{self.__column__: key}).one()
commit 4b3e9a2ff5dddb711487cacfe9c25384b27e7e5e
Author: Luke Macken <lmacken(a)redhat.com>
Date: Tue May 17 16:41:13 2011 -0400
Add our BugResource, and tests
diff --git a/pyramid/bodhi/bodhi/models/models.py b/pyramid/bodhi/bodhi/models/models.py
index a54a557..57f594e 100644
--- a/pyramid/bodhi/bodhi/models/models.py
+++ b/pyramid/bodhi/bodhi/models/models.py
@@ -744,6 +744,7 @@ class Update(Base):
mail.send(self.get_maintainers(), 'unstable', self)
comment = Comment(text=text, karma=karma, anonymous=anonymous)
+
if anonymous:
author = u'anonymous'
try:
@@ -1017,6 +1018,9 @@ def populate():
session.add(build)
update = Update(builds=[build], user=user, notes=u'Useful details!')
update.type = UpdateType.bugfix
+ bug = Bug(bug_id=12345)
+ session.add(bug)
+ update.bugs.append(bug)
session.add(update)
session.commit()
#session.flush()
diff --git a/pyramid/bodhi/bodhi/resources.py b/pyramid/bodhi/bodhi/resources.py
index a918be3..a14173a 100644
--- a/pyramid/bodhi/bodhi/resources.py
+++ b/pyramid/bodhi/bodhi/resources.py
@@ -3,7 +3,7 @@ import logging
from sqlalchemy.orm.exc import NoResultFound
from bodhi.models import initialize_sql, DBSession
-from bodhi.models import Update, Package, Build, Release, User
+from bodhi.models import Update, Package, Build, Release, User, Bug
log = logging.getLogger(__name__)
@@ -55,6 +55,12 @@ class UserResource(BodhiResource):
__model__ = User
__column__ = u'name'
+class BugResource(BodhiResource):
+ __model__ = Bug
+ __column__ = u'bug_id'
+ __filter__ = int
+
+
root = BodhiRoot()
def default_get_root(request):
@@ -65,6 +71,7 @@ def default_get_root(request):
u'packages': PackageResource,
u'releases': ReleaseResource,
u'users': UserResource,
+ u'bugs': BugResource,
})
return root
diff --git a/pyramid/bodhi/bodhi/tests/functional/test_wsgi.py
b/pyramid/bodhi/bodhi/tests/functional/test_wsgi.py
index 7a21563..63e7d59 100644
--- a/pyramid/bodhi/bodhi/tests/functional/test_wsgi.py
+++ b/pyramid/bodhi/bodhi/tests/functional/test_wsgi.py
@@ -27,3 +27,10 @@ class FunctionalTests(unittest.TestCase):
data = json.loads(res.body)
eq_(data[u'entries'][0][u'name'], 'F15')
+ def test_releases_view_invalid_bug(self):
+ res = app.get('/bugs/abc', status=404)
+
+ def test_releases_view_bug(self):
+ res = app.get('/bugs/12345', status=200)
+ data = json.loads(res.body)
+ eq_(data[u'context'][u'bug_id'], 12345)
commit 66c00168512ee047e0b5cd41649a08974fa96888
Author: Luke Macken <lmacken(a)redhat.com>
Date: Tue May 17 15:50:35 2011 -0400
Update our comment api to work with our new user model
diff --git a/pyramid/bodhi/bodhi/models/models.py b/pyramid/bodhi/bodhi/models/models.py
index fdbbe97..a54a557 100644
--- a/pyramid/bodhi/bodhi/models/models.py
+++ b/pyramid/bodhi/bodhi/models/models.py
@@ -719,9 +719,9 @@ class Update(Base):
if not author:
author = identity.current.user_name
if not anonymous and karma != 0 and \
- not filter(lambda c: c.author == author and c.karma == karma,
+ not filter(lambda c: c.user.name == author and c.karma == karma,
self.comments):
- mycomments = [c.karma for c in self.comments if c.author == author]
+ mycomments = [c.karma for c in self.comments if c.user.name == author]
if karma == 1 and -1 in mycomments:
self.karma += 2
elif karma == -1 and 1 in mycomments:
@@ -743,8 +743,15 @@ class Update(Base):
self.obsolete()
mail.send(self.get_maintainers(), 'unstable', self)
- comment = Comment(text=text, karma=karma,author=author,
- anonymous=anonymous)
+ comment = Comment(text=text, karma=karma, anonymous=anonymous)
+ if anonymous:
+ author = u'anonymous'
+ try:
+ user = User.query.filter_by(name=author).one()
+ except NoResultFound:
+ user = User(name=author)
+ DBSession.add(user)
+ user.comments.append(comment)
DBSession.add(comment)
self.comments.append(comment)
@@ -755,9 +762,9 @@ class Update(Base):
for person in self.get_maintainers():
people.add(person)
for comment in self.comments:
- if comment.anonymous or comment.author == 'bodhi':
+ if comment.anonymous or comment.user.name == u'bodhi':
continue
- people.add(comment.author)
+ people.add(comment.user.name)
mail.send(people, 'comment', self)
def unpush(self):
diff --git a/pyramid/bodhi/bodhi/tests/models/test_models.py
b/pyramid/bodhi/bodhi/tests/models/test_models.py
index 03d91a1..ddd5a01 100644
--- a/pyramid/bodhi/bodhi/tests/models/test_models.py
+++ b/pyramid/bodhi/bodhi/tests/models/test_models.py
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
"""Test suite for the Bodhi models"""
-import os
import time
from nose.tools import eq_, raises
@@ -312,12 +311,12 @@ class TestUpdate(ModelTest):
self.obj.status = UpdateStatus.testing
self.obj.status_comment()
eq_(len(self.obj.comments), 1)
- eq_(self.obj.comments[0].author, u'bodhi')
+ eq_(self.obj.comments[0].user.name, u'bodhi')
eq_(self.obj.comments[0].text, u'This update has been pushed to
testing')
self.obj.status = UpdateStatus.stable
self.obj.status_comment()
eq_(len(self.obj.comments), 2)
- eq_(self.obj.comments[1].author, u'bodhi')
+ eq_(self.obj.comments[1].user.name, u'bodhi')
eq_(self.obj.comments[1].text, u'This update has been pushed to stable')
def test_get_url(self):