launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #00614
[Merge] lp:~jtv/launchpad/recife-karmarecorder-fix into lp:~launchpad/launchpad/recife
Jeroen T. Vermeulen has proposed merging lp:~jtv/launchpad/recife-karmarecorder-fix into lp:~launchpad/launchpad/recife.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers): code
= KarmaRecorder test and fix =
In the Recife feature branch we use a new test helper class, the KarmaRecorder, to keep track of what karma is assigned. It turns out that this class was slightly broken (filtering by person simply wasn't implemented) and entirely untested.
Here I fix that. To test,
{{{
./bin/test -vvc -m lp.testing.tests.test_karma
}}}
No lint.
Jeroen
--
https://code.launchpad.net/~jtv/launchpad/recife-karmarecorder-fix/+merge/32756
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jtv/launchpad/recife-karmarecorder-fix into lp:~launchpad/launchpad/recife.
=== modified file 'lib/lp/testing/karma.py'
--- lib/lp/testing/karma.py 2010-03-25 15:27:52 +0000
+++ lib/lp/testing/karma.py 2010-08-16 12:41:09 +0000
@@ -53,6 +53,7 @@
def filter(self, karma):
"""Does `karma` match our filters?"""
return (
+ self._filterFor(self.person, karma.person) and
self._filterFor(self.action_name, karma.action.name) and
self._filterFor(self.product, karma.product) and
self._filterFor(self.distribution, karma.distribution) and
@@ -69,7 +70,7 @@
def receive(self, obj, event):
"""Process a karma event.
-
+
Runs `filter` on the event and if it passes, `record`s it.
"""
if self.filter(event.karma):
@@ -106,6 +107,7 @@
A set of KarmaAction objects assigned since the register_listener()
method was called is available in the added_listener_actions property.
"""
+
def __init__(self, show_person=False):
super(KarmaAssignedEventListener, self).__init__()
self.added_karma_actions = set()
=== added file 'lib/lp/testing/tests/test_karma.py'
--- lib/lp/testing/tests/test_karma.py 1970-01-01 00:00:00 +0000
+++ lib/lp/testing/tests/test_karma.py 2010-08-16 12:41:09 +0000
@@ -0,0 +1,122 @@
+# Copyright 2010 Canonical Ltd. This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""XXX: Module docstring goes here."""
+
+__metaclass__ = type
+
+from canonical.testing import DatabaseFunctionalLayer
+from lp.testing import TestCaseWithFactory
+from lp.testing.fakemethod import FakeMethod
+
+
+class TestKarmaRecorder(TestCaseWithFactory):
+ layer = DatabaseFunctionalLayer
+
+ def test_record(self):
+ person = self.factory.makePerson()
+ product = self.factory.makeProduct()
+
+ recorder = self.installKarmaRecorder()
+ person.assignKarma('bugcreated', product=product)
+
+ self.assertEqual(1, len(recorder.karma_events))
+ karma = recorder.karma_events[0]
+ self.assertEqual(person, karma.person)
+ self.assertEqual(product, karma.product)
+
+ def test_record_person(self):
+ person = self.factory.makePerson()
+ unrelated_person = self.factory.makePerson()
+ product = self.factory.makeProduct()
+
+ recorder = self.installKarmaRecorder(person=person)
+ person.assignKarma('bugfixed', product=product)
+ unrelated_person.assignKarma('bugfixed', product=product)
+
+ self.assertEqual(1, len(recorder.karma_events))
+ karma = recorder.karma_events[0]
+ self.assertEqual(person, karma.person)
+
+ def test_record_action_name(self):
+ person = self.factory.makePerson()
+ product = self.factory.makeProduct()
+
+ recorder = self.installKarmaRecorder(action_name='bugrejected')
+ person.assignKarma('bugrejected', product=product)
+ person.assignKarma('bugaccepted', product=product)
+
+ self.assertEqual(1, len(recorder.karma_events))
+ karma = recorder.karma_events[0]
+ self.assertEqual('bugrejected', karma.action.name)
+
+ def test_record_product(self):
+ person = self.factory.makePerson()
+ product = self.factory.makeProduct()
+ other_product = self.factory.makeProduct()
+ package = self.factory.makeDistributionSourcePackage()
+
+ recorder = self.installKarmaRecorder(product=product)
+ person.assignKarma('faqcreated', product=other_product)
+ person.assignKarma('faqcreated', product=product)
+ person.assignKarma(
+ 'faqcreated', sourcepackagename=package.sourcepackagename,
+ distribution=package.distribution)
+
+ self.assertEqual(1, len(recorder.karma_events))
+ karma = recorder.karma_events[0]
+ self.assertEqual(product, karma.product)
+
+ def test_record_distribution(self):
+ person = self.factory.makePerson()
+ product = self.factory.makeProduct()
+ package = self.factory.makeDistributionSourcePackage()
+ distro = package.distribution
+ other_distro = self.factory.makeDistribution()
+
+ recorder = self.installKarmaRecorder(distribution=distro)
+ person.assignKarma(
+ 'faqcreated', distribution=distro,
+ sourcepackagename=package.sourcepackagename)
+ person.assignKarma(
+ 'faqcreated', distribution=other_distro,
+ sourcepackagename=package.sourcepackagename)
+ person.assignKarma('faqcreated', product=product)
+
+ self.assertEqual(1, len(recorder.karma_events))
+ karma = recorder.karma_events[0]
+ self.assertEqual(distro, karma.distribution)
+
+ def test_record_sourcepackagename(self):
+ person = self.factory.makePerson()
+ product = self.factory.makeProduct()
+ package = self.factory.makeDistributionSourcePackage()
+ packagename = package.sourcepackagename
+ other_packagename = self.factory.makeSourcePackageName()
+
+ recorder = self.installKarmaRecorder(sourcepackagename=packagename)
+ person.assignKarma(
+ 'faqcreated', distribution=package.distribution,
+ sourcepackagename=packagename)
+ person.assignKarma(
+ 'faqcreated', distribution=package.distribution,
+ sourcepackagename=other_packagename)
+ person.assignKarma('faqcreated', product=product)
+
+ self.assertEqual(1, len(recorder.karma_events))
+ karma = recorder.karma_events[0]
+ self.assertEqual(packagename, karma.sourcepackagename)
+
+ def test_record_can_be_replaced(self):
+ person = self.factory.makePerson()
+ product = self.factory.makeProduct()
+
+ recorder = self.installKarmaRecorder()
+ recorder.record = FakeMethod()
+
+ person.assignKarma('faqedited', product=product)
+ self.assertEqual(1, recorder.record.call_count)
+ call_args, call_kwargs = recorder.record.calls[0]
+ self.assertEqual(1, len(call_args))
+ self.assertEqual({}, call_kwargs)
+ self.assertEqual('faqedited', call_args[0].action.name)