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
273 lines (210 loc) · 7.97 KB
/
Copy pathtest_pulls.py
File metadata and controls
273 lines (210 loc) · 7.97 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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
"""Unit tests for the github3.pulls module."""
import pytest
from . import helper
from github3 import GitHubError
from github3 import pulls
get_pr_example_data = helper.create_example_data_helper(
'pull_request_example'
)
url_for = helper.create_url_helper(
'https://api.github.com/repos/octocat/Hello-World/pulls/1'
)
class TestPullRequest(helper.UnitHelper):
"""PullRequest unit tests."""
described_class = pulls.PullRequest
example_data = get_pr_example_data()
def test_close(self):
"""Show that a user can close a Pull Request."""
self.instance.close()
self.patch_called_with(
url_for(),
data={
'title': self.instance.title,
'body': self.instance.body,
'state': 'closed'
}
)
def test_create_comment(self):
"""Show that a user can comment on a PR."""
self.instance.create_comment('body')
self.post_called_with(
url_for('comments').replace('pulls', 'issues'),
data={'body': 'body'}
)
def test_create_review_comment(self):
"""Verify the request to create a review comment on a PR diff."""
self.instance.create_review_comment('body', 'sha', 'path', 6)
self.post_called_with(
url_for('comments'),
data={
'body': 'body',
'commit_id': 'sha',
'path': 'path',
'position': 6
}
)
def test_diff(self):
"""Show that a user can request the diff of a Pull Request."""
self.instance.diff()
self.session.get.assert_called_once_with(
url_for(),
headers={'Accept': 'application/vnd.github.diff'}
)
def test_is_merged_request(self):
"""Show that a user can request the merge status of a PR."""
self.instance.merged = False
self.instance.is_merged()
self.session.get.assert_called_once_with(url_for('merge'))
def test_is_merged_no_requset(self):
"""Show that no request is needed if .merged is True."""
self.instance.merged = True
assert self.instance.is_merged()
assert self.session.get.called is False
def test_issue(self):
"""Show that a user can retrieve the associated issue of a PR."""
self.instance.issue()
self.session.get.assert_called_once_with(
url_for().replace('pulls', 'issues')
)
def test_merge(self):
"""Show that a user can merge a Pull Request."""
self.instance.merge()
self.put_called_with(
url_for('merge'),
data={"squash": False, "commit_message": ""}
)
def test_merge_squash_message(self):
"""Show that a user can merge a Pull Request."""
self.instance.merge('commit message', squash=True)
self.put_called_with(
url_for('merge'),
data={"squash": True, "commit_message": "commit message"}
)
def test_patch(self):
"""Show that a user can fetch the patch from a Pull Request."""
self.instance.patch()
self.session.get.assert_called_once_with(
url_for(),
headers={'Accept': 'application/vnd.github.patch'}
)
def test_reopen(self):
"""Show that a user can reopen a Pull Request that was closed."""
self.instance.reopen()
self.patch_called_with(
url_for(),
data={
'title': self.instance.title,
'body': self.instance.body,
'state': 'open'
}
)
def test_update(self):
"""Show that a user can update a Pull Request."""
self.instance.update('my new title',
'my new body',
'open')
self.patch_called_with(
url_for(),
data={
'title': 'my new title',
'body': 'my new body',
'state': 'open'
}
)
class TestPullRequestRequiresAuthentication(
helper.UnitRequiresAuthenticationHelper):
"""PullRequest unit tests that demonstrate which methods require auth."""
described_class = pulls.PullRequest
example_data = get_pr_example_data()
def test_close(self):
"""Show that you must be authenticated to close a Pull Request."""
with pytest.raises(GitHubError):
self.instance.close()
def test_create_review_comment(self):
"""Show that you must be authenticated to close a Pull Request."""
with pytest.raises(GitHubError):
self.instance.create_review_comment('', '', '', 1)
def test_merge(self):
"""Show that you must be authenticated to merge a Pull Request."""
with pytest.raises(GitHubError):
self.instance.merge()
def test_reopen(self):
"""Show that you must be authenticated to reopen a Pull Request."""
with pytest.raises(GitHubError):
self.instance.reopen()
def test_update(self):
"""Show that you must be authenticated to update a Pull Request."""
with pytest.raises(GitHubError):
self.instance.update('foo', 'bar', 'bogus')
class TestPullRequestIterator(helper.UnitIteratorHelper):
"""Test PullRequest methods that return Iterators."""
described_class = pulls.PullRequest
example_data = get_pr_example_data()
def test_commits(self):
"""Show that a user can retrieve the commits in a Pull Request."""
i = self.instance.commits()
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('commits'),
params={'per_page': 100},
headers={}
)
def test_issue_comments(self):
"""Show that a user can retrieve the issue-like comments on a PR."""
i = self.instance.issue_comments()
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('comments').replace('pulls', 'issues'),
params={'per_page': 100},
headers={}
)
def test_files(self):
"""Show that a user can retrieve the files from a Pull Request."""
i = self.instance.files()
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('files'),
params={'per_page': 100},
headers={}
)
def test_review_comments(self):
"""Show that a user can retrieve the review comments on a PR."""
i = self.instance.review_comments()
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('comments'),
params={'per_page': 100},
headers={}
)
class TestReviewComment(helper.UnitHelper):
"""Unit tests for the ReviewComment class."""
described_class = pulls.ReviewComment
get_comment_example_data = helper.create_example_data_helper(
'review_comment_example'
)
example_data = get_comment_example_data()
def test_reply(self):
"""Verify the request to reply to a review comment."""
self.instance.reply('foo')
self.post_called_with(
url_for('comments'),
data={'body': 'foo', 'in_reply_to': '1'}
)
def test_reply_requires_authentication(self):
"""Verify that a user needs to be authenticated to reply."""
self.session.has_auth.return_value = False
with pytest.raises(GitHubError):
self.instance.reply('')
class TestPullFile(helper.UnitHelper):
"""Unit tests for the PullFile class."""
described_class = pulls.PullFile
get_pull_file_example_data = helper.create_example_data_helper(
'pull_file_example'
)
example_data = get_pull_file_example_data()
def test_contents(self):
"""Verify the request made to fetch a pull request file contents."""
self.instance.contents()
self.session.get.assert_called_once_with(
self.example_data['contents_url']
)