launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #00800
[Merge] lp:~michael.nelson/launchpad/distro-series-difference-message into lp:launchpad
Michael Nelson has proposed merging lp:~michael.nelson/launchpad/distro-series-difference-message into lp:launchpad with lp:~michael.nelson/launchpad/distro-series-difference-basic-model as a prerequisite.
Requested reviews:
Brad Crittenden (bac)
Launchpad code reviewers (launchpad-reviewers)
Overview
========
Hi Brad or other reviewer :)
This branch adds the comment model for DistroSeriesDifferences, and then adds a IDistroSeriesDifference.addComment().
This is part of the work for:
https://dev.launchpad.net/LEP/DerivativeDistributions
To test:
bin/test -vv -m lp.registry.tests.test_distroseriesdifferencecomment -m lp.registry.tests.test_distroseriesdifference
No lint.
--
https://code.launchpad.net/~michael.nelson/launchpad/distro-series-difference-message/+merge/33929
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~michael.nelson/launchpad/distro-series-difference-message into lp:launchpad.
=== modified file 'lib/lp/registry/configure.zcml'
--- lib/lp/registry/configure.zcml 2010-08-27 16:58:45 +0000
+++ lib/lp/registry/configure.zcml 2010-08-27 16:58:47 +0000
@@ -113,6 +113,18 @@
class="lp.registry.model.distroseriesdifference.DistroSeriesDifference">
<allow interface="lp.registry.interfaces.distroseriesdifference.IDistroSeriesDifference"/>
</class>
+
+ <!-- DistroSeriesDifferenceComment -->
+ <securedutility
+ component="lp.registry.model.distroseriesdifferencecomment.DistroSeriesDifferenceComment"
+ provides="lp.registry.interfaces.distroseriesdifferencecomment.IDistroSeriesDifferenceCommentSource">
+ <allow interface="lp.registry.interfaces.distroseriesdifferencecomment.IDistroSeriesDifferenceCommentSource"/>
+ </securedutility>
+ <class
+ class="lp.registry.model.distroseriesdifferencecomment.DistroSeriesDifferenceComment">
+ <allow interface="lp.registry.interfaces.distroseriesdifferencecomment.IDistroSeriesDifferenceComment"/>
+ </class>
+
<class
class="lp.registry.model.distroseries.DistroSeries">
<allow
=== modified file 'lib/lp/registry/interfaces/distroseriesdifference.py'
--- lib/lp/registry/interfaces/distroseriesdifference.py 2010-08-27 16:58:45 +0000
+++ lib/lp/registry/interfaces/distroseriesdifference.py 2010-08-27 16:58:47 +0000
@@ -17,6 +17,7 @@
Choice,
Int,
Text,
+ TextLine,
)
from canonical.launchpad import _
@@ -81,6 +82,13 @@
description=_(
"The most recent published version in the parent series."))
+ title = TextLine(
+ title=_("Title"), readonly=True, required=False, description=_(
+ "A human-readable name describing this difference."))
+
+ def addComment(owner, comment):
+ """Add a comment on this difference."""
+
class IDistroSeriesDifferenceSource(Interface):
"""A utility of this interface can be used to create differences."""
@@ -105,4 +113,3 @@
is not a derived series.
:return: A new `DistroSeriesDifference` object.
"""
-
=== added file 'lib/lp/registry/interfaces/distroseriesdifferencecomment.py'
--- lib/lp/registry/interfaces/distroseriesdifferencecomment.py 1970-01-01 00:00:00 +0000
+++ lib/lp/registry/interfaces/distroseriesdifferencecomment.py 2010-08-27 16:58:47 +0000
@@ -0,0 +1,57 @@
+# Copyright 2010 Canonical Ltd. This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Distribution series difference messages."""
+
+__metaclass__ = type
+__all__ = [
+ 'IDistroSeriesDifferenceComment',
+ 'IDistroSeriesDifferenceCommentSource',
+ ]
+
+
+from lazr.restful.fields import Reference
+from zope.interface import Interface
+from zope.schema import (
+ Int,
+ Text,
+ )
+
+from canonical.launchpad import _
+from canonical.launchpad.interfaces.message import IMessage
+from lp.registry.interfaces.distroseriesdifference import (
+ IDistroSeriesDifference,
+ )
+
+
+class IDistroSeriesDifferenceComment(Interface):
+ """A comment for a distroseries difference record."""
+
+ id = Int(title=_('ID'), required=True, readonly=True)
+
+ distro_series_difference = Reference(
+ IDistroSeriesDifference, title=_("Distro series difference"),
+ required=True, readonly=True, description=_(
+ "The distro series difference to which this message "
+ "belongs."))
+ message = Reference(
+ IMessage, title=_("Message"), required=True, readonly=True,
+ description=_("A comment about this difference."))
+
+ comment = Text(
+ title=_("Comment text"), readonly=True, description=_(
+ "The comment text for the related distro series difference."))
+
+
+class IDistroSeriesDifferenceCommentSource(Interface):
+ """A utility of this interface can be used to create comments."""
+
+ def new(distro_series_difference, owner, comment):
+ """Create a new comment on a distro series difference.
+
+ :param distro_series_difference: The distribution series difference
+ that is being commented on.
+ :param owner: The person making the comment.
+ :param comment: The comment.
+ :return: A new `DistroSeriesDifferenceComment` object.
+ """
=== modified file 'lib/lp/registry/model/distroseriesdifference.py'
--- lib/lp/registry/model/distroseriesdifference.py 2010-08-27 16:58:45 +0000
+++ lib/lp/registry/model/distroseriesdifference.py 2010-08-27 16:58:47 +0000
@@ -14,8 +14,8 @@
Int,
Reference,
Storm,
- Unicode,
)
+from zope.component import getUtility
from zope.interface import (
classProvides,
implements,
@@ -32,6 +32,9 @@
IDistroSeriesDifference,
IDistroSeriesDifferenceSource,
)
+from lp.registry.interfaces.distroseriesdifferencecomment import (
+ IDistroSeriesDifferenceCommentSource,
+ )
class DistroSeriesDifference(Storm):
@@ -88,6 +91,19 @@
return self._getLatestSourcePub(for_parent=True)
@property
+ def title(self):
+ """See `IDistroSeriesDifference`."""
+ parent_name = self.derived_series.parent_series.displayname
+ return ("Difference between distroseries '%(parent_name)s' and "
+ "'%(derived_name)s' for package '%(pkg_name)s' "
+ "(%(versions)s)" % {
+ 'parent_name': parent_name,
+ 'derived_name': self.derived_series.displayname,
+ 'pkg_name': self.source_package_name.name,
+ 'versions': self._getVersions(),
+ })
+
+ @property
def activity_log(self):
"""See `IDistroSeriesDifference`."""
return u""
@@ -115,3 +131,8 @@
if self.parent_source_pub is not None:
parent_src_pub_ver = self.parent_source_pub.source_package_version
return parent_src_pub_ver + "/" + src_pub_ver
+
+ def addComment(self, owner, comment):
+ """See `IDistroSeriesDifference`."""
+ return getUtility(IDistroSeriesDifferenceCommentSource).new(
+ self, owner, comment)
=== added file 'lib/lp/registry/model/distroseriesdifferencecomment.py'
--- lib/lp/registry/model/distroseriesdifferencecomment.py 1970-01-01 00:00:00 +0000
+++ lib/lp/registry/model/distroseriesdifferencecomment.py 2010-08-27 16:58:47 +0000
@@ -0,0 +1,67 @@
+# Copyright 2010 Canonical Ltd. This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""A comment/message for a difference between two distribution series."""
+
+__metaclass__ = type
+
+__all__ = [
+ 'DistroSeriesDifferenceComment',
+ ]
+
+from email.Utils import make_msgid
+
+from storm.locals import (
+ Int,
+ Reference,
+ Storm,
+ )
+from zope.interface import (
+ classProvides,
+ implements,
+ )
+
+from canonical.launchpad.database.message import Message, MessageChunk
+from canonical.launchpad.interfaces.lpstorm import IMasterStore
+from lp.registry.interfaces.distroseriesdifferencecomment import (
+ IDistroSeriesDifferenceComment,
+ IDistroSeriesDifferenceCommentSource,
+ )
+
+
+class DistroSeriesDifferenceComment(Storm):
+ """See `IDistroSeriesDifferenceComment`."""
+ implements(IDistroSeriesDifferenceComment)
+ classProvides(IDistroSeriesDifferenceCommentSource)
+ __storm_table__ = 'DistroSeriesDifferenceMessage'
+
+ id = Int(primary=True)
+
+ distro_series_difference_id = Int(name='distro_series_difference',
+ allow_none=False)
+ distro_series_difference = Reference(
+ distro_series_difference_id, 'DistroSeriesDifference.id')
+
+ message_id = Int(name="message", allow_none=False)
+ message = Reference(message_id, 'Message.id')
+
+ @property
+ def comment(self):
+ """See `IDistroSeriesDifferenceComment`."""
+ return self.message.text_contents
+
+ @staticmethod
+ def new(distro_series_difference, owner, comment):
+ """See `IDistroSeriesDifferenceCommentSource`."""
+ msgid = make_msgid('distroseriesdifference')
+ message = Message(
+ parent=None, owner=owner, rfc822msgid=msgid,
+ subject=distro_series_difference.title)
+ MessageChunk(message=message, content=comment, sequence=1)
+
+ store = IMasterStore(DistroSeriesDifferenceComment)
+ dsd_comment = DistroSeriesDifferenceComment()
+ dsd_comment.distro_series_difference = distro_series_difference
+ dsd_comment.message = message
+
+ return store.add(dsd_comment)
=== modified file 'lib/lp/registry/tests/test_distroseriesdifference.py'
--- lib/lp/registry/tests/test_distroseriesdifference.py 2010-08-27 16:58:45 +0000
+++ lib/lp/registry/tests/test_distroseriesdifference.py 2010-08-27 16:58:47 +0000
@@ -51,7 +51,7 @@
self.assertRaises(
NotADerivedSeriesError, distroseriesdifference_factory.new,
distro_series, source_package_name,
- DistroSeriesDifferenceType.UNIQUE_TO_DERIVED_SERIES
+ DistroSeriesDifferenceType.UNIQUE_TO_DERIVED_SERIES,
)
def test_source_pub(self):
@@ -94,7 +94,7 @@
ds_diff.derived_series.parent_series,
ds_diff.parent_source_pub.distroseries)
- def test_paren_source_pub_gets_latest_pending(self):
+ def test_parent_source_pub_gets_latest_pending(self):
# The most recent publication is always returned, even if its pending.
ds_diff = self.factory.makeDistroSeriesDifference(
source_package_name_str="foonew")
@@ -105,6 +105,32 @@
self.assertEqual(pending_pub, ds_diff.parent_source_pub)
+ def test_title(self):
+ # The title is a friendly description of the difference.
+ parent_series = self.factory.makeDistroSeries(name="lucid")
+ derived_series = self.factory.makeDistroSeries(
+ parent_series=parent_series, name="derilucid")
+ ds_diff = self.factory.makeDistroSeriesDifference(
+ source_package_name_str="foonew", derived_series=derived_series,
+ versions={
+ 'parent': '1.0',
+ 'derived': '0.9',
+ })
+
+ self.assertEqual(
+ "Difference between distroseries 'Lucid' and 'Derilucid' "
+ "for package 'foonew' (1.0/0.9)", ds_diff.title)
+
+ def test_addComment(self):
+ # Adding a comment creates a new DistroSeriesDifferenceComment
+ ds_diff = self.factory.makeDistroSeriesDifference(
+ source_package_name_str="foonew")
+ person = self.factory.makePerson()
+
+ dsd_comment = ds_diff.addComment(person, "Wait until version 2.1")
+
+ self.assertEqual(ds_diff, dsd_comment.distro_series_difference)
+
def test_suite():
return unittest.TestLoader().loadTestsFromName(__name__)
=== added file 'lib/lp/registry/tests/test_distroseriesdifferencecomment.py'
--- lib/lp/registry/tests/test_distroseriesdifferencecomment.py 1970-01-01 00:00:00 +0000
+++ lib/lp/registry/tests/test_distroseriesdifferencecomment.py 2010-08-27 16:58:47 +0000
@@ -0,0 +1,44 @@
+# Copyright 2010 Canonical Ltd. This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Model tests for the DistroSeriesDifferenceComment class."""
+
+__metaclass__ = type
+
+from storm.store import Store
+
+from canonical.launchpad.webapp.testing import verifyObject
+from canonical.testing import DatabaseFunctionalLayer
+from lp.registry.interfaces.distroseriesdifferencecomment import (
+ IDistroSeriesDifferenceComment,
+ )
+from lp.testing import TestCaseWithFactory
+
+
+class DistroSeriesDifferenceCommentTestCase(TestCaseWithFactory):
+
+ layer = DatabaseFunctionalLayer
+
+ def test_implements_interface(self):
+ # The implementation implements the interface correctly.
+ dsd_comment = self.factory.makeDistroSeriesDifferenceComment()
+ # Flush the store to ensure db constraints are triggered.
+ Store.of(dsd_comment).flush()
+
+ verifyObject(IDistroSeriesDifferenceComment, dsd_comment)
+
+ def test_comment(self):
+ # The comment attribute returns the text of the comment.
+ dsd_comment = self.factory.makeDistroSeriesDifferenceComment(
+ comment="Wait until version 2.3")
+
+ self.assertEqual("Wait until version 2.3", dsd_comment.comment)
+
+ def test_subject(self):
+ # The subject of the message is set from the distro series diff
+ # title.
+ dsd_comment = self.factory.makeDistroSeriesDifferenceComment()
+
+ self.assertEqual(
+ dsd_comment.distro_series_difference.title,
+ dsd_comment.message.subject)
=== modified file 'lib/lp/testing/factory.py'
--- lib/lp/testing/factory.py 2010-08-27 16:58:45 +0000
+++ lib/lp/testing/factory.py 2010-08-27 16:58:47 +0000
@@ -162,6 +162,13 @@
from lp.registry.interfaces.distroseriesdifference import (
IDistroSeriesDifferenceSource,
)
+from lp.registry.interfaces.distroseriesdifferencecomment import (
+ IDistroSeriesDifferenceCommentSource,
+ )
+from lp.registry.interfaces.gpg import (
+ GPGKeyAlgorithm,
+ IGPGKeySet,
+ )
from lp.registry.interfaces.mailinglist import (
IMailingListSet,
MailingListStatus,
@@ -1851,6 +1858,19 @@
return getUtility(IDistroSeriesDifferenceSource).new(
derived_series, source_package_name, difference_type)
+ def makeDistroSeriesDifferenceComment(
+ self, distro_series_difference=None, owner=None, comment=None):
+ """Create a new distro series difference comment."""
+ if distro_series_difference is None:
+ distro_series_difference = self.makeDistroSeriesDifference()
+ if owner is None:
+ owner = self.makePerson()
+ if comment is None:
+ comment = self.getUniqueString('dsdcomment')
+
+ return getUtility(IDistroSeriesDifferenceCommentSource).new(
+ distro_series_difference, owner, comment)
+
def makeDistroArchSeries(self, distroseries=None,
architecturetag=None, processorfamily=None,
official=True, owner=None,
Follow ups