forked from sigmavirus24/github3.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_pulls.py
More file actions
251 lines (216 loc) · 10.1 KB
/
Copy pathtest_pulls.py
File metadata and controls
251 lines (216 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# -*- coding: utf-8 -*-
"""Integration tests for methods implemented on PullRequest."""
import github3
from github3 import repos
from .helper import IntegrationHelper
class TestPullRequest(IntegrationHelper):
"""PullRequest integration tests."""
def get_pull_request(self, repository="sigmavirus24/github3.py", num=235):
"""Get the pull request we wish to use in this test."""
owner, repo = repository.split("/")
p = self.gh.pull_request(owner, repo, num)
assert isinstance(p, github3.pulls.PullRequest)
return p
def test_close(self):
"""Show that one can close an open Pull Request."""
self.basic_login()
cassette_name = self.cassette_name("close")
with self.recorder.use_cassette(cassette_name):
p = self.get_pull_request(
repository="github3py/delete_contents", num=2
)
assert p.close() is True
def test_create_comment(self):
"""Show that a user can create a comment on a PR."""
self.basic_login()
cassette_name = self.cassette_name("create_comment")
with self.recorder.use_cassette(cassette_name):
p = self.get_pull_request(num=423)
comment = p.create_comment("Testing pull request comment")
assert isinstance(comment, github3.issues.comment.IssueComment)
def test_commits(self):
"""Show that one can iterate over a PR's commits."""
cassette_name = self.cassette_name("commits")
with self.recorder.use_cassette(cassette_name):
p = self.get_pull_request()
for commit in p.commits():
assert isinstance(commit, github3.repos.commit.ShortCommit)
def test_create_review_comment(self):
"""Show that a user can create an in-line reveiw comment on a PR."""
self.basic_login()
cassette_name = self.cassette_name("create_review_comment")
with self.recorder.use_cassette(cassette_name):
p = self.get_pull_request(num=286)
comment = p.create_review_comment(
body="Testing review comments",
commit_id="4437428aefdb50913e2acabd0552bd13021dc38f",
path="github3/pulls.py",
position=6,
)
assert isinstance(comment, github3.pulls.ReviewComment)
def test_create_review_requests(self):
"""Show that a user can create review requests on a PR."""
self.token_login()
cassette_name = self.cassette_name("create_review_requests")
with self.recorder.use_cassette(cassette_name):
p = self.get_pull_request(num=873)
pull_request = p.create_review_requests(
reviewers=["sigmavirus24"]
)
assert isinstance(pull_request, github3.pulls.ShortPullRequest)
def test_create_review(self):
"""Verify the request to create a pending review on a PR."""
self.token_login()
cassette_name = self.cassette_name("create_review")
with self.recorder.use_cassette(cassette_name):
p = self.get_pull_request(num=819)
comment = p.create_review(
body="Testing create review", event="COMMENT"
)
assert isinstance(comment, github3.pulls.PullReview)
def test_delete_review_requests(self):
"""Show that a user can delete review requests on a PR."""
self.token_login()
cassette_name = self.cassette_name("delete_review_requests")
with self.recorder.use_cassette(cassette_name):
p = self.get_pull_request(num=873)
assert (
p.delete_review_requests(reviewers=["sigmavirus24"]) is True
)
def test_diff(self):
"""Show that one can retrieve a bytestring diff of a PR."""
cassette_name = self.cassette_name("diff")
with self.recorder.use_cassette(cassette_name):
p = self.get_pull_request()
diff = p.diff()
assert isinstance(diff, bytes)
assert len(diff) > 0
def test_files(self):
"""Show that one can iterate over a PR's files."""
cassette_name = self.cassette_name("files")
with self.recorder.use_cassette(cassette_name):
p = self.get_pull_request()
for pr_file in p.files():
assert isinstance(pr_file, github3.pulls.PullFile)
def test_is_merged(self):
"""Show that one can check if a PR was merged."""
cassette_name = self.cassette_name("is_merged")
with self.recorder.use_cassette(cassette_name):
p = self.get_pull_request()
assert p.is_merged() is True
def test_issue(self):
"""Show that one can retrieve the associated issue of a PR."""
cassette_name = self.cassette_name("issue")
with self.recorder.use_cassette(cassette_name):
p = self.get_pull_request()
issue = p.issue()
assert isinstance(issue, github3.issues.Issue)
def test_issue_comments(self):
"""Show that one can iterate over a PR's issue comments."""
cassette_name = self.cassette_name("issue_comments")
with self.recorder.use_cassette(cassette_name):
p = self.get_pull_request()
for comment in p.issue_comments():
assert isinstance(
comment, github3.issues.comment.IssueComment
)
def test_patch(self):
"""Show that a user can get the patch from a PR."""
cassette_name = self.cassette_name("patch")
with self.recorder.use_cassette(cassette_name):
p = self.get_pull_request()
patch = p.patch()
assert isinstance(patch, bytes)
assert len(patch) > 0
def test_pull_reviews(self):
"""Show that one can iterate over a PR's reviews."""
cassette_name = self.cassette_name("pull_reviews")
with self.recorder.use_cassette(cassette_name):
p = self.get_pull_request(num=671)
for pull_review in p.reviews():
assert isinstance(pull_review, github3.pulls.PullReview)
assert isinstance(pull_review.user, github3.users.ShortUser)
def test_reopen(self):
"""Show that one can reopen an open Pull Request."""
self.basic_login()
cassette_name = self.cassette_name("reopen")
with self.recorder.use_cassette(cassette_name):
p = self.get_pull_request(
repository="github3py/delete_contents", num=2
)
assert p.reopen() is True
def test_review_comments(self):
"""Show that one can iterate over a PR's review comments."""
cassette_name = self.cassette_name("review_comments")
with self.recorder.use_cassette(cassette_name):
p = self.get_pull_request()
for comment in p.review_comments():
assert isinstance(comment, github3.pulls.ReviewComment)
def test_review_requests(self):
"""Show that one can retrieve the review requests of a PR."""
cassette_name = self.cassette_name("review_requests")
with self.recorder.use_cassette(cassette_name):
p = self.get_pull_request(num=873)
review_requests = p.review_requests()
assert isinstance(review_requests, github3.pulls.ReviewRequests)
def test_update(self):
"""Show that one can update an open Pull Request."""
self.basic_login()
cassette_name = self.cassette_name("update")
with self.recorder.use_cassette(cassette_name):
p = self.get_pull_request(
repository="github3py/delete_contents", num=2
)
assert p.update(p.title) is True
def test_repository(self):
"""Show that the pull request has the owner repository."""
self.basic_login()
cassette_name = self.cassette_name("single")
with self.recorder.use_cassette(cassette_name):
p = self.get_pull_request()
assert isinstance(p.repository, github3.repos.ShortRepository)
class TestPullReview(IntegrationHelper):
"""Integration tests for the PullReview object."""
def test_submit(self):
self.token_login()
cassette_name = self.cassette_name("submit")
with self.recorder.use_cassette(cassette_name):
pr = self.gh.pull_request("sigmavirus24", "github3.py", 819)
p = pr.create_review(body="Testing submit review")
p.submit(body="Testing submit review", event="COMMENT")
assert p.submitted_at is not None
class TestReviewComment(IntegrationHelper):
"""Integration tests for the ReviewComment object."""
def test_reply(self):
"""Show that a user can reply to an existing ReviewComment."""
self.basic_login()
cassette_name = self.cassette_name("reply")
with self.recorder.use_cassette(cassette_name):
p = self.gh.pull_request("github3py", "delete_contents", 2)
c = next(p.review_comments())
comment = c.reply("Replying to comments is fun.")
assert isinstance(comment, github3.pulls.ReviewComment)
class TestPullFile(IntegrationHelper):
"""Integration tests for the PullFile object."""
def get_pull_request_file(self, owner, repo, pull_number, filename):
"""Helper method to retrieve a PR file."""
p = self.gh.pull_request(owner, repo, pull_number)
for pull_file in p.files():
if pull_file.filename == filename:
break
else:
assert False, "Could not find '{0}'".format(filename)
return pull_file
def test_contents(self):
"""Show that a user can retrieve the contents of a PR file."""
cassette_name = self.cassette_name("contents")
with self.recorder.use_cassette(cassette_name):
pull_file = self.get_pull_request_file(
owner="sigmavirus24",
repo="github3.py",
pull_number=286,
filename="github3/pulls.py",
)
contents = pull_file.contents()
assert isinstance(contents, repos.contents.Contents)
assert contents.decoded != b""