|
5 | 5 | create_example_data_helper) |
6 | 6 |
|
7 | 7 | from github3 import GitHubError |
8 | | -from github3.pulls import PullRequest |
| 8 | +from github3.pulls import PullRequest, ReviewComment |
9 | 9 |
|
10 | 10 | get_pr_example_data = create_example_data_helper('pull_request_example') |
11 | 11 |
|
@@ -195,3 +195,84 @@ def test_review_comments(self): |
195 | 195 | params={'per_page': 100}, |
196 | 196 | headers={} |
197 | 197 | ) |
| 198 | + |
| 199 | + |
| 200 | +class TestReviewComment(UnitHelper): |
| 201 | + |
| 202 | + """Unit tests for the ReviewComment class.""" |
| 203 | + |
| 204 | + described_class = ReviewComment |
| 205 | + example_data = { |
| 206 | + "url": ("https://api.github.com/repos/octocat/Hello-World/pulls/" |
| 207 | + "comments/1"), |
| 208 | + "id": 1, |
| 209 | + "diff_hunk": ("@@ -16,33 +16,40 @@ public class Connection :" |
| 210 | + " IConnection..."), |
| 211 | + "path": "file1.txt", |
| 212 | + "position": 1, |
| 213 | + "original_position": 4, |
| 214 | + "commit_id": "6dcb09b5b57875f334f61aebed695e2e4193db5e", |
| 215 | + "original_commit_id": "9c48853fa3dc5c1c3d6f1f1cd1f2743e72652840", |
| 216 | + "user": { |
| 217 | + "login": "octocat", |
| 218 | + "id": 1, |
| 219 | + "avatar_url": "https://github.com/images/error/octocat_happy.gif", |
| 220 | + "gravatar_id": "", |
| 221 | + "url": "https://api.github.com/users/octocat", |
| 222 | + "html_url": "https://github.com/octocat", |
| 223 | + "followers_url": "https://api.github.com/users/octocat/followers", |
| 224 | + "following_url": ("https://api.github.com/users/octocat/following" |
| 225 | + "{/other_user}"), |
| 226 | + "gists_url": ("https://api.github.com/users/octocat/gists" |
| 227 | + "{/gist_id}"), |
| 228 | + "starred_url": ("https://api.github.com/users/octocat/starred" |
| 229 | + "{/owner}{/repo}"), |
| 230 | + "subscriptions_url": ("https://api.github.com/users/octocat" |
| 231 | + "/subscriptions"), |
| 232 | + "organizations_url": "https://api.github.com/users/octocat/orgs", |
| 233 | + "repos_url": "https://api.github.com/users/octocat/repos", |
| 234 | + "events_url": ("https://api.github.com/users/octocat/events" |
| 235 | + "{/privacy}"), |
| 236 | + "received_events_url": ("https://api.github.com/users/octocat" |
| 237 | + "/received_events"), |
| 238 | + "type": "User", |
| 239 | + "site_admin": False |
| 240 | + }, |
| 241 | + "body": "Great stuff", |
| 242 | + "created_at": "2011-04-14T16:00:49Z", |
| 243 | + "updated_at": "2011-04-14T16:00:49Z", |
| 244 | + "html_url": ("https://github.com/octocat/Hello-World/pull/1" |
| 245 | + "#discussion-diff-1"), |
| 246 | + "pull_request_url": ("https://api.github.com/repos/octocat/" |
| 247 | + "Hello-World/pulls/1"), |
| 248 | + "_links": { |
| 249 | + "self": { |
| 250 | + "href": ("https://api.github.com/repos/octocat/Hello-World/" |
| 251 | + "pulls/comments/1") |
| 252 | + }, |
| 253 | + "html": { |
| 254 | + "href": ("https://github.com/octocat/Hello-World/pull/1" |
| 255 | + "#discussion-diff-1") |
| 256 | + }, |
| 257 | + "pull_request": { |
| 258 | + "href": ("https://api.github.com/repos/octocat/" |
| 259 | + "Hello-World/pulls/1") |
| 260 | + } |
| 261 | + } |
| 262 | + } |
| 263 | + |
| 264 | + def test_reply(self): |
| 265 | + """Verify the request to reply to a review comment.""" |
| 266 | + self.instance.reply('foo') |
| 267 | + |
| 268 | + self.post_called_with( |
| 269 | + url_for('comments'), |
| 270 | + data={'body': 'foo', 'in_reply_to': '1'} |
| 271 | + ) |
| 272 | + |
| 273 | + def test_reply_requires_authentication(self): |
| 274 | + """Verify that a user needs to be authenticated to reply.""" |
| 275 | + self.session.has_auth.return_value = False |
| 276 | + |
| 277 | + with pytest.raises(GitHubError): |
| 278 | + self.instance.reply('') |
0 commit comments