Merge lp:~michael.nelson/launchpad/distro-series-difference-model into lp:launchpad/db-devel
- distro-series-difference-model
- Merge into db-devel
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Aaron Bentley | ||||
Approved revision: | no longer in the source branch. | ||||
Merged at revision: | 9729 | ||||
Proposed branch: | lp:~michael.nelson/launchpad/distro-series-difference-model | ||||
Merge into: | lp:launchpad/db-devel | ||||
Prerequisite: | lp:~michael.nelson/launchpad/distro-series-difference-message | ||||
Diff against target: |
509 lines (+280/-32) 6 files modified
lib/lp/registry/configure.zcml (+4/-1) lib/lp/registry/interfaces/distroseriesdifference.py (+46/-7) lib/lp/registry/model/distroseriesdifference.py (+61/-16) lib/lp/registry/tests/test_distroseriesdifference.py (+159/-5) lib/lp/registry/tests/test_distroseriesdifferencecomment.py (+2/-0) lib/lp/testing/factory.py (+8/-3) |
||||
To merge this branch: | bzr merge lp:~michael.nelson/launchpad/distro-series-difference-model | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Aaron Bentley (community) | Approve | ||
Review via email: mp+34086@code.launchpad.net |
Commit message
Restrict DistroSeriesDif
Description of the change
Overview
========
This branch ensures that comments can only be added to a DistroSeriesDif
It also adds a getComments() method, and a method to update the status and/or type of difference based on any new publishings.
This branch follows on from:
https:/
Test:
bin/test -vv -m test_distroseri
No lint.
Aaron Bentley (abentley) wrote : | # |
Michael Nelson (michael.nelson) wrote : | # |
On Mon, Aug 30, 2010 at 7:18 PM, Aaron Bentley <email address hidden> wrote:
> Why are source_version and parent_
They were originally returning None (as you saw by the test comment
below), but I'd thought for comparisons etc., it would be more
consistent if these properties always resulted in a string - an empty
one if there is no version. Anyway, I've switched them back to return
None.
>
> Why not implement getComments directly instead of indirecting through IDistroSeriesDi
Because there's no reason why DistroSeriesDif
about the implementation of DistroSeriesDif
interfaces, not implementations", "Depend on abstractions, do not
depend on concrete classes", etc.)
Currently DistroSeriesDif
does it do any storm queries directly. I thought that was a good
thing, but can change it if you want.
>
> Your test comments say None, but test for the empty string. Please fix either the test or the comment.
Tests updated to expect None.
>
> Why assertIs(True, was_updated) instead of assertTrue(
My bad.
>
> Why assertIs(True, was_updated) instead of assertTrue(
Ditto.
Thanks Aaron.
1 | === modified file 'lib/lp/registry/model/distroseriesdifference.py' |
2 | --- lib/lp/registry/model/distroseriesdifference.py 2010-08-30 15:09:17 +0000 |
3 | +++ lib/lp/registry/model/distroseriesdifference.py 2010-08-31 07:16:47 +0000 |
4 | @@ -128,14 +128,14 @@ |
5 | """See `IDistroSeriesDifference`.""" |
6 | if self.source_pub: |
7 | return self.source_pub.source_package_version |
8 | - return '' |
9 | + return None |
10 | |
11 | @property |
12 | def parent_source_version(self): |
13 | """See `IDistroSeriesDifference`.""" |
14 | if self.parent_source_pub: |
15 | return self.parent_source_pub.source_package_version |
16 | - return '' |
17 | + return None |
18 | |
19 | def updateStatusAndType(self): |
20 | """See `IDistroSeriesDifference`.""" |
21 | |
22 | === modified file 'lib/lp/registry/tests/test_distroseriesdifference.py' |
23 | --- lib/lp/registry/tests/test_distroseriesdifference.py 2010-08-30 15:09:17 +0000 |
24 | +++ lib/lp/registry/tests/test_distroseriesdifference.py 2010-08-31 07:36:32 +0000 |
25 | @@ -130,7 +130,7 @@ |
26 | difference_type=( |
27 | DistroSeriesDifferenceType.MISSING_FROM_DERIVED_SERIES)) |
28 | |
29 | - self.assertEqual('', ds_diff.source_version) |
30 | + self.assertEqual(None, ds_diff.source_version) |
31 | |
32 | def test_updateStatusAndType_resolves_difference(self): |
33 | # Status is set to resolved when versions match. |
34 | @@ -148,7 +148,7 @@ |
35 | |
36 | was_updated = ds_diff.updateStatusAndType() |
37 | |
38 | - self.assertIs(True, was_updated) |
39 | + self.assertTrue(was_updated) |
40 | self.assertEqual( |
41 | DistroSeriesDifferenceStatus.RESOLVED, |
42 | ds_diff.status) |
43 | @@ -171,7 +171,7 @@ |
44 | |
45 | was_updated = ds_diff.updateStatusAndType() |
46 | |
47 | - self.assertIs(True, was_updated) |
48 | + self.assertTrue(was_updated) |
49 | self.assertEqual( |
50 | DistroSeriesDifferenceStatus.NEEDS_ATTENTION, |
51 | ds_diff.status) |
52 | @@ -195,7 +195,7 @@ |
53 | |
54 | was_updated = ds_diff.updateStatusAndType() |
55 | |
56 | - self.assertIs(False, was_updated) |
57 | + self.assertFalse(was_updated) |
58 | self.assertEqual( |
59 | DistroSeriesDifferenceStatus.NEEDS_ATTENTION, |
60 | ds_diff.status) |
61 | @@ -220,7 +220,7 @@ |
62 | |
63 | was_updated = ds_diff.updateStatusAndType() |
64 | |
65 | - self.assertIs(True, was_updated) |
66 | + self.assertTrue(was_updated) |
67 | self.assertEqual( |
68 | DistroSeriesDifferenceType.DIFFERENT_VERSIONS, |
69 | ds_diff.difference_type) |
Robert Collins (lifeless) wrote : | # |
@Michael regarding interfaces and model code; if our implementations
were substitutable *with* high performance, I'd totally support what
you're saying.
However, the reality is that object traversal is slow (because of lazy
loading); our model objects conflate database access with domain
knowledge, and these two things combined mean that:
- you cannot replace Person in calls wanting IPerson with something
derived from Person and stored in another table: the whole structure
of model->storm relationships means that that will simply not work.
- working solely via I* guarantees terrible performance and the
inability to drive the lower layers efficiently.
I would like to change this, as has been discussed on the list, but we
don't have a better pattern || code for it yet.
You should, of course, delegate, DRY and so forth, but Interface vs
Implementation as far as Launchpad Interfaces go is a weak story.
-Rob
Aaron Bentley (abentley) wrote : | # |
Approved, assuming the changes in http://
Preview Diff
1 | === modified file 'lib/lp/registry/configure.zcml' |
2 | --- lib/lp/registry/configure.zcml 2010-08-31 15:59:47 +0000 |
3 | +++ lib/lp/registry/configure.zcml 2010-08-31 15:59:49 +0000 |
4 | @@ -111,7 +111,10 @@ |
5 | </securedutility> |
6 | <class |
7 | class="lp.registry.model.distroseriesdifference.DistroSeriesDifference"> |
8 | - <allow interface="lp.registry.interfaces.distroseriesdifference.IDistroSeriesDifference"/> |
9 | + <allow interface="lp.registry.interfaces.distroseriesdifference.IDistroSeriesDifferencePublic"/> |
10 | + <require |
11 | + permission="launchpad.Edit" |
12 | + interface="lp.registry.interfaces.distroseriesdifference.IDistroSeriesDifferenceEdit"/> |
13 | </class> |
14 | |
15 | <!-- DistroSeriesDifferenceComment --> |
16 | |
17 | === modified file 'lib/lp/registry/interfaces/distroseriesdifference.py' |
18 | --- lib/lp/registry/interfaces/distroseriesdifference.py 2010-08-31 15:59:47 +0000 |
19 | +++ lib/lp/registry/interfaces/distroseriesdifference.py 2010-08-31 15:59:49 +0000 |
20 | @@ -8,6 +8,8 @@ |
21 | |
22 | __all__ = [ |
23 | 'IDistroSeriesDifference', |
24 | + 'IDistroSeriesDifferencePublic', |
25 | + 'IDistroSeriesDifferenceEdit', |
26 | 'IDistroSeriesDifferenceSource', |
27 | ] |
28 | |
29 | @@ -16,7 +18,6 @@ |
30 | from zope.schema import ( |
31 | Choice, |
32 | Int, |
33 | - Text, |
34 | TextLine, |
35 | ) |
36 | |
37 | @@ -26,13 +27,15 @@ |
38 | DistroSeriesDifferenceType, |
39 | ) |
40 | from lp.registry.interfaces.distroseries import IDistroSeries |
41 | +from lp.registry.interfaces.person import IPerson |
42 | from lp.registry.interfaces.sourcepackagename import ISourcePackageName |
43 | +from lp.registry.interfaces.role import IHasOwner |
44 | from lp.soyuz.interfaces.packagediff import IPackageDiff |
45 | from lp.soyuz.interfaces.publishing import ISourcePackagePublishingHistory |
46 | |
47 | |
48 | -class IDistroSeriesDifference(Interface): |
49 | - """An interface for a package difference between two distroseries.""" |
50 | +class IDistroSeriesDifferencePublic(IHasOwner, Interface): |
51 | + """The public interface for distro series differences.""" |
52 | |
53 | id = Int(title=_('ID'), required=True, readonly=True) |
54 | |
55 | @@ -54,10 +57,6 @@ |
56 | readonly=True, description=_( |
57 | "The most recently generated package diff for this difference.")) |
58 | |
59 | - activity_log = Text( |
60 | - title=_('A log of activity and comments for this difference.'), |
61 | - required=False, readonly=True) |
62 | - |
63 | status = Choice( |
64 | title=_('Distro series difference status.'), |
65 | description=_('The current status of this difference.'), |
66 | @@ -76,20 +75,60 @@ |
67 | description=_( |
68 | "The most recent published version in the derived series.")) |
69 | |
70 | + source_version = TextLine( |
71 | + title=_("Source version"), readonly=True, |
72 | + description=_( |
73 | + "The version of the most recent source publishing in the " |
74 | + "derived series.")) |
75 | + |
76 | parent_source_pub = Reference( |
77 | ISourcePackagePublishingHistory, |
78 | title=_("Parent source pub"), readonly=True, |
79 | description=_( |
80 | "The most recent published version in the parent series.")) |
81 | |
82 | + parent_source_version = TextLine( |
83 | + title=_("Parent source version"), readonly=True, |
84 | + description=_( |
85 | + "The version of the most recent source publishing in the " |
86 | + "parent series.")) |
87 | + |
88 | + owner = Reference( |
89 | + IPerson, title=_("Owning team of the derived series"), readonly=True, |
90 | + description=_( |
91 | + "This attribute mirrors the owner of the derived series.")) |
92 | + |
93 | title = TextLine( |
94 | title=_("Title"), readonly=True, required=False, description=_( |
95 | "A human-readable name describing this difference.")) |
96 | |
97 | + def updateStatusAndType(): |
98 | + """Checks that difference type and status matches current publishings. |
99 | + |
100 | + If the record is updated, a relevant comment is added. |
101 | + |
102 | + If there is no longer a difference (ie. the versions are |
103 | + the same) then the status is updated to RESOLVED. |
104 | + |
105 | + :return: True if the record was updated, False otherwise. |
106 | + """ |
107 | + |
108 | + def getComments(): |
109 | + """Return a result set of the comments for this difference.""" |
110 | + |
111 | + |
112 | +class IDistroSeriesDifferenceEdit(Interface): |
113 | + """Difference attributes requiring launchpad.Edit.""" |
114 | + |
115 | def addComment(owner, comment): |
116 | """Add a comment on this difference.""" |
117 | |
118 | |
119 | +class IDistroSeriesDifference(IDistroSeriesDifferencePublic, |
120 | + IDistroSeriesDifferenceEdit): |
121 | + """An interface for a package difference between two distroseries.""" |
122 | + |
123 | + |
124 | class IDistroSeriesDifferenceSource(Interface): |
125 | """A utility of this interface can be used to create differences.""" |
126 | |
127 | |
128 | === modified file 'lib/lp/registry/model/distroseriesdifference.py' |
129 | --- lib/lp/registry/model/distroseriesdifference.py 2010-08-31 15:59:47 +0000 |
130 | +++ lib/lp/registry/model/distroseriesdifference.py 2010-08-31 15:59:49 +0000 |
131 | @@ -9,7 +9,6 @@ |
132 | 'DistroSeriesDifference', |
133 | ] |
134 | |
135 | - |
136 | from storm.locals import ( |
137 | Int, |
138 | Reference, |
139 | @@ -22,7 +21,10 @@ |
140 | ) |
141 | |
142 | from canonical.database.enumcol import DBEnum |
143 | -from canonical.launchpad.interfaces.lpstorm import IMasterStore |
144 | +from canonical.launchpad.interfaces.lpstorm import ( |
145 | + IMasterStore, |
146 | + IStore, |
147 | + ) |
148 | from lp.registry.enum import ( |
149 | DistroSeriesDifferenceStatus, |
150 | DistroSeriesDifferenceType, |
151 | @@ -35,6 +37,8 @@ |
152 | from lp.registry.interfaces.distroseriesdifferencecomment import ( |
153 | IDistroSeriesDifferenceCommentSource, |
154 | ) |
155 | +from lp.registry.model.distroseriesdifferencecomment import ( |
156 | + DistroSeriesDifferenceComment) |
157 | |
158 | |
159 | class DistroSeriesDifference(Storm): |
160 | @@ -91,23 +95,24 @@ |
161 | return self._getLatestSourcePub(for_parent=True) |
162 | |
163 | @property |
164 | + def owner(self): |
165 | + """See `IDistroSeriesDifference`.""" |
166 | + return self.derived_series.owner |
167 | + |
168 | + @property |
169 | def title(self): |
170 | """See `IDistroSeriesDifference`.""" |
171 | parent_name = self.derived_series.parent_series.displayname |
172 | return ("Difference between distroseries '%(parent_name)s' and " |
173 | "'%(derived_name)s' for package '%(pkg_name)s' " |
174 | - "(%(versions)s)" % { |
175 | + "(%(parent_version)s/%(source_version)s)" % { |
176 | 'parent_name': parent_name, |
177 | 'derived_name': self.derived_series.displayname, |
178 | 'pkg_name': self.source_package_name.name, |
179 | - 'versions': self._getVersions(), |
180 | + 'parent_version': self.parent_source_version, |
181 | + 'source_version': self.source_version, |
182 | }) |
183 | |
184 | - @property |
185 | - def activity_log(self): |
186 | - """See `IDistroSeriesDifference`.""" |
187 | - return u"" |
188 | - |
189 | def _getLatestSourcePub(self, for_parent=False): |
190 | """Helper to keep source_pub/parent_source_pub DRY.""" |
191 | distro_series = self.derived_series |
192 | @@ -123,16 +128,56 @@ |
193 | else: |
194 | return None |
195 | |
196 | - def _getVersions(self): |
197 | - """Helper method returning versions string.""" |
198 | - src_pub_ver = parent_src_pub_ver = "-" |
199 | + @property |
200 | + def source_version(self): |
201 | + """See `IDistroSeriesDifference`.""" |
202 | if self.source_pub: |
203 | - src_pub_ver = self.source_pub.source_package_version |
204 | - if self.parent_source_pub is not None: |
205 | - parent_src_pub_ver = self.parent_source_pub.source_package_version |
206 | - return parent_src_pub_ver + "/" + src_pub_ver |
207 | + return self.source_pub.source_package_version |
208 | + return None |
209 | + |
210 | + @property |
211 | + def parent_source_version(self): |
212 | + """See `IDistroSeriesDifference`.""" |
213 | + if self.parent_source_pub: |
214 | + return self.parent_source_pub.source_package_version |
215 | + return None |
216 | + |
217 | + def updateStatusAndType(self): |
218 | + """See `IDistroSeriesDifference`.""" |
219 | + if self.source_pub is None: |
220 | + new_type = DistroSeriesDifferenceType.MISSING_FROM_DERIVED_SERIES |
221 | + elif self.parent_source_pub is None: |
222 | + new_type = DistroSeriesDifferenceType.UNIQUE_TO_DERIVED_SERIES |
223 | + else: |
224 | + new_type = DistroSeriesDifferenceType.DIFFERENT_VERSIONS |
225 | + |
226 | + updated = False |
227 | + if new_type != self.difference_type: |
228 | + updated = True |
229 | + self.difference_type = new_type |
230 | + |
231 | + version = self.source_version |
232 | + parent_version = self.parent_source_version |
233 | + if self.status == DistroSeriesDifferenceStatus.RESOLVED: |
234 | + if version != parent_version: |
235 | + updated = True |
236 | + self.status = DistroSeriesDifferenceStatus.NEEDS_ATTENTION |
237 | + else: |
238 | + if version == parent_version: |
239 | + updated = True |
240 | + self.status = DistroSeriesDifferenceStatus.RESOLVED |
241 | + |
242 | + return updated |
243 | |
244 | def addComment(self, owner, comment): |
245 | """See `IDistroSeriesDifference`.""" |
246 | return getUtility(IDistroSeriesDifferenceCommentSource).new( |
247 | self, owner, comment) |
248 | + |
249 | + def getComments(self): |
250 | + """See `IDistroSeriesDifference`.""" |
251 | + DSDComment = DistroSeriesDifferenceComment |
252 | + comments = IStore(DSDComment).find( |
253 | + DistroSeriesDifferenceComment, |
254 | + DSDComment.distro_series_difference == self) |
255 | + return comments.order_by(DSDComment.id) |
256 | |
257 | === modified file 'lib/lp/registry/tests/test_distroseriesdifference.py' |
258 | --- lib/lp/registry/tests/test_distroseriesdifference.py 2010-08-31 15:59:47 +0000 |
259 | +++ lib/lp/registry/tests/test_distroseriesdifference.py 2010-08-31 15:59:49 +0000 |
260 | @@ -3,17 +3,27 @@ |
261 | |
262 | """Model tests for the DistroSeriesDifference class.""" |
263 | |
264 | +from __future__ import with_statement |
265 | + |
266 | __metaclass__ = type |
267 | |
268 | import unittest |
269 | |
270 | from storm.store import Store |
271 | from zope.component import getUtility |
272 | +from zope.security.interfaces import Unauthorized |
273 | |
274 | +from canonical.launchpad.webapp.authorization import check_permission |
275 | from canonical.launchpad.webapp.testing import verifyObject |
276 | from canonical.testing import DatabaseFunctionalLayer |
277 | -from lp.testing import TestCaseWithFactory |
278 | -from lp.registry.enum import DistroSeriesDifferenceType |
279 | +from lp.testing import ( |
280 | + person_logged_in, |
281 | + TestCaseWithFactory, |
282 | + ) |
283 | +from lp.registry.enum import ( |
284 | + DistroSeriesDifferenceStatus, |
285 | + DistroSeriesDifferenceType, |
286 | + ) |
287 | from lp.registry.exceptions import NotADerivedSeriesError |
288 | from lp.registry.interfaces.distroseriesdifference import ( |
289 | IDistroSeriesDifference, |
290 | @@ -105,6 +115,116 @@ |
291 | |
292 | self.assertEqual(pending_pub, ds_diff.parent_source_pub) |
293 | |
294 | + def test_source_version(self): |
295 | + # The version of the source in the derived series is returned. |
296 | + ds_diff = self.factory.makeDistroSeriesDifference( |
297 | + source_package_name_str="foonew") |
298 | + |
299 | + self.assertEqual( |
300 | + ds_diff.source_pub.source_package_version, ds_diff.source_version) |
301 | + |
302 | + def test_source_version_none(self): |
303 | + # None is returned for source_version when there is no source pub. |
304 | + ds_diff = self.factory.makeDistroSeriesDifference( |
305 | + source_package_name_str="foonew", |
306 | + difference_type=( |
307 | + DistroSeriesDifferenceType.MISSING_FROM_DERIVED_SERIES)) |
308 | + |
309 | + self.assertEqual(None, ds_diff.source_version) |
310 | + |
311 | + def test_updateStatusAndType_resolves_difference(self): |
312 | + # Status is set to resolved when versions match. |
313 | + ds_diff = self.factory.makeDistroSeriesDifference( |
314 | + source_package_name_str="foonew", |
315 | + versions={ |
316 | + 'parent': '1.0', |
317 | + 'derived': '0.9', |
318 | + }) |
319 | + new_derived_pub = self.factory.makeSourcePackagePublishingHistory( |
320 | + sourcepackagename=ds_diff.source_package_name, |
321 | + distroseries=ds_diff.derived_series, |
322 | + status=PackagePublishingStatus.PENDING, |
323 | + version='1.0') |
324 | + |
325 | + was_updated = ds_diff.updateStatusAndType() |
326 | + |
327 | + self.assertTrue(was_updated) |
328 | + self.assertEqual( |
329 | + DistroSeriesDifferenceStatus.RESOLVED, |
330 | + ds_diff.status) |
331 | + |
332 | + def test_updateStatusAndType_re_opens_difference(self): |
333 | + # The status of a resolved difference will updated with new |
334 | + # uploads. |
335 | + ds_diff = self.factory.makeDistroSeriesDifference( |
336 | + source_package_name_str="foonew", |
337 | + versions={ |
338 | + 'parent': '1.0', |
339 | + 'derived': '1.0', |
340 | + }, |
341 | + status=DistroSeriesDifferenceStatus.RESOLVED) |
342 | + new_derived_pub = self.factory.makeSourcePackagePublishingHistory( |
343 | + sourcepackagename=ds_diff.source_package_name, |
344 | + distroseries=ds_diff.derived_series, |
345 | + status=PackagePublishingStatus.PENDING, |
346 | + version='1.1') |
347 | + |
348 | + was_updated = ds_diff.updateStatusAndType() |
349 | + |
350 | + self.assertTrue(was_updated) |
351 | + self.assertEqual( |
352 | + DistroSeriesDifferenceStatus.NEEDS_ATTENTION, |
353 | + ds_diff.status) |
354 | + |
355 | + def test_updateStatusAndType_new_version_no_change(self): |
356 | + # Uploading a new (different) version does not necessarily |
357 | + # update the record. |
358 | + # In this case, a new version is uploaded, but there is still a |
359 | + # difference needing attention. |
360 | + ds_diff = self.factory.makeDistroSeriesDifference( |
361 | + source_package_name_str="foonew", |
362 | + versions={ |
363 | + 'parent': '1.0', |
364 | + 'derived': '0.9', |
365 | + }) |
366 | + new_derived_pub = self.factory.makeSourcePackagePublishingHistory( |
367 | + sourcepackagename=ds_diff.source_package_name, |
368 | + distroseries=ds_diff.derived_series, |
369 | + status=PackagePublishingStatus.PENDING, |
370 | + version='1.1') |
371 | + |
372 | + was_updated = ds_diff.updateStatusAndType() |
373 | + |
374 | + self.assertFalse(was_updated) |
375 | + self.assertEqual( |
376 | + DistroSeriesDifferenceStatus.NEEDS_ATTENTION, |
377 | + ds_diff.status) |
378 | + |
379 | + def test_updateStatusAndType_changes_type(self): |
380 | + # The type of difference is updated when appropriate. |
381 | + # In this case, a package that was previously only in the |
382 | + # derived series (UNIQUE_TO_DERIVED_SERIES), is uploaded |
383 | + # to the parent series with a different version. |
384 | + ds_diff = self.factory.makeDistroSeriesDifference( |
385 | + source_package_name_str="foonew", |
386 | + versions={ |
387 | + 'derived': '0.9', |
388 | + }, |
389 | + difference_type=( |
390 | + DistroSeriesDifferenceType.UNIQUE_TO_DERIVED_SERIES)) |
391 | + new_parent_pub = self.factory.makeSourcePackagePublishingHistory( |
392 | + sourcepackagename=ds_diff.source_package_name, |
393 | + distroseries=ds_diff.derived_series.parent_series, |
394 | + status=PackagePublishingStatus.PENDING, |
395 | + version='1.1') |
396 | + |
397 | + was_updated = ds_diff.updateStatusAndType() |
398 | + |
399 | + self.assertTrue(was_updated) |
400 | + self.assertEqual( |
401 | + DistroSeriesDifferenceType.DIFFERENT_VERSIONS, |
402 | + ds_diff.difference_type) |
403 | + |
404 | def test_title(self): |
405 | # The title is a friendly description of the difference. |
406 | parent_series = self.factory.makeDistroSeries(name="lucid") |
407 | @@ -126,11 +246,45 @@ |
408 | # Adding a comment creates a new DistroSeriesDifferenceComment |
409 | ds_diff = self.factory.makeDistroSeriesDifference( |
410 | source_package_name_str="foonew") |
411 | + |
412 | + with person_logged_in(ds_diff.owner): |
413 | + dsd_comment = ds_diff.addComment( |
414 | + ds_diff.owner, "Wait until version 2.1") |
415 | + |
416 | + self.assertEqual(ds_diff, dsd_comment.distro_series_difference) |
417 | + |
418 | + def test_getComments(self): |
419 | + # All comments for this difference are returned. |
420 | + ds_diff = self.factory.makeDistroSeriesDifference() |
421 | + |
422 | + with person_logged_in(ds_diff.owner): |
423 | + dsd_comment = ds_diff.addComment( |
424 | + ds_diff.owner, "Wait until version 2.1") |
425 | + dsd_comment_2 = ds_diff.addComment( |
426 | + ds_diff.owner, "Wait until version 2.1") |
427 | + |
428 | + self.assertEqual( |
429 | + [dsd_comment, dsd_comment_2], list(ds_diff.getComments())) |
430 | + |
431 | + def test_addComment_not_public(self): |
432 | + # Comments cannot be added with launchpad.View. |
433 | + ds_diff = self.factory.makeDistroSeriesDifference() |
434 | person = self.factory.makePerson() |
435 | |
436 | - dsd_comment = ds_diff.addComment(person, "Wait until version 2.1") |
437 | - |
438 | - self.assertEqual(ds_diff, dsd_comment.distro_series_difference) |
439 | + with person_logged_in(person): |
440 | + self.assertTrue(check_permission('launchpad.View', ds_diff)) |
441 | + self.assertFalse(check_permission('launchpad.Edit', ds_diff)) |
442 | + self.assertRaises(Unauthorized, getattr, ds_diff, 'addComment') |
443 | + |
444 | + def test_addComment_for_owners(self): |
445 | + # Comments can be added by any of the owners of the derived |
446 | + # series. |
447 | + ds_diff = self.factory.makeDistroSeriesDifference() |
448 | + |
449 | + with person_logged_in(ds_diff.owner): |
450 | + self.assertTrue(check_permission('launchpad.Edit', ds_diff)) |
451 | + diff_comment = ds_diff.addComment( |
452 | + ds_diff.derived_series.owner, "Boo") |
453 | |
454 | |
455 | def test_suite(): |
456 | |
457 | === modified file 'lib/lp/registry/tests/test_distroseriesdifferencecomment.py' |
458 | --- lib/lp/registry/tests/test_distroseriesdifferencecomment.py 2010-08-31 15:59:47 +0000 |
459 | +++ lib/lp/registry/tests/test_distroseriesdifferencecomment.py 2010-08-31 15:59:49 +0000 |
460 | @@ -6,11 +6,13 @@ |
461 | __metaclass__ = type |
462 | |
463 | from storm.store import Store |
464 | +from zope.component import getUtility |
465 | |
466 | from canonical.launchpad.webapp.testing import verifyObject |
467 | from canonical.testing import DatabaseFunctionalLayer |
468 | from lp.registry.interfaces.distroseriesdifferencecomment import ( |
469 | IDistroSeriesDifferenceComment, |
470 | + IDistroSeriesDifferenceCommentSource, |
471 | ) |
472 | from lp.testing import TestCaseWithFactory |
473 | |
474 | |
475 | === modified file 'lib/lp/testing/factory.py' |
476 | --- lib/lp/testing/factory.py 2010-08-31 15:59:47 +0000 |
477 | +++ lib/lp/testing/factory.py 2010-08-31 15:59:49 +0000 |
478 | @@ -154,7 +154,10 @@ |
479 | IHWSubmissionDeviceSet, |
480 | IHWSubmissionSet, |
481 | ) |
482 | -from lp.registry.enum import DistroSeriesDifferenceType |
483 | +from lp.registry.enum import ( |
484 | + DistroSeriesDifferenceStatus, |
485 | + DistroSeriesDifferenceType, |
486 | + ) |
487 | from lp.registry.interfaces.distribution import IDistributionSet |
488 | from lp.registry.interfaces.distributionmirror import ( |
489 | MirrorContent, |
490 | @@ -1827,7 +1830,8 @@ |
491 | def makeDistroSeriesDifference( |
492 | self, derived_series=None, source_package_name_str=None, |
493 | versions=None, |
494 | - difference_type=DistroSeriesDifferenceType.DIFFERENT_VERSIONS): |
495 | + difference_type=DistroSeriesDifferenceType.DIFFERENT_VERSIONS, |
496 | + status=DistroSeriesDifferenceStatus.NEEDS_ATTENTION): |
497 | """Create a new distro series source package difference.""" |
498 | if derived_series is None: |
499 | parent_series = self.makeDistroSeries() |
500 | @@ -1860,7 +1864,8 @@ |
501 | sourcepackagename=source_package_name) |
502 | |
503 | return getUtility(IDistroSeriesDifferenceSource).new( |
504 | - derived_series, source_package_name, difference_type) |
505 | + derived_series, source_package_name, difference_type, |
506 | + status=status) |
507 | |
508 | def makeDistroSeriesDifferenceComment( |
509 | self, distro_series_difference=None, owner=None, comment=None): |
Why are source_version and parent_ source_ version returning ''? I would have expected them to return None if there was no such value.
Why not implement getComments directly instead of indirecting through IDistroSeriesDi fferenceComment Source?
Your test comments say None, but test for the empty string. Please fix either the test or the comment.
Why assertIs(True, was_updated) instead of assertTrue( was_updated) ? We should only care about whether the returned value evaluates to True. We should definitely not care about its identity.
Why assertIs(True, was_updated) instead of assertTrue( ds_diff. updateStatusAnd Type()) ? It is shorter, so easier to read.