bodhi/model.py | 19 +++++++++-------
bodhi/tests/test_controllers.py | 47 ++++++++++++++++++++++++++++++++++++----
bodhi/tools/metrics.py | 1
3 files changed, 55 insertions(+), 12 deletions(-)
New commits:
commit 6899d5963fc49d6bc502f002076118098d348f30
Author: Luke Macken <lmacken(a)redhat.com>
Date: Tue Sep 14 17:41:19 2010 -0400
Refactor some of our karma code, allowing people to revert their karma more
than once (#480)
diff --git a/bodhi/model.py b/bodhi/model.py
index c03e194..56acd88 100644
--- a/bodhi/model.py
+++ b/bodhi/model.py
@@ -779,15 +779,18 @@ class PackageUpdate(SQLObject):
# in which case this block is not necessary
pass
- if not anonymous and karma != 0 and \
- not filter(lambda c: c.author == author and c.karma == karma,
- self.comments):
+ if not anonymous and karma != 0:
mycomments = [c.karma for c in self.comments if c.author == author
- and not c.anonymous]
- if karma == 1 and -1 in mycomments:
- self.karma += 2
- elif karma == -1 and 1 in mycomments:
- self.karma -= 2
+ and not c.anonymous and c.karma != 0]
+ if mycomments:
+ if karma == 1 and mycomments[-1] == -1:
+ self.karma += 2
+ elif karma == -1 and mycomments[-1] == 1:
+ self.karma -= 2
+ elif mycomments[-1] == self.karma:
+ pass
+ else:
+ self.karma += karma
else:
self.karma += karma
log.info("Updated %s karma to %d" % (self.title, self.karma))
diff --git a/bodhi/tests/test_controllers.py b/bodhi/tests/test_controllers.py
index 8626b84..e29b15a 100644
--- a/bodhi/tests/test_controllers.py
+++ b/bodhi/tests/test_controllers.py
@@ -241,14 +241,15 @@ class TestControllers(testutil.DBTest):
update = PackageUpdate.byTitle(params['builds'])
assert update.karma == -1
- # don't let them do it again
+ # let them change their -1 to a +1
x =
testutil.create_request('/updates/comment?text=bizbaz&title=%s&karma=1' %
params['builds'], method='POST',
headers=session)
update = PackageUpdate.byTitle(params['builds'])
- assert update.karma == -1
+ assert update.karma == 1, update.karma
- # Add a new comment, and make sure we can access the comments in the proper
order
+ # Add a new comment, and make sure we can access the comments in the
+ # proper order
x =
testutil.create_request('/updates/comment?text=woopdywoop&title=%s' %
params['builds'], method='POST',
headers=session)
@@ -2231,10 +2232,48 @@ class TestControllers(testutil.DBTest):
assert PackageUpdate.byTitle(params['builds']).karma == 1
# have the submitter +1 the update
+ #testutil.capture_log(['bodhi.controller', 'bodhi.util'])
testutil.create_request('/updates/comment?text=foobar&title=%s&karma=1' %
params['builds'], method='POST',
headers=session)
up = PackageUpdate.byTitle(params['builds'])
- assert up.karma == 3
+ #assert False, testutil.get_log()
+ assert up.karma == 3, up.karma
+
+ def test_reverting_karma(self):
+ """
+ Ensure that a developer can give negative karma, and then proceed to
+ later give positive karma.
+ """
+ session = login()
+ create_release()
+ params = {
+ 'builds' : 'TurboGears-1.0.8-1.fc7',
+ 'release' : 'Fedora 7',
+ 'type_' : 'bugfix',
+ 'bugs' : '',
+ 'notes' : 'foobar',
+ 'request' : 'Stable',
+ 'autokarma' : True,
+ 'stable_karma' : 5,
+ 'unstable_karma' : -5
+ }
+ self.save_update(params, session)
+ assert PackageUpdate.byTitle(params['builds']).karma == 0
+
+
testutil.create_request('/updates/comment?text=bar&title=%s&karma=1' %
+ params['builds'], method='POST',
+ headers=session)
+ assert PackageUpdate.byTitle(params['builds']).karma == 1
+
+
testutil.create_request('/updates/comment?text=bar&title=%s&karma=-1' %
+ params['builds'], method='POST',
+ headers=session)
+ assert PackageUpdate.byTitle(params['builds']).karma == -1
+
+
testutil.create_request('/updates/comment?text=bar&title=%s&karma=1' %
+ params['builds'], method='POST',
+ headers=session)
+ assert PackageUpdate.byTitle(params['builds']).karma == 1,
PackageUpdate.byTitle(params['builds']).karma
def test_suggest_reboot(self):
session = login()
commit 0f59a166e16d84f25fffed717c3ae1ce1d65316b
Author: Luke Macken <lmacken(a)redhat.com>
Date: Tue Sep 14 16:04:57 2010 -0400
Display the # of fixed bugs in our metrics report
diff --git a/bodhi/tools/metrics.py b/bodhi/tools/metrics.py
index 871fbe3..34fa9c3 100755
--- a/bodhi/tools/metrics.py
+++ b/bodhi/tools/metrics.py
@@ -143,6 +143,7 @@ def main():
for type in types:
print " * %d %s updates (%0.2f%%)" % (data['num_%s' %
type], type,
float(data['num_%s' % type]) / data['num_updates'] *
100)
+ print " * %d bugs resolved" % len(data['bugs'])
print " * %d critical path updates (%0.2f%%)" %
(data['num_critpath'],
float(data['num_critpath']) / data['num_updates'] * 100)
print " * %d approved critical path updates" % (