|
5 | 5 | from github3 import GitHubError
|
6 | 6 | from github3.null import NullObject
|
7 | 7 | from github3.repos.repo import Repository
|
| 8 | +from github3.models import GitHubCore |
8 | 9 |
|
9 | 10 | from . import helper
|
10 | 11 |
|
@@ -248,19 +249,65 @@ def test_create_milestone_accepted_state(self):
|
248 | 249 | }
|
249 | 250 | )
|
250 | 251 |
|
251 |
| - def test_create_pull(self): |
| 252 | + def test_create_pull_private_required_data(self): |
| 253 | + """Verify the request for creating a pull request.""" |
| 254 | + with helper.mock.patch.object(GitHubCore, '_remove_none') as rm_none: |
| 255 | + data = {} |
| 256 | + self.instance._create_pull(data) |
| 257 | + rm_none.assert_called_once_with({}) |
| 258 | + assert self.session.post.called is False |
| 259 | + |
| 260 | + def test_create_pull_private(self): |
252 | 261 | """Verify the request for creating a pull request."""
|
253 | 262 | data = {
|
254 | 263 | 'title': 'foo',
|
255 | 264 | 'base': 'master',
|
256 | 265 | 'head': 'feature_branch'
|
257 | 266 | }
|
258 |
| - self.instance.create_pull(**data) |
| 267 | + self.instance._create_pull(data) |
259 | 268 | self.post_called_with(
|
260 | 269 | url_for('pulls'),
|
261 | 270 | data=data
|
262 | 271 | )
|
263 | 272 |
|
| 273 | + def test_create_pull(self): |
| 274 | + """Verify the request for creating a pull request.""" |
| 275 | + data = { |
| 276 | + 'title': 'foo', |
| 277 | + 'base': 'master', |
| 278 | + 'head': 'feature_branch', |
| 279 | + 'body': 'body' |
| 280 | + } |
| 281 | + with helper.mock.patch.object(Repository, '_create_pull') as pull: |
| 282 | + self.instance.create_pull(**data) |
| 283 | + pull.assert_called_once_with( |
| 284 | + data |
| 285 | + ) |
| 286 | + |
| 287 | + def test_create_pull_from_issue(self): |
| 288 | + """Verify the request for creating a pull request from an issue.""" |
| 289 | + with helper.mock.patch.object(Repository, '_create_pull') as pull: |
| 290 | + data = { |
| 291 | + 'issue': 1, |
| 292 | + 'base': 'master', |
| 293 | + 'head': 'feature_branch' |
| 294 | + } |
| 295 | + self.instance.create_pull_from_issue( |
| 296 | + **data |
| 297 | + ) |
| 298 | + pull.assert_called_once_with(data) |
| 299 | + |
| 300 | + def test_create_pull_from_issue_required_issue_number(self): |
| 301 | + """Verify the request for creating a pull request from an issue.""" |
| 302 | + with helper.mock.patch.object(Repository, '_create_pull') as pull: |
| 303 | + pull_request = self.instance.create_pull_from_issue( |
| 304 | + issue=-1, |
| 305 | + base='master', |
| 306 | + head='feature_branch' |
| 307 | + ) |
| 308 | + assert pull.called is False |
| 309 | + assert pull_request is None |
| 310 | + |
264 | 311 | def test_create_ref(self):
|
265 | 312 | """Verify the request to create a reference."""
|
266 | 313 | self.instance.create_ref('refs/heads/foo', 'my-fake-sha')
|
@@ -903,6 +950,17 @@ def test_create_pull(self):
|
903 | 950 | with pytest.raises(GitHubError):
|
904 | 951 | self.instance.create_pull(title='foo', base='master')
|
905 | 952 |
|
| 953 | + def test_create_pull_from_issue(self): |
| 954 | + """ |
| 955 | + Verify that creating a pull request from issue requires authentication. |
| 956 | + """ |
| 957 | + with pytest.raises(GitHubError): |
| 958 | + self.instance.create_pull_from_issue( |
| 959 | + issue=1, |
| 960 | + title='foo', |
| 961 | + base='master' |
| 962 | + ) |
| 963 | + |
906 | 964 | def test_hooks(self):
|
907 | 965 | """Show that a user must be authenticated to list hooks."""
|
908 | 966 | with pytest.raises(GitHubError):
|
|
0 commit comments