~launchpad-pqm/launchpad/devel

9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
1
== Create a new merge proposal ==
2
3
Branch merge proposals can be created through the API.
4
5
    >>> from canonical.launchpad.testing.pages import webservice_for_person
6
    >>> from canonical.launchpad.webapp.interfaces import OAuthPermission
7
    >>> from lazr.restful.testing.webservice import pprint_entry
8
    >>> login('admin@canonical.com')
9
    >>> target = factory.makeBranch()
10420.4.9 by Leonard Richardson
Fix the branch merge proposal test in a way that doesn't break a whole lot of other tests.
10
10420.4.5 by Leonard Richardson
Made canonical_url work correctly with versioned web service requests.
11
    >>> from canonical.launchpad.webapp.servers import WebServiceTestRequest
12
    >>> request = WebServiceTestRequest(version="beta")
10420.4.9 by Leonard Richardson
Fix the branch merge proposal test in a way that doesn't break a whole lot of other tests.
13
    >>> request.processInputs()
14
15
    >>> from lazr.restful.utils import get_current_web_service_request
16
    >>> request = get_current_web_service_request()
17
18
    >>> def fix_url(url):
19
    ...     """Convert a browser request to a web service client request.
20
    ...     This is a bit of a hack, but it's the simplest way to get a
21
    ...     URL that the web service client will respect."""
22
    ...     return url.replace("launchpad.dev/api/", "api.launchpad.dev/")
23
24
    >>> target_url = fix_url(str(canonical_url(
25
    ...     target, request=request, rootsite='api')))
9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
26
    >>> source = factory.makeBranchTargetBranch(target.target)
10420.4.9 by Leonard Richardson
Fix the branch merge proposal test in a way that doesn't break a whole lot of other tests.
27
    >>> source_url = fix_url(str(
28
    ...     canonical_url(source, request=request, rootsite='api')))
9801.1.2 by Aaron Bentley
Expose prerequisite_branch and initial comment.
29
    >>> prerequisite = factory.makeBranchTargetBranch(target.target)
10420.4.9 by Leonard Richardson
Fix the branch merge proposal test in a way that doesn't break a whole lot of other tests.
30
    >>> prerequisite_url = fix_url(str(canonical_url(
31
    ...     prerequisite, request=request, rootsite='api')))
9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
32
    >>> registrant = source.registrant
10420.4.9 by Leonard Richardson
Fix the branch merge proposal test in a way that doesn't break a whole lot of other tests.
33
    >>> reviewer_url = fix_url(str(canonical_url(
34
    ...     factory.makePerson(), request=request, rootsite='api')))
9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
35
    >>> logout()
36
    >>> registrant_webservice = webservice_for_person(
37
    ...     registrant, permission=OAuthPermission.WRITE_PUBLIC)
38
    >>> bmp_result = registrant_webservice.named_post(
9801.1.6 by Aaron Bentley
Allow creating merge proposal with reviewers via API.
39
    ...     source_url, 'createMergeProposal', target_branch=target_url,
9801.1.11 by Aaron Bentley
Allow newlines in initial comment and commit message.
40
    ...     prerequisite_branch=prerequisite_url,
41
    ...     initial_comment='Merge\nit!', needs_review=True,
42
    ...     commit_message='It was merged!\n', reviewers=[reviewer_url],
43
    ...     review_types=['green'])
9801.1.2 by Aaron Bentley
Expose prerequisite_branch and initial comment.
44
    >>> bmp_url = bmp_result.getHeader('Location')
45
    >>> bmp = registrant_webservice.get(bmp_url).jsonBody()
46
    >>> pprint_entry(bmp)
9801.1.9 by Aaron Bentley
Simplify branch locations.
47
    address: u'mp+...@code.launchpad.dev'
9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
48
    all_comments_collection_link:
10420.4.9 by Leonard Richardson
Fix the branch merge proposal test in a way that doesn't break a whole lot of other tests.
49
        u'http://api.launchpad.dev/devel/~.../+merge/.../all_comments'
9801.1.11 by Aaron Bentley
Allow newlines in initial comment and commit message.
50
    commit_message: u'It was merged!\n'
9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
51
    date_created: u'...'
52
    date_merged: None
53
    date_queued: None
9801.1.3 by Aaron Bentley
Export needs_review
54
    date_review_requested: u'...'
9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
55
    date_reviewed: None
7675.548.6 by Tim Penhey
Update the webservice for descriptions.
56
    description: u'Merge\nit!'
9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
57
    merge_reporter_link: None
58
    merged_revno: None
10420.4.9 by Leonard Richardson
Fix the branch merge proposal test in a way that doesn't break a whole lot of other tests.
59
    prerequisite_branch_link: u'http://api.launchpad.dev/devel/~...'
9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
60
    preview_diff_link: None
61
    private: False
62
    queue_position: None
9801.1.3 by Aaron Bentley
Export needs_review
63
    queue_status: u'Needs review'
7675.508.7 by Tim Penhey
Fix the broken tests.
64
    queued_revid: None
9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
65
    queuer_link: None
10420.4.9 by Leonard Richardson
Fix the branch merge proposal test in a way that doesn't break a whole lot of other tests.
66
    registrant_link: u'http://api.launchpad.dev/devel/~person-name...'
9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
67
    resource_type_link:
10420.4.9 by Leonard Richardson
Fix the branch merge proposal test in a way that doesn't break a whole lot of other tests.
68
        u'http://api.launchpad.dev/devel/#branch_merge_proposal'
7675.508.7 by Tim Penhey
Fix the broken tests.
69
    reviewed_revid: None
9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
70
    reviewer_link: None
10420.4.9 by Leonard Richardson
Fix the branch merge proposal test in a way that doesn't break a whole lot of other tests.
71
    self_link: u'http://api.launchpad.dev/devel/~.../+merge/...'
72
    source_branch_link: u'http://api.launchpad.dev/devel/~...'
9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
73
    superseded_by_link: None
74
    supersedes_link: None
10420.4.9 by Leonard Richardson
Fix the branch merge proposal test in a way that doesn't break a whole lot of other tests.
75
    target_branch_link: u'http://api.launchpad.dev/devel/~...'
9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
76
    votes_collection_link:
10420.4.9 by Leonard Richardson
Fix the branch merge proposal test in a way that doesn't break a whole lot of other tests.
77
        u'http://api.launchpad.dev/devel/~.../+merge/.../votes'
12243.5.6 by Leonard Richardson
Got another batch of tests to pass.
78
    web_link: u'http://code.../~.../+merge/...'
9801.1.2 by Aaron Bentley
Expose prerequisite_branch and initial comment.
79
10466.1.3 by Paul Hummer
Added failing test
80
If we try and create the merge proposal again, we should get a ValueError.
81
82
    >>> print registrant_webservice.named_post(
83
    ...     source_url, 'createMergeProposal', target_branch=target_url,
84
    ...     prerequisite_branch=prerequisite_url,
85
    ...     initial_comment='Merge\nit!', needs_review=True,
86
    ...     commit_message='It was merged!\n', reviewers=[reviewer_url],
87
    ...     review_types=['green'])
12361.1.7 by Tim Penhey
Fix the traceback removal on the webservice tests.
88
    HTTP/1.1 400 Bad Request
89
    ...
90
    There is already a branch merge proposal registered for branch
91
    ... to land on ... that is still active.
10466.1.3 by Paul Hummer
Added failing test
92
9801.1.6 by Aaron Bentley
Allow creating merge proposal with reviewers via API.
93
Our review request is listed in the votes collection.
94
95
    >>> votes = webservice.get(
96
    ...     bmp['votes_collection_link']).jsonBody()
97
    >>> pprint_entry(votes['entries'][0])
10420.4.9 by Leonard Richardson
Fix the branch merge proposal test in a way that doesn't break a whole lot of other tests.
98
    branch_merge_proposal_link: u'http://api.launchpad.dev/devel/~.../+merge/...'
9801.1.6 by Aaron Bentley
Allow creating merge proposal with reviewers via API.
99
    comment_link: None
100
    date_created: u'...'
7675.430.1 by Tim Penhey
Add the is_pending bits to the webservice tests.
101
    is_pending: True
10420.4.9 by Leonard Richardson
Fix the branch merge proposal test in a way that doesn't break a whole lot of other tests.
102
    registrant_link: u'http://api.launchpad.dev/devel/~person-name...'
103
    resource_type_link: u'http://api.launchpad.dev/devel/#code_review_vote_reference'
9801.1.6 by Aaron Bentley
Allow creating merge proposal with reviewers via API.
104
    review_type: u'green'
10420.4.9 by Leonard Richardson
Fix the branch merge proposal test in a way that doesn't break a whole lot of other tests.
105
    reviewer_link: u'http://api.launchpad.dev/devel/~person-name...'
106
    self_link: u'http://api.launchpad.dev/devel/~...'
9801.1.6 by Aaron Bentley
Allow creating merge proposal with reviewers via API.
107
7325.8.2 by Paul Hummer
Added failing test for getting a branch merge proposal
108
== Get an existing merge proposal ==
109
110
Branch merge proposals can be fetched through the API.
111
7771.3.2 by Tim Penhey
Fix the doctest to not use an admin.
112
    >>> login('admin@canonical.com')
11542.3.26 by Ian Booth
Fix some tests after merge from trunk
113
    >>> from lp.code.tests.helpers import (
114
    ...     make_merge_proposal_without_reviewers)
115
    >>> fixit_proposal = make_merge_proposal_without_reviewers(factory)
7701.1.7 by Paul Hummer
Got approved merge proposals working
116
    >>> fixit_proposal.source_branch.owner.name = 'source'
117
    >>> fixit_proposal.source_branch.name = 'fix-it'
118
    >>> fixit_proposal.target_branch.owner.name = 'target'
119
    >>> fixit_proposal.target_branch.name = 'trunk'
8555.1.6 by Tim Penhey
Get the branch merge proposals for a project.~
120
    >>> fooix = fixit_proposal.source_branch.product
121
    >>> fooix.name = 'fooix'
8555.2.9 by Tim Penhey
Move CodeReviewVote enum.
122
    >>> from lp.code.enums import CodeReviewVote
7719.1.1 by Paul Hummer
Added comments to the bmp api test
123
    >>> comment = factory.makeCodeReviewComment(
124
    ...     subject='Looks good', body='This is great work',
125
    ...     vote=CodeReviewVote.APPROVE, vote_tag='code',
126
    ...     merge_proposal=fixit_proposal)
127
    >>> comment2 = factory.makeCodeReviewComment(
128
    ...     subject='Not really', body='This is mediocre work.',
129
    ...     vote=CodeReviewVote.ABSTAIN, parent=comment,
130
    ...     merge_proposal=fixit_proposal)
7176.8.22 by Stuart Bishop
Fix xx-branchmergeproposal.txt
131
    >>> transaction.commit()
7719.1.1 by Paul Hummer
Added comments to the bmp api test
132
10420.4.9 by Leonard Richardson
Fix the branch merge proposal test in a way that doesn't break a whole lot of other tests.
133
    >>> proposal_url = fix_url(canonical_url(
134
    ...     fixit_proposal, request=request, rootsite='api'))
7771.3.2 by Tim Penhey
Fix the doctest to not use an admin.
135
    >>> new_person = factory.makePerson()
136
    >>> target_owner = fixit_proposal.target_branch.owner
7325.8.2 by Paul Hummer
Added failing test for getting a branch merge proposal
137
    >>> logout()
138
7771.3.3 by Tim Penhey
Updates following review.
139
We use the webservice as an unrelated, unprivileged user.
7771.3.2 by Tim Penhey
Fix the doctest to not use an admin.
140
141
    >>> webservice = webservice_for_person(
142
    ...     new_person, permission=OAuthPermission.READ_PUBLIC)
143
7325.8.2 by Paul Hummer
Added failing test for getting a branch merge proposal
144
    >>> merge_proposal = webservice.get(proposal_url).jsonBody()
145
    >>> pprint_entry(merge_proposal)
9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
146
    address: u'mp+...@code.launchpad.dev'
147
    all_comments_collection_link: u'http://.../~source/fooix/fix-it/+merge/.../all_comments'
7325.8.8 by Paul Hummer
Added commit_message attribute
148
    commit_message: None
7325.8.12 by Paul Hummer
Added date attributes
149
    date_created: ...
7325.8.11 by Paul Hummer
Addded date_merged attribute
150
    date_merged: None
7325.8.12 by Paul Hummer
Added date attributes
151
    date_queued: None
152
    date_review_requested: None
153
    date_reviewed: None
7675.548.6 by Tim Penhey
Update the webservice for descriptions.
154
    description: None
7325.8.16 by Paul Hummer
Added merge_reporter attribute
155
    merge_reporter_link: None
7325.8.10 by Paul Hummer
merged_revno attribute added
156
    merged_revno: None
7675.343.1 by Aaron Bentley
Rename dependent branch to prerequisite branch.
157
    prerequisite_branch_link: None
7667.9.6 by Tim Penhey
Add traversal and tests.
158
    preview_diff_link: None
9373.2.4 by Aaron Bentley
Fix API test
159
    private: False
7325.8.9 by Paul Hummer
Added queue_position attribute
160
    queue_position: None
7325.8.7 by Paul Hummer
Added queue_states attribute
161
    queue_status: u'Work in progress'
7675.508.7 by Tim Penhey
Fix the broken tests.
162
    queued_revid: None
7325.8.15 by Paul Hummer
Added queuer_link attribute
163
    queuer_link: None
7675.300.1 by Aaron Bentley
Support makeBranchMergeProposal for package branches
164
    registrant_link: u'http://.../~person-name...'
7719.1.2 by Paul Hummer
Exposed IBranchMergeProposal.all_comments through the API
165
    resource_type_link: u'http://.../#branch_merge_proposal'
7675.508.7 by Tim Penhey
Fix the broken tests.
166
    reviewed_revid: None
7325.8.14 by Paul Hummer
Added reviewer_link attribute
167
    reviewer_link: None
7719.1.2 by Paul Hummer
Exposed IBranchMergeProposal.all_comments through the API
168
    self_link: u'http://.../~source/fooix/fix-it/+merge/...'
169
    source_branch_link: u'http://.../~source/fooix/fix-it'
7325.8.18 by Paul Hummer
Added supersedes and superseded by
170
    superseded_by_link: None
171
    supersedes_link: None
7719.1.2 by Paul Hummer
Exposed IBranchMergeProposal.all_comments through the API
172
    target_branch_link: u'http://.../~target/fooix/trunk'
7944.2.1 by Paul Hummer
Added tests for exposing the IBranchMergeProposal.votes
173
    votes_collection_link: u'http://.../~source/fooix/fix-it/+merge/.../votes'
12243.5.6 by Leonard Richardson
Got another batch of tests to pass.
174
    web_link: u'http://code.../~source/fooix/fix-it/+merge/...'
7325.8.2 by Paul Hummer
Added failing test for getting a branch merge proposal
175
7325.8.1 by Paul Hummer
Added branchmergeproposal test stub
176
7719.1.3 by Paul Hummer
Added failing test for exposing ICodeReviewComment
177
== Read the comments ==
178
179
The comments on a branch merge proposal are exposed through the API.
180
181
    >>> all_comments = webservice.get(
182
    ...     merge_proposal['all_comments_collection_link']).jsonBody()
7719.1.5 by Paul Hummer
Refactored the test
183
    >>> print len(all_comments['entries'])
184
    2
185
    >>> pprint_entry(all_comments['entries'][0])
9742.8.10 by Aaron Bentley
Update test for API expansion.
186
    as_quoted_email: u'> This is great work'
10384.1.3 by Tim Penhey
Add the author link to the page test.
187
    author_link: u'http://api.launchpad.dev/devel/~...'
9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
188
    branch_merge_proposal_link: u'http://.../~source/fooix/fix-it/+merge/...'
10384.1.4 by Tim Penhey
Export the date_created of the code review comment.
189
    date_created: u'...'
9801.1.2 by Aaron Bentley
Expose prerequisite_branch and initial comment.
190
    id: ...
7719.1.4 by Paul Hummer
Exposed the rest of CodeReviewComment
191
    message_body: u'This is great work'
7719.2.19 by Paul Hummer
Fixed the tests to be more detailed
192
    resource_type_link: u'http://.../#code_review_comment'
9801.1.2 by Aaron Bentley
Expose prerequisite_branch and initial comment.
193
    self_link: u'http://.../~source/fooix/fix-it/+merge/.../comments/...'
8377.8.19 by Tim Penhey
Make the branch displayname refer to bzr_identity instead of unique name.
194
    title: u'Comment on proposed merge of lp://dev/~source/fooix/fix-it into lp://dev/~target/fooix/trunk'
7719.1.4 by Paul Hummer
Exposed the rest of CodeReviewComment
195
    vote: u'Approve'
196
    vote_tag: u'code'
12243.5.6 by Leonard Richardson
Got another batch of tests to pass.
197
    web_link: u'http://code.../~source/fooix/fix-it/+merge/.../comments/...'
7719.1.3 by Paul Hummer
Added failing test for exposing ICodeReviewComment
198
7719.2.6 by Paul Hummer
Fixed test
199
    >>> comment_2 = webservice.named_get(
7675.548.6 by Tim Penhey
Update the webservice for descriptions.
200
    ...     merge_proposal['self_link'], 'getComment', id=2).jsonBody()
7719.2.6 by Paul Hummer
Fixed test
201
    >>> pprint_entry(comment_2)
9742.8.10 by Aaron Bentley
Update test for API expansion.
202
    as_quoted_email: u'> This is mediocre work.'
10384.1.3 by Tim Penhey
Add the author link to the page test.
203
    author_link: u'http://api.launchpad.dev/devel/~...'
9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
204
    branch_merge_proposal_link: u'http://.../~source/fooix/fix-it/+merge/...'
10384.1.4 by Tim Penhey
Export the date_created of the code review comment.
205
    date_created: u'...'
9801.1.2 by Aaron Bentley
Expose prerequisite_branch and initial comment.
206
    id: ...
7719.2.6 by Paul Hummer
Fixed test
207
    message_body: u'This is mediocre work.'
208
    resource_type_link: u'http://.../#code_review_comment'
9801.1.2 by Aaron Bentley
Expose prerequisite_branch and initial comment.
209
    self_link: u'http://.../~source/fooix/fix-it/+merge/.../comments/...'
8377.8.19 by Tim Penhey
Make the branch displayname refer to bzr_identity instead of unique name.
210
    title: ...
7719.2.6 by Paul Hummer
Fixed test
211
    vote: u'Abstain'
212
    vote_tag: None
12243.5.6 by Leonard Richardson
Got another batch of tests to pass.
213
    web_link: u'http://code.../~source/fooix/fix-it/+merge/.../comments/...'
7719.1.3 by Paul Hummer
Added failing test for exposing ICodeReviewComment
214
7719.2.8 by Paul Hummer
Added test for isPersonValidReviewer
215
7944.2.1 by Paul Hummer
Added tests for exposing the IBranchMergeProposal.votes
216
== Check the votes ==
217
7944.2.3 by Paul Hummer
Responded to jml's review
218
The votes on a branch merge proposal can be checked through the API.
7944.2.1 by Paul Hummer
Added tests for exposing the IBranchMergeProposal.votes
219
220
    >>> votes = webservice.get(
221
    ...     merge_proposal['votes_collection_link']).jsonBody()['entries']
222
    >>> print len(votes)
223
    2
224
    >>> pprint_entry(votes[0])
225
    branch_merge_proposal_link: u'http://.../~source/fooix/fix-it/+merge/...'
9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
226
    comment_link: u'http://.../~source/fooix/fix-it/+merge/.../comments/...'
7944.2.1 by Paul Hummer
Added tests for exposing the IBranchMergeProposal.votes
227
    date_created: u'...'
7675.430.1 by Tim Penhey
Add the is_pending bits to the webservice tests.
228
    is_pending: False
9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
229
    registrant_link: u'http://.../~person-name...'
7944.2.1 by Paul Hummer
Added tests for exposing the IBranchMergeProposal.votes
230
    resource_type_link: u'http://.../#code_review_vote_reference'
231
    review_type: u'code'
9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
232
    reviewer_link: u'http://.../~person-name...'
7944.2.1 by Paul Hummer
Added tests for exposing the IBranchMergeProposal.votes
233
    self_link: u'http://.../~source/fooix/fix-it/+merge/.../+review/...'
234
235
7719.2.8 by Paul Hummer
Added test for isPersonValidReviewer
236
== Performing a Review ==
237
238
A review can be performed through the API.
239
9041.4.1 by Tim Penhey
Move isPersonTrustedReviewer to the IBranch interface.
240
A review can be requested of the person 'target'.
7719.2.9 by Paul Hummer
Added test for nominateReviewer
241
7771.3.2 by Tim Penhey
Fix the doctest to not use an admin.
242
    >>> reviewer_webservice = webservice_for_person(
243
    ...     target_owner, permission=OAuthPermission.WRITE_PUBLIC)
244
9041.4.5 by Tim Penhey
Fix the breakage of the branchmergeproposal webservice story.
245
    >>> person = webservice.get('/~target').jsonBody()
7771.3.2 by Tim Penhey
Fix the doctest to not use an admin.
246
    >>> reviewer = reviewer_webservice.named_post(
7719.2.9 by Paul Hummer
Added test for nominateReviewer
247
    ...     merge_proposal['self_link'], 'nominateReviewer',
248
    ...     reviewer=person['self_link'], review_type='code')
7719.2.19 by Paul Hummer
Fixed the tests to be more detailed
249
    >>> print reviewer
250
    HTTP/1.1 200 Ok ...
7719.2.22 by Paul Hummer
Responded to Michael's review
251
    >>> reviewer_entry = reviewer.jsonBody()
252
    >>> pprint_entry(reviewer_entry)
9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
253
    branch_merge_proposal_link: u'http://.../~source/fooix/fix-it/+merge/...'
7719.2.19 by Paul Hummer
Fixed the tests to be more detailed
254
    comment_link: None
255
    date_created: u'...'
7675.430.1 by Tim Penhey
Add the is_pending bits to the webservice tests.
256
    is_pending: True
7771.3.2 by Tim Penhey
Fix the doctest to not use an admin.
257
    registrant_link: u'http://.../~target'
7719.2.19 by Paul Hummer
Fixed the tests to be more detailed
258
    resource_type_link: u'http://.../#code_review_vote_reference'
259
    review_type: u'code'
7771.3.2 by Tim Penhey
Fix the doctest to not use an admin.
260
    reviewer_link: u'http://.../~target'
9801.1.6 by Aaron Bentley
Allow creating merge proposal with reviewers via API.
261
    self_link: u'http://.../~source/fooix/fix-it/+merge/.../+review/...'
7719.2.9 by Paul Hummer
Added test for nominateReviewer
262
7771.3.2 by Tim Penhey
Fix the doctest to not use an admin.
263
    >>> vote = reviewer_webservice.get(reviewer_entry['self_link'])
7719.2.22 by Paul Hummer
Responded to Michael's review
264
    >>> print vote
265
    HTTP/1.1 200 Ok ...
266
7719.2.11 by Paul Hummer
Working around circular imports still
267
Now the code review should be made.
268
9558.6.42 by Aaron Bentley
Fix failing test.
269
    >>> comment_result = reviewer_webservice.named_post(
7719.2.11 by Paul Hummer
Working around circular imports still
270
    ...     merge_proposal['self_link'], 'createComment',
271
    ...     subject='Great work', content='This is great work',
9558.6.42 by Aaron Bentley
Fix failing test.
272
    ...     vote=CodeReviewVote.APPROVE.title, review_type='code')
9801.1.5 by Aaron Bentley
Cleanup
273
    >>> comment_link = comment_result.getHeader('Location')
274
    >>> comment = reviewer_webservice.get(comment_link).jsonBody()
275
    >>> pprint_entry(comment)
9742.8.10 by Aaron Bentley
Update test for API expansion.
276
    as_quoted_email: u'> This is great work'
10384.1.3 by Tim Penhey
Add the author link to the page test.
277
    author_link: u'http://api.launchpad.dev/devel/~...'
9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
278
    branch_merge_proposal_link: u'http://.../~source/fooix/fix-it/+merge/...'
10384.1.4 by Tim Penhey
Export the date_created of the code review comment.
279
    date_created: u'...'
9801.1.2 by Aaron Bentley
Expose prerequisite_branch and initial comment.
280
    id: ...
7719.2.11 by Paul Hummer
Working around circular imports still
281
    message_body: u'This is great work'
7719.2.19 by Paul Hummer
Fixed the tests to be more detailed
282
    resource_type_link: u'http://.../#code_review_comment'
9801.1.2 by Aaron Bentley
Expose prerequisite_branch and initial comment.
283
    self_link: u'http://.../~source/fooix/fix-it/+merge/.../comments/...'
8377.8.19 by Tim Penhey
Make the branch displayname refer to bzr_identity instead of unique name.
284
    title: ...
7719.2.13 by Paul Hummer
Got review test working
285
    vote: u'Approve'
7719.2.11 by Paul Hummer
Working around circular imports still
286
    vote_tag: u'code'
12243.5.6 by Leonard Richardson
Got another batch of tests to pass.
287
    web_link: u'http://code.../~source/fooix/fix-it/+merge/.../comments/...'
7719.2.8 by Paul Hummer
Added test for isPersonValidReviewer
288
8879.3.9 by Paul Hummer
Exposed IBranchMergeProposal.setStatus through the API
289
In fact, now that the votes indicate approval, we might as well set the merge
290
proposal status to "Approved" as well.
291
292
    >>> _unused = reviewer_webservice.named_post(
293
    ...     merge_proposal['self_link'], 'setStatus',
7675.508.7 by Tim Penhey
Fix the broken tests.
294
    ...     status=u'Approved', revid=u'25')
8879.3.9 by Paul Hummer
Exposed IBranchMergeProposal.setStatus through the API
295
    >>> merge_proposal = reviewer_webservice.get(
296
    ...     merge_proposal['self_link']).jsonBody()
297
298
    >>> print merge_proposal['queue_status']
299
    Approved
7675.508.7 by Tim Penhey
Fix the broken tests.
300
    >>> print merge_proposal['reviewed_revid']
8879.3.9 by Paul Hummer
Exposed IBranchMergeProposal.setStatus through the API
301
    25
302
8879.3.11 by Paul Hummer
Added test for ensuring revision_id argument to IBranchMergeProposal.setStatus is optional
303
However, there may have been breakage in the branch, and we need to revert back
304
to "Work In Progress" and not specify the revision_id.
305
306
    >>> _unused = reviewer_webservice.named_post(
307
    ...     merge_proposal['self_link'], 'setStatus',
308
    ...     status=u'Work in progress')
309
    >>> merge_proposal = reviewer_webservice.get(
310
    ...     merge_proposal['self_link']).jsonBody()
311
312
    >>> print merge_proposal['queue_status']
313
    Work in progress
7675.508.7 by Tim Penhey
Fix the broken tests.
314
    >>> print merge_proposal['reviewed_revid']
8879.3.11 by Paul Hummer
Added test for ensuring revision_id argument to IBranchMergeProposal.setStatus is optional
315
    None
316
8879.3.9 by Paul Hummer
Exposed IBranchMergeProposal.setStatus through the API
317
7667.9.6 by Tim Penhey
Add traversal and tests.
318
== Updating the preview diff ==
319
320
The merge proposal can now be updated with the diff that reflects what the
321
merge would look like if the source branch was merged into the target branch.
322
323
    >>> diff_content = '''\
324
    ... === modified file 'fooix.txt'
9222.4.11 by Aaron Bentley
Remove diffstat parameter from pretty much everything.
325
    ... --- fooix.txt\t2009-01-01 12:00:00 +0000
326
    ... +++ fooix.txt\t2009-02-02 12:34:56 +0000
327
    ... @@ -206,7 +206,7 @@
7667.9.6 by Tim Penhey
Add traversal and tests.
328
    ...  original
329
    ... -removed
330
    ... +added
331
    ... '''
7771.3.2 by Tim Penhey
Fix the doctest to not use an admin.
332
    >>> response = reviewer_webservice.named_post(
7667.9.6 by Tim Penhey
Add traversal and tests.
333
    ...     merge_proposal['self_link'], 'updatePreviewDiff',
334
    ...     diff_content=diff_content,
9222.4.11 by Aaron Bentley
Remove diffstat parameter from pretty much everything.
335
    ...     source_revision_id='rev-a',
7667.9.6 by Tim Penhey
Add traversal and tests.
336
    ...     target_revision_id='rev-b', conflicts='oh, no conflicts')
9123.2.3 by Gary Poster
fix webservice tests
337
    >>> print response
7667.9.6 by Tim Penhey
Add traversal and tests.
338
    HTTP/1.1 200 Ok
9123.2.3 by Gary Poster
fix webservice tests
339
    ...
7667.9.6 by Tim Penhey
Add traversal and tests.
340
    Content-Type: application/json
7703.4.6 by Francis J. Lacoste
Update pagetests for Vary header.
341
    Vary: ...
7688.1.11 by Tim Penhey
Update code to take into account the earlier changes that had been merged into trunk.
342
    ...
7667.9.6 by Tim Penhey
Add traversal and tests.
343
344
The diff is now visible through the merge proposal.
345
346
    >>> merge_proposal = webservice.get(proposal_url).jsonBody()
347
    >>> preview_diff = webservice.get(
348
    ...     merge_proposal['preview_diff_link']).jsonBody()
349
    >>> pprint_entry(preview_diff)
7675.342.3 by Aaron Bentley
Fix test.
350
    added_lines_count: 0
7667.9.7 by Tim Penhey
Tested API calls to update and extract preview diffs.
351
    branch_merge_proposal_link:
9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
352
      u'http://.../~source/fooix/fix-it/+merge/...'
7667.9.7 by Tim Penhey
Tested API calls to update and extract preview diffs.
353
    conflicts: u'oh, no conflicts'
7688.1.11 by Tim Penhey
Update code to take into account the earlier changes that had been merged into trunk.
354
    diff_lines_count: 7
7667.9.7 by Tim Penhey
Tested API calls to update and extract preview diffs.
355
    diff_text_link:
9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
356
      u'http://.../~source/fooix/fix-it/+merge/.../+preview-diff/diff_text'
9222.4.11 by Aaron Bentley
Remove diffstat parameter from pretty much everything.
357
    diffstat: {u'fooix.txt': [0, 0]}
7675.343.1 by Aaron Bentley
Rename dependent branch to prerequisite branch.
358
    prerequisite_revision_id: None
7675.342.3 by Aaron Bentley
Fix test.
359
    removed_lines_count: 0
7719.2.19 by Paul Hummer
Fixed the tests to be more detailed
360
    resource_type_link: u'http://.../#preview_diff'
7667.9.7 by Tim Penhey
Tested API calls to update and extract preview diffs.
361
    self_link:
9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
362
      u'http://.../~source/fooix/fix-it/+merge/.../+preview-diff'
7667.9.7 by Tim Penhey
Tested API calls to update and extract preview diffs.
363
    source_revision_id: u'rev-a'
7688.1.4 by Tim Penhey
Add the stale output to the api test result.
364
    stale: True
7667.9.7 by Tim Penhey
Tested API calls to update and extract preview diffs.
365
    target_revision_id: u'rev-b'
7667.9.6 by Tim Penhey
Add traversal and tests.
366
7675.8.1 by Tim Penhey
Expose a few more bits of branch (that I want), and add an explicit flush to get around a storm bug.
367
It is possible that the diff will be empty.
368
369
    >>> response = reviewer_webservice.named_post(
370
    ...     merge_proposal['self_link'], 'updatePreviewDiff',
371
    ...     diff_content='',
372
    ...     diff_stat='', source_revision_id='rev-c',
373
    ...     target_revision_id='rev-d', conflicts=None)
9123.2.3 by Gary Poster
fix webservice tests
374
    >>> print response
7675.8.1 by Tim Penhey
Expose a few more bits of branch (that I want), and add an explicit flush to get around a storm bug.
375
    HTTP/1.1 200 Ok
9123.2.3 by Gary Poster
fix webservice tests
376
    ...
7675.8.1 by Tim Penhey
Expose a few more bits of branch (that I want), and add an explicit flush to get around a storm bug.
377
    Content-Type: application/json
378
    Vary: ...
379
    ...
7701.1.1 by Paul Hummer
Added failing test
380
381
== Getting a Project's Pending Merge Proposals ==
382
383
It is possible to view all of a project's merge proposals or filter the
384
proposals by their status.
385
7701.1.7 by Paul Hummer
Got approved merge proposals working
386
    >>> def print_proposal(proposal):
7701.1.6 by Paul Hummer
Added status checking to the test
387
    ...     print proposal['self_link'] + ' - ' + \
388
    ...         proposal['queue_status']
7701.1.7 by Paul Hummer
Got approved merge proposals working
389
390
391
    >>> proposals = webservice.named_get(
392
    ...     '/fooix', 'getMergeProposals').jsonBody()
393
    >>> for proposal in proposals['entries']:
394
    ...     print_proposal(proposal)
9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
395
    http://.../~source/fooix/fix-it/+merge/... - Work in progress
7701.1.1 by Paul Hummer
Added failing test
396
397
7771.3.3 by Tim Penhey
Updates following review.
398
Or I can look for anything that is approved.
7701.1.7 by Paul Hummer
Got approved merge proposals working
399
7771.3.2 by Tim Penhey
Fix the doctest to not use an admin.
400
    >>> login('admin@canonical.com')
8555.2.4 by Tim Penhey
Move BranchMergeProposalStatus.
401
    >>> from lp.code.enums import BranchMergeProposalStatus
7771.3.2 by Tim Penhey
Fix the doctest to not use an admin.
402
    >>> fixit_proposal.approveBranch(fixit_proposal.target_branch.owner, '1')
7701.1.7 by Paul Hummer
Got approved merge proposals working
403
    >>> logout()
404
7773.4.7 by Paul Hummer
Responded to bac's review
405
    >>> def print_proposals(webservice, url, status=None):
7771.3.1 by Tim Penhey
Commit interface update, and broken pagetest.
406
    ...     proposals = webservice.named_get(
7773.4.7 by Paul Hummer
Responded to bac's review
407
    ...         url, 'getMergeProposals',
7771.3.1 by Tim Penhey
Commit interface update, and broken pagetest.
408
    ...         status=status).jsonBody()
409
    ...     for proposal in proposals['entries']:
410
    ...         print_proposal(proposal)
411
7773.4.7 by Paul Hummer
Responded to bac's review
412
    >>> print_proposals(
413
    ...     webservice, url='/fooix',
414
    ...     status=[BranchMergeProposalStatus.CODE_APPROVED.title])
9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
415
    http://.../~source/fooix/fix-it/+merge/... - Approved
7771.3.1 by Tim Penhey
Commit interface update, and broken pagetest.
416
7771.3.3 by Tim Penhey
Updates following review.
417
If the branch is private it is not visible to an unpriveleged user.
7771.3.1 by Tim Penhey
Commit interface update, and broken pagetest.
418
419
    >>> login('admin@canonical.com')
8137.17.24 by Barry Warsaw
thread merge
420
    >>> from zope.security.proxy import removeSecurityProxy
13760.3.10 by Ian Booth
Rework implementation to remove metaclass and setattr - use explicitly_private property
421
    >>> removeSecurityProxy(fixit_proposal.source_branch).explicitly_private = True
7771.3.1 by Tim Penhey
Commit interface update, and broken pagetest.
422
    >>> branch_owner = fixit_proposal.source_branch.owner
423
    >>> logout()
424
7773.4.7 by Paul Hummer
Responded to bac's review
425
    >>> print_proposals(
426
    ...     webservice, url='/fooix',
427
    ...     status=[BranchMergeProposalStatus.CODE_APPROVED.title])
7771.3.1 by Tim Penhey
Commit interface update, and broken pagetest.
428
429
If we get a webservice for the owner of the source branch, then they can see
430
the proposal if they have allowed the API to access private bits.
431
432
    >>> service = webservice_for_person(
433
    ...     branch_owner, permission=OAuthPermission.READ_PRIVATE)
7773.4.7 by Paul Hummer
Responded to bac's review
434
    >>> print_proposals(
435
    ...     service, url='/fooix',
436
    ...     status=[BranchMergeProposalStatus.CODE_APPROVED.title])
9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
437
    http://.../~source/fooix/fix-it/+merge/... - Approved
7675.29.1 by Guilherme Salgado
merge from mainline
438
8555.1.6 by Tim Penhey
Get the branch merge proposals for a project.~
439
    >>> login('admin@canonical.com')
13760.3.10 by Ian Booth
Rework implementation to remove metaclass and setattr - use explicitly_private property
440
    >>> removeSecurityProxy(fixit_proposal.source_branch).explicitly_private = False
7773.4.7 by Paul Hummer
Responded to bac's review
441
    >>> logout()
442
7773.4.2 by Paul Hummer
Added tests, made things work
443
444
== Getting a Person's Pending Merge Proposals ==
445
7773.4.8 by Paul Hummer
Minor style changes
446
It is possible to view all of a person's merge proposals or filter their
7773.4.2 by Paul Hummer
Added tests, made things work
447
proposals by their status.
448
7773.4.7 by Paul Hummer
Responded to bac's review
449
    >>> proposals = webservice.named_get('/~source', 'getMergeProposals',
450
    ...     ).jsonBody()
451
    >>> print_proposals(service, url='/~source')
9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
452
    http://.../~source/fooix/fix-it/+merge/... - Approved
7773.4.2 by Paul Hummer
Added tests, made things work
453
454
The person's proposals can also be filtered by status.
455
8555.1.6 by Tim Penhey
Get the branch merge proposals for a project.~
456
    >>> login('admin@canonical.com')
7773.4.6 by Paul Hummer
Fixed the tests
457
    >>> fixit_proposal.rejectBranch(fixit_proposal.target_branch.owner, '1')
7773.4.2 by Paul Hummer
Added tests, made things work
458
    >>> logout()
459
7773.4.7 by Paul Hummer
Responded to bac's review
460
    >>> print_proposals(webservice, url='/~source',
7773.4.6 by Paul Hummer
Fixed the tests
461
    ...     status=[BranchMergeProposalStatus.REJECTED.title])
9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
462
    http://.../~source/fooix/fix-it/+merge/... - Rejected
7773.4.2 by Paul Hummer
Added tests, made things work
463
8555.1.6 by Tim Penhey
Get the branch merge proposals for a project.~
464
8555.1.9 by Tim Penhey
Expose branches for a project through the api.
465
== Getting a Project Group's Merge Proposals ==
8555.1.6 by Tim Penhey
Get the branch merge proposals for a project.~
466
8555.1.9 by Tim Penhey
Expose branches for a project through the api.
467
Getting the merge proposals for a project group will get all the proposals for all
468
the projects that are part of the project group.
8555.1.6 by Tim Penhey
Get the branch merge proposals for a project.~
469
470
    >>> login('admin@canonical.com')
471
    >>> project = factory.makeProject(name='widgets')
472
    >>> fooix.project = project
473
    >>> blob = factory.makeProduct(name='blob', project=project)
474
    >>> proposal = factory.makeBranchMergeProposal(
475
    ...     product=blob, set_state=BranchMergeProposalStatus.NEEDS_REVIEW)
476
    >>> proposal.source_branch.owner.name = 'mary'
477
    >>> proposal.source_branch.name = 'bar'
478
    >>> logout()
479
480
By default only work in progress, needs review and approved proposals are
481
returned.
482
483
    >>> print_proposals(webservice, url='/widgets')
9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
484
    http://.../~mary/blob/bar/+merge/... - Needs review
8555.1.6 by Tim Penhey
Get the branch merge proposals for a project.~
485
486
The proposals can also be filtered by status.
487
488
    >>> print_proposals(webservice, url='/widgets',
489
    ...     status=[BranchMergeProposalStatus.REJECTED.title])
9801.1.1 by Aaron Bentley
Initial support for addLandingTarget.
490
    http://.../~source/fooix/fix-it/+merge/... - Rejected
10242.4.1 by James Westby
Export a method on IPerson to get the reviews they have been requested to do.
491
10242.4.2 by James Westby
Fixups from Tom's review. Thanks.
492
== Getting Merge Proposals a Person has been Asked To Review ==
10242.4.1 by James Westby
Export a method on IPerson to get the reviews they have been requested to do.
493
494
It's good to be able to find out which proposals you have been asked to
495
review.
496
497
    >>> login('admin@canonical.com')
498
    >>> from lp.code.enums import BranchMergeProposalStatus
10242.4.5 by James Westby
Fix up the tests so that they are testing the correct thing.
499
500
First we create a review owned by someone else and requested of 'target'
501
which is the one we want the method to return.
502
503
    >>> source_branch = factory.makeBranch(owner=branch_owner,
504
    ...     product=blob, name="foo")
505
    >>> target_branch = factory.makeBranch(owner=target_owner,
506
    ...     product=blob, name="bar")
507
    >>> proposal = factory.makeBranchMergeProposal(
508
    ...     target_branch=target_branch,
509
    ...     product=blob, set_state=BranchMergeProposalStatus.NEEDS_REVIEW,
510
    ...     registrant=branch_owner, source_branch=source_branch)
511
    >>> proposal.nominateReviewer(target_owner, branch_owner)
512
    <CodeReviewVoteReference at ...>
513
514
And then we propose a merge the other way, so that the owner is target,
515
but they have not been asked to review, meaning that the method shouldn't
516
return this review.
517
518
    >>> proposal = factory.makeBranchMergeProposal(
519
    ...     target_branch=source_branch,
520
    ...     product=blob, set_state=BranchMergeProposalStatus.NEEDS_REVIEW,
521
    ...     registrant=target_owner, source_branch=target_branch)
522
    >>> proposal.nominateReviewer(branch_owner, target_owner)
523
    <CodeReviewVoteReference at ...>
10242.4.1 by James Westby
Export a method on IPerson to get the reviews they have been requested to do.
524
    >>> logout()
525
10242.4.2 by James Westby
Fixups from Tom's review. Thanks.
526
    >>> proposals = webservice.named_get('/~target', 'getRequestedReviews'
10242.4.1 by James Westby
Export a method on IPerson to get the reviews they have been requested to do.
527
    ...     ).jsonBody()
528
    >>> for proposal in proposals['entries']:
529
    ...     print_proposal(proposal)
10242.4.5 by James Westby
Fix up the tests so that they are testing the correct thing.
530
    http://.../~source/blob/foo/+merge/4 - Needs review
10242.4.1 by James Westby
Export a method on IPerson to get the reviews they have been requested to do.
531