Merge lp:~wgrant/launchpad/bugbranch-hide into lp:launchpad
- bugbranch-hide
- Merge into devel
Proposed by
William Grant
Status: | Merged |
---|---|
Merged at revision: | 17917 |
Proposed branch: | lp:~wgrant/launchpad/bugbranch-hide |
Merge into: | lp:launchpad |
Diff against target: |
605 lines (+49/-180) 15 files modified
lib/lp/app/browser/tales.py (+1/-1) lib/lp/bugs/configure.zcml (+4/-16) lib/lp/bugs/interfaces/bug.py (+4/-6) lib/lp/bugs/interfaces/bugbranch.py (+2/-29) lib/lp/bugs/model/bug.py (+17/-16) lib/lp/bugs/model/bugbranch.py (+1/-33) lib/lp/bugs/security.py (+0/-11) lib/lp/bugs/subscribers/karma.py (+6/-3) lib/lp/bugs/templates/bug-branch.pt (+2/-5) lib/lp/bugs/tests/test_bugbranch.py (+3/-40) lib/lp/code/browser/branch.py (+1/-1) lib/lp/code/doc/branch-xmlrpc.txt (+2/-2) lib/lp/code/model/tests/test_branch.py (+1/-1) lib/lp/code/model/tests/test_branchjob.py (+1/-1) lib/lp/codehosting/scanner/tests/test_buglinks.py (+4/-15) |
To merge this branch: | bzr merge lp:~wgrant/launchpad/bugbranch-hide |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Colin Watson (community) | Approve | ||
Review via email: mp+285134@code.launchpad.net |
Commit message
Preparatory cleanup for BugBranch XRefification.
Description of the change
Preparatory cleanup for BugBranch XRefification.
It'll have to remain as a wrapper for API/UI compatibility, but good chunks of the related code can be fixed to no longer exist.
To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'lib/lp/app/browser/tales.py' |
2 | --- lib/lp/app/browser/tales.py 2015-10-01 02:59:28 +0000 |
3 | +++ lib/lp/app/browser/tales.py 2016-02-05 23:06:38 +0000 |
4 | @@ -953,7 +953,7 @@ |
5 | |
6 | def _hasBugBranch(self): |
7 | """Return whether the bug has a branch linked to it.""" |
8 | - return not self._context.bug.linked_branches.is_empty() |
9 | + return not self._context.bug.linked_bugbranches.is_empty() |
10 | |
11 | def _hasSpecification(self): |
12 | """Return whether the bug is linked to a specification.""" |
13 | |
14 | === modified file 'lib/lp/bugs/configure.zcml' |
15 | --- lib/lp/bugs/configure.zcml 2015-09-25 09:59:27 +0000 |
16 | +++ lib/lp/bugs/configure.zcml 2016-02-05 23:06:38 +0000 |
17 | @@ -77,18 +77,15 @@ |
18 | for="lp.bugs.interfaces.bugattachment.IBugAttachment lazr.lifecycle.interfaces.IObjectModifiedEvent" |
19 | handler="lp.bugs.subscribers.buglastupdated.update_bug_date_last_updated"/> |
20 | <subscriber |
21 | - for="lp.bugs.interfaces.bugbranch.IBugBranch lazr.lifecycle.interfaces.IObjectCreatedEvent" |
22 | - handler="lp.bugs.subscribers.buglastupdated.update_bug_date_last_updated"/> |
23 | - <subscriber |
24 | - for="lp.bugs.interfaces.bugbranch.IBugBranch lazr.lifecycle.interfaces.IObjectModifiedEvent" |
25 | - handler="lp.bugs.subscribers.buglastupdated.update_bug_date_last_updated"/> |
26 | - <subscriber |
27 | for="lp.bugs.interfaces.bug.IBug lp.bugs.interfaces.buglink.IObjectLinkedEvent" |
28 | handler="lp.bugs.subscribers.buglastupdated.update_bug_date_last_updated"/> |
29 | <subscriber |
30 | for="lp.bugs.interfaces.bug.IBug lp.bugs.interfaces.buglink.IObjectLinkedEvent" |
31 | handler="lp.bugs.subscribers.karma.cve_added"/> |
32 | <subscriber |
33 | + for="lp.bugs.interfaces.bug.IBug lp.bugs.interfaces.buglink.IObjectLinkedEvent" |
34 | + handler="lp.bugs.subscribers.karma.branch_linked"/> |
35 | + <subscriber |
36 | for="lp.bugs.interfaces.bugmessage.IBugMessage lazr.lifecycle.interfaces.IObjectCreatedEvent" |
37 | handler="lp.bugs.subscribers.bug.notify_bug_comment_added"/> |
38 | <subscriber |
39 | @@ -527,18 +524,8 @@ |
40 | class="lp.bugs.model.bugbranch.BugBranch"> |
41 | <allow |
42 | interface="lp.bugs.interfaces.bugbranch.IBugBranch"/> |
43 | - <require |
44 | - permission="launchpad.Edit" |
45 | - attributes=" |
46 | - destroySelf"/> |
47 | </class> |
48 | |
49 | - <!-- hierarchy --> |
50 | - |
51 | - <subscriber |
52 | - for="lp.bugs.interfaces.bugbranch.IBugBranch lazr.lifecycle.interfaces.IObjectCreatedEvent" |
53 | - handler="lp.bugs.subscribers.karma.bug_branch_created"/> |
54 | - |
55 | <!-- BugBranchSet --> |
56 | |
57 | <class |
58 | @@ -719,6 +706,7 @@ |
59 | interface="lp.bugs.interfaces.bug.IBugView" |
60 | attributes=" |
61 | linked_branches |
62 | + linked_bugbranches |
63 | getVisibleLinkedBranches"/> |
64 | <require |
65 | permission="launchpad.Edit" |
66 | |
67 | === modified file 'lib/lp/bugs/interfaces/bug.py' |
68 | --- lib/lp/bugs/interfaces/bug.py 2015-09-30 01:51:52 +0000 |
69 | +++ lib/lp/bugs/interfaces/bug.py 2016-02-05 23:06:38 +0000 |
70 | @@ -399,9 +399,6 @@ |
71 | None to prevent lazy evaluation triggering database lookups. |
72 | """ |
73 | |
74 | - def hasBranch(branch): |
75 | - """Is this branch linked to this bug?""" |
76 | - |
77 | def isSubscribed(person): |
78 | """Is person subscribed to this bug? |
79 | |
80 | @@ -999,14 +996,15 @@ |
81 | """The core bug entry.""" |
82 | export_as_webservice_entry() |
83 | |
84 | - linked_branches = exported( |
85 | + linked_bugbranches = exported( |
86 | CollectionField( |
87 | title=_("Branches associated with this bug, usually " |
88 | "branches on which this bug is being fixed."), |
89 | value_type=Reference(schema=IBugBranch), |
90 | - readonly=True)) |
91 | + readonly=True), |
92 | + exported_as='linked_branches') |
93 | |
94 | - @accessor_for(linked_branches) |
95 | + @accessor_for(linked_bugbranches) |
96 | @call_with(user=REQUEST_USER) |
97 | @export_read_operation() |
98 | @operation_for_version('beta') |
99 | |
100 | === modified file 'lib/lp/bugs/interfaces/bugbranch.py' |
101 | --- lib/lp/bugs/interfaces/bugbranch.py 2016-02-05 06:41:16 +0000 |
102 | +++ lib/lp/bugs/interfaces/bugbranch.py 2016-02-05 23:06:38 +0000 |
103 | @@ -19,45 +19,28 @@ |
104 | Attribute, |
105 | Interface, |
106 | ) |
107 | -from zope.schema import ( |
108 | - Int, |
109 | - Object, |
110 | - TextLine, |
111 | - ) |
112 | +from zope.schema import Object |
113 | |
114 | from lp import _ |
115 | -from lp.bugs.interfaces.bugtask import IBugTask |
116 | from lp.bugs.interfaces.hasbug import IHasBug |
117 | from lp.code.interfaces.branch import IBranch |
118 | -from lp.code.interfaces.branchtarget import IHasBranchTarget |
119 | from lp.registry.interfaces.person import IPerson |
120 | from lp.services.fields import BugField |
121 | |
122 | |
123 | -class IBugBranch(IHasBug, IHasBranchTarget): |
124 | +class IBugBranch(IHasBug): |
125 | """A branch linked to a bug.""" |
126 | |
127 | export_as_webservice_entry() |
128 | |
129 | - id = Int(title=_("Bug Branch #")) |
130 | bug = exported( |
131 | BugField( |
132 | title=_("Bug #"), |
133 | required=True, readonly=True)) |
134 | - branch_id = Int(title=_("Branch ID"), required=True, readonly=True) |
135 | branch = exported( |
136 | ReferenceChoice( |
137 | title=_("Branch"), schema=IBranch, |
138 | vocabulary="Branch", required=True)) |
139 | - revision_hint = TextLine(title=_("Revision Hint")) |
140 | - |
141 | - bug_task = Object( |
142 | - schema=IBugTask, title=_("The bug task that the branch fixes"), |
143 | - description=_( |
144 | - "the bug task reported against this branch's product or the " |
145 | - "first bug task (in case where there is no task reported " |
146 | - "against the branch's product)."), |
147 | - readonly=True) |
148 | |
149 | datecreated = Attribute("The date on which I was created.") |
150 | registrant = Object( |
151 | @@ -67,12 +50,6 @@ |
152 | |
153 | class IBugBranchSet(Interface): |
154 | |
155 | - def getBugBranch(bug, branch): |
156 | - """Return the BugBranch for the given bug and branch. |
157 | - |
158 | - Return None if there is no such link. |
159 | - """ |
160 | - |
161 | def getBranchesWithVisibleBugs(branches, user): |
162 | """Find which of `branches` are for bugs that `user` can see. |
163 | |
164 | @@ -82,7 +59,3 @@ |
165 | found in `branches`, but limited to branches that are |
166 | visible to `user`. |
167 | """ |
168 | - |
169 | - def getBugBranchesForBugTasks(tasks): |
170 | - """Return a sequence of IBugBranch instances associated with |
171 | - the bugs for the given tasks.""" |
172 | |
173 | === modified file 'lib/lp/bugs/model/bug.py' |
174 | --- lib/lp/bugs/model/bug.py 2016-01-26 15:47:37 +0000 |
175 | +++ lib/lp/bugs/model/bug.py 2016-02-05 23:06:38 +0000 |
176 | @@ -28,7 +28,6 @@ |
177 | |
178 | from lazr.lifecycle.event import ( |
179 | ObjectCreatedEvent, |
180 | - ObjectDeletedEvent, |
181 | ObjectModifiedEvent, |
182 | ) |
183 | from lazr.lifecycle.snapshot import Snapshot |
184 | @@ -148,6 +147,10 @@ |
185 | from lp.bugs.model.bugactivity import BugActivity |
186 | from lp.bugs.model.bugattachment import BugAttachment |
187 | from lp.bugs.model.bugbranch import BugBranch |
188 | +from lp.bugs.model.buglinktarget import ( |
189 | + ObjectLinkedEvent, |
190 | + ObjectUnlinkedEvent, |
191 | + ) |
192 | from lp.bugs.model.bugmessage import BugMessage |
193 | from lp.bugs.model.bugnomination import BugNomination |
194 | from lp.bugs.model.bugnotification import BugNotification |
195 | @@ -361,7 +364,7 @@ |
196 | watches = SQLMultipleJoin( |
197 | 'BugWatch', joinColumn='bug', orderBy=['bugtracker', 'remotebug']) |
198 | duplicates = SQLMultipleJoin('Bug', joinColumn='duplicateof', orderBy='id') |
199 | - linked_branches = SQLMultipleJoin( |
200 | + linked_bugbranches = SQLMultipleJoin( |
201 | 'BugBranch', joinColumn='bug', orderBy='id') |
202 | date_last_message = UtcDateTimeCol(default=None) |
203 | number_of_duplicates = IntCol(notNull=True, default=0) |
204 | @@ -373,6 +376,10 @@ |
205 | latest_patch_uploaded = UtcDateTimeCol(default=None) |
206 | |
207 | @property |
208 | + def linked_branches(self): |
209 | + return [link.branch for link in self.linked_bugbranches] |
210 | + |
211 | + @property |
212 | def cves(self): |
213 | from lp.bugs.model.cve import Cve |
214 | xref_cve_sequences = [ |
215 | @@ -1351,32 +1358,26 @@ |
216 | title=title, message=message, |
217 | send_notifications=send_notifications) |
218 | |
219 | - def hasBranch(self, branch): |
220 | - """See `IBug`.""" |
221 | - return BugBranch.selectOneBy(branch=branch, bug=self) is not None |
222 | - |
223 | def linkBranch(self, branch, registrant): |
224 | """See `IBug`.""" |
225 | - for bug_branch in shortlist(self.linked_branches): |
226 | - if bug_branch.branch == branch: |
227 | - return bug_branch |
228 | + if branch in self.linked_branches: |
229 | + return |
230 | |
231 | - bug_branch = BugBranch( |
232 | - branch=branch, bug=self, registrant=registrant) |
233 | + BugBranch(branch=branch, bug=self, registrant=registrant) |
234 | branch.date_last_modified = UTC_NOW |
235 | |
236 | self.addChange(BranchLinkedToBug(UTC_NOW, registrant, branch, self)) |
237 | - notify(ObjectCreatedEvent(bug_branch)) |
238 | - |
239 | - return bug_branch |
240 | + notify(ObjectLinkedEvent(branch, self, user=registrant)) |
241 | + notify(ObjectLinkedEvent(self, branch, user=registrant)) |
242 | |
243 | def unlinkBranch(self, branch, user): |
244 | """See `IBug`.""" |
245 | bug_branch = BugBranch.selectOneBy(bug=self, branch=branch) |
246 | if bug_branch is not None: |
247 | self.addChange(BranchUnlinkedFromBug(UTC_NOW, user, branch, self)) |
248 | - notify(ObjectDeletedEvent(bug_branch, user=user)) |
249 | - bug_branch.destroySelf() |
250 | + notify(ObjectUnlinkedEvent(branch, self, user=user)) |
251 | + notify(ObjectUnlinkedEvent(self, branch, user=user)) |
252 | + Store.of(bug_branch).remove(bug_branch) |
253 | |
254 | def getVisibleLinkedBranches(self, user, eager_load=False): |
255 | """Return all the branches linked to the bug that `user` can see.""" |
256 | |
257 | === modified file 'lib/lp/bugs/model/bugbranch.py' |
258 | --- lib/lp/bugs/model/bugbranch.py 2015-07-08 16:05:11 +0000 |
259 | +++ lib/lp/bugs/model/bugbranch.py 2016-02-05 23:06:38 +0000 |
260 | @@ -10,9 +10,7 @@ |
261 | |
262 | from sqlobject import ( |
263 | ForeignKey, |
264 | - IN, |
265 | IntCol, |
266 | - StringCol, |
267 | ) |
268 | from zope.interface import implementer |
269 | |
270 | @@ -20,7 +18,6 @@ |
271 | IBugBranch, |
272 | IBugBranchSet, |
273 | ) |
274 | -from lp.code.interfaces.branchtarget import IHasBranchTarget |
275 | from lp.registry.interfaces.person import validate_public_person |
276 | from lp.services.database.constants import UTC_NOW |
277 | from lp.services.database.datetimecol import UtcDateTimeCol |
278 | @@ -28,7 +25,7 @@ |
279 | from lp.services.database.sqlbase import SQLBase |
280 | |
281 | |
282 | -@implementer(IBugBranch, IHasBranchTarget) |
283 | +@implementer(IBugBranch) |
284 | class BugBranch(SQLBase): |
285 | """See `IBugBranch`.""" |
286 | |
287 | @@ -36,34 +33,15 @@ |
288 | bug = ForeignKey(dbName="bug", foreignKey="Bug", notNull=True) |
289 | branch_id = IntCol(dbName="branch", notNull=True) |
290 | branch = ForeignKey(dbName="branch", foreignKey="Branch", notNull=True) |
291 | - revision_hint = StringCol(default=None) |
292 | |
293 | registrant = ForeignKey( |
294 | dbName='registrant', foreignKey='Person', |
295 | storm_validator=validate_public_person, notNull=True) |
296 | |
297 | - @property |
298 | - def target(self): |
299 | - """See `IHasBranchTarget`.""" |
300 | - return self.branch.target |
301 | - |
302 | - @property |
303 | - def bug_task(self): |
304 | - """See `IBugBranch`.""" |
305 | - task = self.bug.getBugTask(self.branch.product) |
306 | - if task is None: |
307 | - # Just choose the first task for the bug. |
308 | - task = self.bug.bugtasks[0] |
309 | - return task |
310 | - |
311 | |
312 | @implementer(IBugBranchSet) |
313 | class BugBranchSet: |
314 | |
315 | - def getBugBranch(self, bug, branch): |
316 | - """See `IBugBranchSet`.""" |
317 | - return BugBranch.selectOneBy(bugID=bug.id, branchID=branch.id) |
318 | - |
319 | def getBranchesWithVisibleBugs(self, branches, user): |
320 | """See `IBugBranchSet`.""" |
321 | # Avoid circular imports. |
322 | @@ -80,13 +58,3 @@ |
323 | BugBranch.branch_id.is_in(branch_ids), |
324 | BugTaskFlat.bug_id == BugBranch.bugID, |
325 | visible).config(distinct=True) |
326 | - |
327 | - def getBugBranchesForBugTasks(self, tasks): |
328 | - """See `IBugBranchSet`.""" |
329 | - bug_ids = [task.bugID for task in tasks] |
330 | - if not bug_ids: |
331 | - return [] |
332 | - bugbranches = BugBranch.select(IN(BugBranch.q.bugID, bug_ids), |
333 | - orderBy=['branch']) |
334 | - return bugbranches.prejoin( |
335 | - ['branch', 'branch.owner', 'branch.product']) |
336 | |
337 | === modified file 'lib/lp/bugs/security.py' |
338 | --- lib/lp/bugs/security.py 2016-01-26 15:47:37 +0000 |
339 | +++ lib/lp/bugs/security.py 2016-02-05 23:06:38 +0000 |
340 | @@ -13,7 +13,6 @@ |
341 | ) |
342 | from lp.bugs.interfaces.bug import IBug |
343 | from lp.bugs.interfaces.bugattachment import IBugAttachment |
344 | -from lp.bugs.interfaces.bugbranch import IBugBranch |
345 | from lp.bugs.interfaces.bugnomination import IBugNomination |
346 | from lp.bugs.interfaces.bugsubscription import IBugSubscription |
347 | from lp.bugs.interfaces.bugsubscriptionfilter import IBugSubscriptionFilter |
348 | @@ -131,16 +130,6 @@ |
349 | return not self.obj.private |
350 | |
351 | |
352 | -class EditBugBranch(EditPublicByLoggedInUserAndPrivateByExplicitSubscribers): |
353 | - permission = 'launchpad.Edit' |
354 | - usedfor = IBugBranch |
355 | - |
356 | - def __init__(self, bug_branch): |
357 | - # The same permissions as for the BugBranch's bug should apply |
358 | - # to the BugBranch itself. |
359 | - super(EditBugBranch, self).__init__(bug_branch.bug) |
360 | - |
361 | - |
362 | class ViewBugAttachment(DelegatedAuthorization): |
363 | """Security adapter for viewing a bug attachment. |
364 | |
365 | |
366 | === modified file 'lib/lp/bugs/subscribers/karma.py' |
367 | --- lib/lp/bugs/subscribers/karma.py 2015-09-25 08:50:34 +0000 |
368 | +++ lib/lp/bugs/subscribers/karma.py 2016-02-05 23:06:38 +0000 |
369 | @@ -121,7 +121,10 @@ |
370 | |
371 | |
372 | @block_implicit_flushes |
373 | -def bug_branch_created(bug_branch, event): |
374 | +def branch_linked(bug, event): |
375 | """Assign karma to the user who linked the bug to the branch.""" |
376 | - bug_branch.branch.target.assignKarma( |
377 | - bug_branch.registrant, 'bugbranchcreated') |
378 | + from lp.code.interfaces.branch import IBranch |
379 | + if not IBranch.providedBy(event.other_object): |
380 | + return |
381 | + event.other_object.target.assignKarma( |
382 | + IPerson(event.user), 'bugbranchcreated') |
383 | |
384 | === modified file 'lib/lp/bugs/templates/bug-branch.pt' |
385 | --- lib/lp/bugs/templates/bug-branch.pt 2011-02-03 05:14:54 +0000 |
386 | +++ lib/lp/bugs/templates/bug-branch.pt 2016-02-05 23:06:38 +0000 |
387 | @@ -8,8 +8,7 @@ |
388 | branch bug_branch/branch; |
389 | bug bug_branch/bug; |
390 | show_edit bug_branch/required:launchpad.Edit" |
391 | - tal:condition="branch/required:launchpad.View" |
392 | - tal:attributes="id string:bug-branch-${bug_branch/id}"> |
393 | + tal:condition="branch/required:launchpad.View"> |
394 | |
395 | <tal:branch-ref replace="structure branch/fmt:link"/> |
396 | <tal:branch-status condition="view/show_branch_status"> |
397 | @@ -20,9 +19,7 @@ |
398 | <a title="Remove link" |
399 | class="bugbranch-delete" |
400 | tal:condition="show_edit" |
401 | - tal:attributes=" |
402 | - href string:${branch/fmt:url}/+bug/${bug/id}/+delete; |
403 | - id string:bugbranch-${bug_branch/id}-delete;"> |
404 | + tal:attributes="href string:${branch/fmt:url}/+bug/${bug/id}/+delete"> |
405 | <img src="/@@/remove" alt="Remove"/> |
406 | </a> |
407 | <div tal:repeat="proposal view/merge_proposals" class="reviews"> |
408 | |
409 | === modified file 'lib/lp/bugs/tests/test_bugbranch.py' |
410 | --- lib/lp/bugs/tests/test_bugbranch.py 2012-09-18 18:36:09 +0000 |
411 | +++ lib/lp/bugs/tests/test_bugbranch.py 2016-02-05 23:06:38 +0000 |
412 | @@ -143,20 +143,6 @@ |
413 | self.assertContentEqual( |
414 | [branch.id], utility.getBranchesWithVisibleBugs([branch], admin)) |
415 | |
416 | - def test_getBugBranchesForBugTasks(self): |
417 | - # IBugBranchSet.getBugBranchesForBugTasks returns all of the BugBranch |
418 | - # objects associated with the given bug tasks. |
419 | - bug_a = self.factory.makeBug() |
420 | - bug_b = self.factory.makeBug() |
421 | - bugtasks = bug_a.bugtasks + bug_b.bugtasks |
422 | - branch = self.factory.makeBranch() |
423 | - self.factory.loginAsAnyone() |
424 | - link_1 = bug_a.linkBranch(branch, self.factory.makePerson()) |
425 | - link_2 = bug_b.linkBranch(branch, self.factory.makePerson()) |
426 | - found_links = getUtility(IBugBranchSet).getBugBranchesForBugTasks( |
427 | - bugtasks) |
428 | - self.assertEqual(set([link_1, link_2]), set(found_links)) |
429 | - |
430 | |
431 | class TestBugBranch(TestCaseWithFactory): |
432 | |
433 | @@ -174,16 +160,6 @@ |
434 | registrant=self.factory.makePerson()) |
435 | self.assertProvides(bug_branch, IBugBranch) |
436 | |
437 | - def test_linkBranch_returns_IBugBranch(self): |
438 | - # Bug.linkBranch returns an IBugBranch linking the bug to the branch. |
439 | - bug = self.factory.makeBug() |
440 | - branch = self.factory.makeBranch() |
441 | - registrant = self.factory.makePerson() |
442 | - bug_branch = bug.linkBranch(branch, registrant) |
443 | - self.assertEqual(branch, bug_branch.branch) |
444 | - self.assertEqual(bug, bug_branch.bug) |
445 | - self.assertEqual(registrant, bug_branch.registrant) |
446 | - |
447 | def test_bug_start_with_no_linked_branches(self): |
448 | # Bugs have a linked_branches attribute which is initially an empty |
449 | # collection. |
450 | @@ -195,8 +171,9 @@ |
451 | # BugBranch object. |
452 | bug = self.factory.makeBug() |
453 | branch = self.factory.makeBranch() |
454 | - bug_branch = bug.linkBranch(branch, self.factory.makePerson()) |
455 | - self.assertEqual([bug_branch], list(bug.linked_branches)) |
456 | + self.assertContentEqual([], list(bug.linked_branches)) |
457 | + bug.linkBranch(branch, self.factory.makePerson()) |
458 | + self.assertContentEqual([branch], list(bug.linked_branches)) |
459 | |
460 | def test_linking_branch_twice_returns_same_IBugBranch(self): |
461 | # Calling Bug.linkBranch twice with the same parameters returns the |
462 | @@ -217,18 +194,6 @@ |
463 | bug_branch_2 = bug.linkBranch(branch, self.factory.makePerson()) |
464 | self.assertEqual(bug_branch, bug_branch_2) |
465 | |
466 | - def test_bug_has_no_branches(self): |
467 | - # Bug.hasBranch returns False for any branch that it is not linked to. |
468 | - bug = self.factory.makeBug() |
469 | - self.assertFalse(bug.hasBranch(self.factory.makeBranch())) |
470 | - |
471 | - def test_bug_has_branch(self): |
472 | - # Bug.hasBranch returns False for any branch that it is linked to. |
473 | - bug = self.factory.makeBug() |
474 | - branch = self.factory.makeBranch() |
475 | - bug.linkBranch(branch, self.factory.makePerson()) |
476 | - self.assertTrue(bug.hasBranch(branch)) |
477 | - |
478 | def test_unlink_branch(self): |
479 | # Bug.unlinkBranch removes the bug<->branch link. |
480 | bug = self.factory.makeBug() |
481 | @@ -236,7 +201,6 @@ |
482 | bug.linkBranch(branch, self.factory.makePerson()) |
483 | bug.unlinkBranch(branch, self.factory.makePerson()) |
484 | self.assertEqual([], list(bug.linked_branches)) |
485 | - self.assertFalse(bug.hasBranch(branch)) |
486 | |
487 | def test_unlink_not_linked_branch(self): |
488 | # When unlinkBranch is called with a branch that isn't already linked, |
489 | @@ -245,7 +209,6 @@ |
490 | branch = self.factory.makeBranch() |
491 | bug.unlinkBranch(branch, self.factory.makePerson()) |
492 | self.assertEqual([], list(bug.linked_branches)) |
493 | - self.assertFalse(bug.hasBranch(branch)) |
494 | |
495 | def test_the_unwashed_cannot_link_branch_to_private_bug(self): |
496 | # Those who cannot see a bug are forbidden to link a branch to it. |
497 | |
498 | === modified file 'lib/lp/code/browser/branch.py' |
499 | --- lib/lp/code/browser/branch.py 2015-10-07 16:14:42 +0000 |
500 | +++ lib/lp/code/browser/branch.py 2016-02-05 23:06:38 +0000 |
501 | @@ -190,7 +190,7 @@ |
502 | """Traverses to an `IBugBranch`.""" |
503 | bug = getUtility(IBugSet).get(bugid) |
504 | |
505 | - for bug_branch in bug.linked_branches: |
506 | + for bug_branch in bug.linked_bugbranches: |
507 | if bug_branch.branch == self.context: |
508 | return bug_branch |
509 | |
510 | |
511 | === modified file 'lib/lp/code/doc/branch-xmlrpc.txt' |
512 | --- lib/lp/code/doc/branch-xmlrpc.txt 2012-12-10 13:43:47 +0000 |
513 | +++ lib/lp/code/doc/branch-xmlrpc.txt 2016-02-05 23:06:38 +0000 |
514 | @@ -291,8 +291,8 @@ |
515 | |
516 | >>> from lp.bugs.interfaces.bug import IBugSet |
517 | >>> bug_one = getUtility(IBugSet).get(1) |
518 | - >>> for bug_branch in bug_one.linked_branches: |
519 | - ... print bug_branch.branch.url |
520 | + >>> for branch in bug_one.linked_branches: |
521 | + ... print branch.url |
522 | http://foo.com/other_branch |
523 | |
524 | We get an error if we try to specify a non-existant branch or bug: |
525 | |
526 | === modified file 'lib/lp/code/model/tests/test_branch.py' |
527 | --- lib/lp/code/model/tests/test_branch.py 2015-10-12 12:58:32 +0000 |
528 | +++ lib/lp/code/model/tests/test_branch.py 2016-02-05 23:06:38 +0000 |
529 | @@ -1582,7 +1582,7 @@ |
530 | """break_links allows deleting a branch with a bug.""" |
531 | bug1 = self.factory.makeBug() |
532 | bug1.linkBranch(self.branch, self.branch.owner) |
533 | - bug_branch1 = bug1.linked_branches[0] |
534 | + bug_branch1 = bug1.linked_bugbranches[0] |
535 | bug_branch1_id = bug_branch1.id |
536 | self.branch.destroySelf(break_references=True) |
537 | self.assertRaises(SQLObjectNotFound, BugBranch.get, bug_branch1_id) |
538 | |
539 | === modified file 'lib/lp/code/model/tests/test_branchjob.py' |
540 | --- lib/lp/code/model/tests/test_branchjob.py 2015-09-28 17:38:45 +0000 |
541 | +++ lib/lp/code/model/tests/test_branchjob.py 2016-02-05 23:06:38 +0000 |
542 | @@ -202,7 +202,7 @@ |
543 | with dbuser("branchscanner"): |
544 | job.run() |
545 | self.assertEqual(db_branch.revision_count, 1) |
546 | - self.assertTrue(private_bug.hasBranch(db_branch)) |
547 | + self.assertIn(db_branch, private_bug.linked_branches) |
548 | |
549 | |
550 | class TestBranchUpgradeJob(TestCaseWithFactory): |
551 | |
552 | === modified file 'lib/lp/codehosting/scanner/tests/test_buglinks.py' |
553 | --- lib/lp/codehosting/scanner/tests/test_buglinks.py 2013-07-04 07:58:00 +0000 |
554 | +++ lib/lp/codehosting/scanner/tests/test_buglinks.py 2016-02-05 23:06:38 +0000 |
555 | @@ -11,7 +11,6 @@ |
556 | |
557 | from lp.app.errors import NotFoundError |
558 | from lp.bugs.interfaces.bug import IBugSet |
559 | -from lp.bugs.interfaces.bugbranch import IBugBranchSet |
560 | from lp.code.interfaces.revision import IRevisionSet |
561 | from lp.codehosting.scanner import events |
562 | from lp.codehosting.scanner.buglinks import BugBranchLinker |
563 | @@ -141,9 +140,7 @@ |
564 | |
565 | Raises an assertion error if there's no such bug. |
566 | """ |
567 | - bug_branch = getUtility(IBugBranchSet).getBugBranch(bug, branch) |
568 | - if bug_branch is None: |
569 | - self.fail('No BugBranch found for %r, %r' % (bug, branch)) |
570 | + self.assertIn(branch, bug.linked_branches) |
571 | |
572 | def test_newMainlineRevisionAddsBugBranch(self): |
573 | """New mainline revisions with bugs properties create BugBranches.""" |
574 | @@ -187,11 +184,7 @@ |
575 | self.syncBazaarBranchToDatabase(self.bzr_branch, self.db_branch) |
576 | # Create a new DB branch to sync with. |
577 | self.syncBazaarBranchToDatabase(self.bzr_branch, self.new_db_branch) |
578 | - self.assertEqual( |
579 | - getUtility(IBugBranchSet).getBugBranch( |
580 | - self.bug1, self.new_db_branch), |
581 | - None, |
582 | - "Should not create a BugBranch.") |
583 | + self.assertNotIn(self.new_db_branch, self.bug1.linked_branches) |
584 | |
585 | def test_nonMainlineRevisionsDontMakeBugBranches(self): |
586 | """Don't add BugBranches based on non-mainline revisions.""" |
587 | @@ -224,10 +217,7 @@ |
588 | allow_pointless=True) |
589 | |
590 | self.syncBazaarBranchToDatabase(self.bzr_branch, self.db_branch) |
591 | - self.assertEqual( |
592 | - getUtility(IBugBranchSet).getBugBranch(self.bug1, self.db_branch), |
593 | - None, |
594 | - "Should not create a BugBranch.") |
595 | + self.assertNotIn(self.db_branch, self.bug1.linked_branches) |
596 | |
597 | def test_ignoreNonExistentBug(self): |
598 | """If the bug doesn't actually exist, we just ignore it.""" |
599 | @@ -272,5 +262,4 @@ |
600 | revision_set.newFromBazaarRevisions([bzr_revision]) |
601 | notify(events.NewMainlineRevisions( |
602 | db_branch, tree.branch, [bzr_revision])) |
603 | - bug_branch = getUtility(IBugBranchSet).getBugBranch(bug, db_branch) |
604 | - self.assertIsNot(None, bug_branch) |
605 | + self.assertIn(db_branch, bug.linked_branches) |