Merge lp:~thumper/launchpad/lp-code-errors into lp:launchpad/db-devel

Proposed by Tim Penhey
Status: Merged
Approved by: Michael Hudson-Doyle
Approved revision: not available
Merged at revision: 8757
Proposed branch: lp:~thumper/launchpad/lp-code-errors
Merge into: lp:launchpad/db-devel
Prerequisite: lp:~thumper/launchpad/claim-review-into-model
Diff against target: 264 lines (+66/-52)
9 files modified
lib/lp/code/browser/branch.py (+1/-1)
lib/lp/code/browser/branchmergeproposal.py (+2/-2)
lib/lp/code/errors.py (+48/-0)
lib/lp/code/interfaces/branchmergeproposal.py (+1/-38)
lib/lp/code/mail/codehandler.py (+2/-2)
lib/lp/code/model/branch.py (+3/-2)
lib/lp/code/model/branchmergeproposal.py (+4/-3)
lib/lp/code/model/tests/test_branch.py (+2/-2)
lib/lp/code/model/tests/test_branchmergeproposals.py (+3/-2)
To merge this branch: bzr merge lp:~thumper/launchpad/lp-code-errors
Reviewer Review Type Date Requested Status
Michael Hudson-Doyle Approve
Review via email: mp+15724@code.launchpad.net

Commit message

Create the lp.code.errors module and start moving exceptions across.

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

Cherry picked the new errors file out.

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Looks like a good start for this file :-)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/code/browser/branch.py'
--- lib/lp/code/browser/branch.py 2009-11-25 23:25:51 +0000
+++ lib/lp/code/browser/branch.py 2009-12-07 02:20:33 +0000
@@ -80,10 +80,10 @@
80 latest_proposals_for_each_branch)80 latest_proposals_for_each_branch)
81from lp.code.enums import (81from lp.code.enums import (
82 BranchLifecycleStatus, BranchType, UICreatableBranchType)82 BranchLifecycleStatus, BranchType, UICreatableBranchType)
83from lp.code.errors import InvalidBranchMergeProposal
83from lp.code.interfaces.branch import (84from lp.code.interfaces.branch import (
84 BranchCreationForbidden, BranchExists, IBranch,85 BranchCreationForbidden, BranchExists, IBranch,
85 user_has_special_branch_access)86 user_has_special_branch_access)
86from lp.code.interfaces.branchmergeproposal import InvalidBranchMergeProposal
87from lp.code.interfaces.branchtarget import IBranchTarget87from lp.code.interfaces.branchtarget import IBranchTarget
88from lp.code.interfaces.codeimport import CodeImportReviewStatus88from lp.code.interfaces.codeimport import CodeImportReviewStatus
89from lp.code.interfaces.codeimportjob import (89from lp.code.interfaces.codeimportjob import (
9090
=== modified file 'lib/lp/code/browser/branchmergeproposal.py'
--- lib/lp/code/browser/branchmergeproposal.py 2009-11-24 01:53:32 +0000
+++ lib/lp/code/browser/branchmergeproposal.py 2009-12-07 02:20:34 +0000
@@ -71,8 +71,8 @@
71from lp.code.enums import (71from lp.code.enums import (
72 BranchMergeProposalStatus, BranchType, CodeReviewNotificationLevel,72 BranchMergeProposalStatus, BranchType, CodeReviewNotificationLevel,
73 CodeReviewVote)73 CodeReviewVote)
74from lp.code.interfaces.branchmergeproposal import (74from lp.code.errors import WrongBranchMergeProposal
75 IBranchMergeProposal, WrongBranchMergeProposal)75from lp.code.interfaces.branchmergeproposal import IBranchMergeProposal
76from lp.code.interfaces.codereviewcomment import ICodeReviewComment76from lp.code.interfaces.codereviewcomment import ICodeReviewComment
77from lp.code.interfaces.codereviewvote import (77from lp.code.interfaces.codereviewvote import (
78 ICodeReviewVoteReference)78 ICodeReviewVoteReference)
7979
=== added file 'lib/lp/code/errors.py'
--- lib/lp/code/errors.py 1970-01-01 00:00:00 +0000
+++ lib/lp/code/errors.py 2009-12-07 02:20:33 +0000
@@ -0,0 +1,48 @@
1# Copyright 2009 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4"""Errors used in the lp/code modules."""
5
6__metaclass__ = type
7__all__ = [
8 'BadBranchMergeProposalSearchContext',
9 'BadStateTransition',
10 'BranchMergeProposalExists',
11 'InvalidBranchMergeProposal',
12 'UserNotBranchReviewer',
13 'WrongBranchMergeProposal',
14]
15
16
17class BadBranchMergeProposalSearchContext(Exception):
18 """The context is not valid for a branch merge proposal search."""
19
20
21class BadStateTransition(Exception):
22 """The user requested a state transition that is not possible."""
23
24
25class InvalidBranchMergeProposal(Exception):
26 """Raised during the creation of a new branch merge proposal.
27
28 The text of the exception is the rule violation.
29 """
30
31
32class BranchMergeProposalExists(InvalidBranchMergeProposal):
33 """Raised if there is already a matching BranchMergeProposal."""
34
35
36class UserNotBranchReviewer(Exception):
37 """The user who attempted to review the merge proposal isn't a reviewer.
38
39 A specific reviewer may be set on a branch. If a specific reviewer
40 isn't set then any user in the team of the owner of the branch is
41 considered a reviewer.
42 """
43
44
45class WrongBranchMergeProposal(Exception):
46 """The comment requested is not associated with this merge proposal."""
47
48
049
=== modified file 'lib/lp/code/interfaces/branchmergeproposal.py'
--- lib/lp/code/interfaces/branchmergeproposal.py 2009-10-23 00:48:47 +0000
+++ lib/lp/code/interfaces/branchmergeproposal.py 2009-12-07 02:20:33 +0000
@@ -7,11 +7,7 @@
77
8__metaclass__ = type8__metaclass__ = type
9__all__ = [9__all__ = [
10 'BadBranchMergeProposalSearchContext',
11 'BadStateTransition',
12 'BranchMergeProposalExists',
13 'BRANCH_MERGE_PROPOSAL_FINAL_STATES',10 'BRANCH_MERGE_PROPOSAL_FINAL_STATES',
14 'InvalidBranchMergeProposal',
15 'IBranchMergeProposal',11 'IBranchMergeProposal',
16 'IBranchMergeProposalGetter',12 'IBranchMergeProposalGetter',
17 'IBranchMergeProposalJob',13 'IBranchMergeProposalJob',
@@ -20,10 +16,9 @@
20 'ICreateMergeProposalJobSource',16 'ICreateMergeProposalJobSource',
21 'IMergeProposalCreatedJob',17 'IMergeProposalCreatedJob',
22 'IMergeProposalCreatedJobSource',18 'IMergeProposalCreatedJobSource',
23 'UserNotBranchReviewer',
24 'WrongBranchMergeProposal',
25 ]19 ]
2620
21
27from lazr.lifecycle.event import ObjectModifiedEvent22from lazr.lifecycle.event import ObjectModifiedEvent
28from zope.event import notify23from zope.event import notify
29from zope.interface import Attribute, Interface24from zope.interface import Attribute, Interface
@@ -47,38 +42,6 @@
47 REQUEST_USER)42 REQUEST_USER)
4843
4944
50class InvalidBranchMergeProposal(Exception):
51 """Raised during the creation of a new branch merge proposal.
52
53 The text of the exception is the rule violation.
54 """
55
56
57class BranchMergeProposalExists(InvalidBranchMergeProposal):
58 """Raised if there is already a matching BranchMergeProposal."""
59
60
61class UserNotBranchReviewer(Exception):
62 """The user who attempted to review the merge proposal isn't a reviewer.
63
64 A specific reviewer may be set on a branch. If a specific reviewer
65 isn't set then any user in the team of the owner of the branch is
66 considered a reviewer.
67 """
68
69
70class BadStateTransition(Exception):
71 """The user requested a state transition that is not possible."""
72
73
74class WrongBranchMergeProposal(Exception):
75 """The comment requested is not associated with this merge proposal."""
76
77
78class BadBranchMergeProposalSearchContext(Exception):
79 """The context is not valid for a branch merge proposal search."""
80
81
82BRANCH_MERGE_PROPOSAL_FINAL_STATES = (45BRANCH_MERGE_PROPOSAL_FINAL_STATES = (
83 BranchMergeProposalStatus.REJECTED,46 BranchMergeProposalStatus.REJECTED,
84 BranchMergeProposalStatus.MERGED,47 BranchMergeProposalStatus.MERGED,
8548
=== modified file 'lib/lp/code/mail/codehandler.py'
--- lib/lp/code/mail/codehandler.py 2009-10-23 19:33:09 +0000
+++ lib/lp/code/mail/codehandler.py 2009-12-07 02:20:33 +0000
@@ -36,10 +36,10 @@
36from canonical.launchpad.webapp.interfaces import ILaunchBag36from canonical.launchpad.webapp.interfaces import ILaunchBag
37from lazr.uri import URI37from lazr.uri import URI
38from lp.code.enums import BranchType, CodeReviewVote38from lp.code.enums import BranchType, CodeReviewVote
39from lp.code.errors import BranchMergeProposalExists, UserNotBranchReviewer
39from lp.code.interfaces.branchlookup import IBranchLookup40from lp.code.interfaces.branchlookup import IBranchLookup
40from lp.code.interfaces.branchmergeproposal import (41from lp.code.interfaces.branchmergeproposal import (
41 BranchMergeProposalExists, IBranchMergeProposalGetter,42 IBranchMergeProposalGetter, ICreateMergeProposalJobSource)
42 ICreateMergeProposalJobSource, UserNotBranchReviewer)
43from lp.code.interfaces.branchnamespace import (43from lp.code.interfaces.branchnamespace import (
44 lookup_branch_namespace, split_unique_name)44 lookup_branch_namespace, split_unique_name)
45from lp.code.interfaces.branchtarget import check_default_stacked_on45from lp.code.interfaces.branchtarget import check_default_stacked_on
4646
=== modified file 'lib/lp/code/model/branch.py'
--- lib/lp/code/model/branch.py 2009-11-26 22:55:06 +0000
+++ lib/lp/code/model/branch.py 2009-12-07 02:20:34 +0000
@@ -47,6 +47,8 @@
47from lp.code.enums import (47from lp.code.enums import (
48 BranchLifecycleStatus, BranchMergeControlStatus,48 BranchLifecycleStatus, BranchMergeControlStatus,
49 BranchMergeProposalStatus, BranchType)49 BranchMergeProposalStatus, BranchType)
50from lp.code.errors import (
51 BranchMergeProposalExists, InvalidBranchMergeProposal)
50from lp.code.mail.branch import send_branch_modified_notifications52from lp.code.mail.branch import send_branch_modified_notifications
51from lp.code.model.branchmergeproposal import (53from lp.code.model.branchmergeproposal import (
52 BranchMergeProposal, BranchMergeProposalGetter)54 BranchMergeProposal, BranchMergeProposalGetter)
@@ -63,8 +65,7 @@
63from lp.code.interfaces.branchcollection import IAllBranches65from lp.code.interfaces.branchcollection import IAllBranches
64from lp.code.interfaces.branchlookup import IBranchLookup66from lp.code.interfaces.branchlookup import IBranchLookup
65from lp.code.interfaces.branchmergeproposal import (67from lp.code.interfaces.branchmergeproposal import (
66 BRANCH_MERGE_PROPOSAL_FINAL_STATES, BranchMergeProposalExists,68 BRANCH_MERGE_PROPOSAL_FINAL_STATES)
67 InvalidBranchMergeProposal)
68from lp.code.interfaces.branchnamespace import IBranchNamespacePolicy69from lp.code.interfaces.branchnamespace import IBranchNamespacePolicy
69from lp.code.interfaces.branchpuller import IBranchPuller70from lp.code.interfaces.branchpuller import IBranchPuller
70from lp.code.interfaces.branchtarget import IBranchTarget71from lp.code.interfaces.branchtarget import IBranchTarget
7172
=== modified file 'lib/lp/code/model/branchmergeproposal.py'
--- lib/lp/code/model/branchmergeproposal.py 2009-12-07 02:20:32 +0000
+++ lib/lp/code/model/branchmergeproposal.py 2009-12-07 02:20:34 +0000
@@ -30,6 +30,9 @@
30from canonical.database.sqlbase import quote, SQLBase, sqlvalues30from canonical.database.sqlbase import quote, SQLBase, sqlvalues
3131
32from lp.code.enums import BranchMergeProposalStatus, CodeReviewVote32from lp.code.enums import BranchMergeProposalStatus, CodeReviewVote
33from lp.code.errors import (
34 BadBranchMergeProposalSearchContext, BadStateTransition,
35 UserNotBranchReviewer, WrongBranchMergeProposal)
33from lp.code.model.branchrevision import BranchRevision36from lp.code.model.branchrevision import BranchRevision
34from lp.code.model.codereviewcomment import CodeReviewComment37from lp.code.model.codereviewcomment import CodeReviewComment
35from lp.code.model.codereviewvote import (38from lp.code.model.codereviewvote import (
@@ -42,10 +45,8 @@
42from lp.code.interfaces.branch import IBranchNavigationMenu45from lp.code.interfaces.branch import IBranchNavigationMenu
43from lp.code.interfaces.branchcollection import IAllBranches46from lp.code.interfaces.branchcollection import IAllBranches
44from lp.code.interfaces.branchmergeproposal import (47from lp.code.interfaces.branchmergeproposal import (
45 BadBranchMergeProposalSearchContext, BadStateTransition,
46 BRANCH_MERGE_PROPOSAL_FINAL_STATES as FINAL_STATES,48 BRANCH_MERGE_PROPOSAL_FINAL_STATES as FINAL_STATES,
47 IBranchMergeProposal, IBranchMergeProposalGetter, UserNotBranchReviewer,49 IBranchMergeProposal, IBranchMergeProposalGetter)
48 WrongBranchMergeProposal)
49from lp.code.interfaces.branchtarget import IHasBranchTarget50from lp.code.interfaces.branchtarget import IHasBranchTarget
50from lp.registry.interfaces.person import IPerson51from lp.registry.interfaces.person import IPerson
51from lp.registry.interfaces.product import IProduct52from lp.registry.interfaces.product import IProduct
5253
=== modified file 'lib/lp/code/model/tests/test_branch.py'
--- lib/lp/code/model/tests/test_branch.py 2009-11-25 23:24:58 +0000
+++ lib/lp/code/model/tests/test_branch.py 2009-12-07 02:20:34 +0000
@@ -37,6 +37,7 @@
37from lp.code.enums import (37from lp.code.enums import (
38 BranchLifecycleStatus, BranchSubscriptionNotificationLevel, BranchType,38 BranchLifecycleStatus, BranchSubscriptionNotificationLevel, BranchType,
39 BranchVisibilityRule, CodeReviewNotificationLevel)39 BranchVisibilityRule, CodeReviewNotificationLevel)
40from lp.code.errors import InvalidBranchMergeProposal
40from lp.code.interfaces.branch import (41from lp.code.interfaces.branch import (
41 BranchCannotBePrivate, BranchCannotBePublic,42 BranchCannotBePrivate, BranchCannotBePublic,
42 BranchCreatorNotMemberOfOwnerTeam, BranchCreatorNotOwner,43 BranchCreatorNotMemberOfOwnerTeam, BranchCreatorNotOwner,
@@ -45,8 +46,7 @@
45from lp.code.interfaces.branchlookup import IBranchLookup46from lp.code.interfaces.branchlookup import IBranchLookup
46from lp.code.interfaces.branchnamespace import IBranchNamespaceSet47from lp.code.interfaces.branchnamespace import IBranchNamespaceSet
47from lp.code.interfaces.branchmergeproposal import (48from lp.code.interfaces.branchmergeproposal import (
48 BRANCH_MERGE_PROPOSAL_FINAL_STATES as FINAL_STATES,49 BRANCH_MERGE_PROPOSAL_FINAL_STATES as FINAL_STATES)
49 InvalidBranchMergeProposal)
50from lp.code.interfaces.linkedbranch import ICanHasLinkedBranch50from lp.code.interfaces.linkedbranch import ICanHasLinkedBranch
51from lp.code.interfaces.seriessourcepackagebranch import (51from lp.code.interfaces.seriessourcepackagebranch import (
52 IFindOfficialBranchLinks)52 IFindOfficialBranchLinks)
5353
=== modified file 'lib/lp/code/model/tests/test_branchmergeproposals.py'
--- lib/lp/code/model/tests/test_branchmergeproposals.py 2009-12-07 02:20:32 +0000
+++ lib/lp/code/model/tests/test_branchmergeproposals.py 2009-12-07 02:20:34 +0000
@@ -26,6 +26,8 @@
26from canonical.launchpad.interfaces import IPrivacy26from canonical.launchpad.interfaces import IPrivacy
27from canonical.launchpad.interfaces.message import IMessageJob27from canonical.launchpad.interfaces.message import IMessageJob
28from canonical.launchpad.webapp.testing import verifyObject28from canonical.launchpad.webapp.testing import verifyObject
29from lp.code.errors import (
30 BadStateTransition, WrongBranchMergeProposal)
29from lp.code.event.branchmergeproposal import (31from lp.code.event.branchmergeproposal import (
30 NewBranchMergeProposalEvent, NewCodeReviewCommentEvent,32 NewBranchMergeProposalEvent, NewCodeReviewCommentEvent,
31 ReviewerNominatedEvent)33 ReviewerNominatedEvent)
@@ -36,11 +38,10 @@
36 BranchType, CodeReviewNotificationLevel, CodeReviewVote,38 BranchType, CodeReviewNotificationLevel, CodeReviewVote,
37 BranchVisibilityRule)39 BranchVisibilityRule)
38from lp.code.interfaces.branchmergeproposal import (40from lp.code.interfaces.branchmergeproposal import (
39 BadStateTransition,
40 BRANCH_MERGE_PROPOSAL_FINAL_STATES as FINAL_STATES,41 BRANCH_MERGE_PROPOSAL_FINAL_STATES as FINAL_STATES,
41 IBranchMergeProposal, IBranchMergeProposalGetter, IBranchMergeProposalJob,42 IBranchMergeProposal, IBranchMergeProposalGetter, IBranchMergeProposalJob,
42 ICreateMergeProposalJob, ICreateMergeProposalJobSource,43 ICreateMergeProposalJob, ICreateMergeProposalJobSource,
43 IMergeProposalCreatedJob, notify_modified, WrongBranchMergeProposal)44 IMergeProposalCreatedJob, notify_modified)
44from lp.code.model.branchmergeproposaljob import (45from lp.code.model.branchmergeproposaljob import (
45 BranchMergeProposalJob, BranchMergeProposalJobType,46 BranchMergeProposalJob, BranchMergeProposalJobType,
46 CreateMergeProposalJob, MergeProposalCreatedJob, UpdatePreviewDiffJob)47 CreateMergeProposalJob, MergeProposalCreatedJob, UpdatePreviewDiffJob)

Subscribers

People subscribed via source and target branches

to status/vote changes: